jupyter | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!
The tutorial below imports NumPy, Pandas, SciPy and Plotly.
importplotly.plotlyaspyimportplotly.graph_objsasgoimportnumpyasnpimportpandasaspdimportscipyfromscipyimportsignal
Similar to convolution, the 1D Cross-Correlation between two functions
$$ \begin{align*} (fg)[n] = \sum_{m=-\infty}^{\infty} f^{}[m]g[n+m] \end{align*} $$
where complex conjugate
of
To give us an intuitive glance at what this does, let us look at the cross-correlation between a saw wave and a square wave.
x=np.linspace(0, 20, 50) saw_y=signal.sawtooth(t=x) square_y=signal.square(t=x) convolve_y=signal.convolve(saw_y, square_y) trace_saw=go.Scatter( x=x, y=saw_y, mode='lines', name='Saw', marker=dict( color='#57D1C9' ) ) trace_square=go.Scatter( x=x, y=square_y, mode='lines', name='Square', marker=dict( color='#ED5485' ) ) trace_convolution=go.Scatter( x=x, y=convolve_y, mode='lines', name='Convolution', marker=dict( color='#FFE869' ) ) data= [trace_saw, trace_square, trace_convolution] py.iplot(data, filename='1d-convolution-of-saw-and-square')
To compare with the plot above, we can plot a saw wave, a phase shifted saw wave and the convolution between the two to see how they correlate along the axis.
x=np.linspace(0, 20, 50) saw_y=signal.sawtooth(t=x) square_y=signal.square(t=x) shifted_saw_y=signal.sawtooth(t=np.linspace(10, 30, 50)) convolve_y=signal.convolve(saw_y, shifted_saw_y) trace_saw=go.Scatter( x=x, y=saw_y, mode='lines', name='Saw', marker=dict( color='#FF7844' ), opacity=0.8 ) trace_shifted_saw=go.Scatter( x=x, y=shifted_saw_y, mode='lines', name='Shifted Saw', marker=dict( color='#A64942' ), opacity=0.8 ) trace_convolution=go.Scatter( x=x, y=convolve_y, mode='lines', name='Convolution', marker=dict( color='#53354A' ) ) data= [trace_saw, trace_shifted_saw, trace_convolution] py.iplot(data, filename='1d-convolution-of-saw-and-shifted-saw')
fromIPython.displayimportdisplay, HTMLdisplay(HTML('<link href="//fonts.googleapis.com/css?family=Open+Sans:600,400,300,200|Inconsolata|Ubuntu+Mono:400,700" rel="stylesheet" type="text/css" />')) display(HTML('<link rel="stylesheet" type="text/css" href="http://help.plot.ly/documentation/all_static/css/ipython-notebook-custom.css">')) ! pipinstallgit+https://github.com/plotly/publisher.git--upgradeimportpublisherpublisher.publish( 'python-1D-Correlation.ipynb', 'python/1d-correlation/', '1D Correlation | plotly', 'Learn how to perform 1 dimensional correlation between two signals in Python.', title='1D Correlation in Python | plotly', name='1D Correlation', language='python', page_type='example_index', has_thumbnail='false', display_as='signal-analysis', order=5)