.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "11_demos\python_packages\scipy\demo_scipy-signal-correlate.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_11_demos_python_packages_scipy_demo_scipy-signal-correlate.py: Signal correlation ====================== Implement a matched filter using cross-correlation, to recover a signal that has passed through a noisy channel. .. GENERATED FROM PYTHON SOURCE LINES 6-30 .. image-sg:: /11_demos/python_packages/scipy/images/sphx_glr_demo_scipy-signal-correlate_001.png :alt: Original signal, Signal with noise, Cross-correlated with rectangular pulse :srcset: /11_demos/python_packages/scipy/images/sphx_glr_demo_scipy-signal-correlate_001.png :class: sphx-glr-single-img .. code-block:: Python from scipy import signal import numpy as np import matplotlib.pyplot as plt sig = np.repeat([0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0], 128) sig_noise = sig + np.random.randn(len(sig)) corr = signal.correlate(sig_noise, np.ones(128), mode="same") / 128 clock = np.arange(64, len(sig), 128) fig, (ax_orig, ax_noise, ax_corr) = plt.subplots(3, 1, sharex=True) ax_orig.plot(sig) ax_orig.plot(clock, sig[clock], "ro") ax_orig.set_title("Original signal") ax_noise.plot(sig_noise) ax_noise.set_title("Signal with noise") ax_corr.plot(corr) ax_corr.plot(clock, corr[clock], "ro") ax_corr.axhline(0.5, ls=":") ax_corr.set_title("Cross-correlated with rectangular pulse") ax_orig.margins(0, 0.1) fig.tight_layout() fig.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.232 seconds) .. _sphx_glr_download_11_demos_python_packages_scipy_demo_scipy-signal-correlate.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_scipy-signal-correlate.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_scipy-signal-correlate.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demo_scipy-signal-correlate.zip `