.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/convolution.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_auto_examples_convolution.py: Simple Convolution Example ========================== Since we use convolution a bit for signal analysis, test it here. This also demonstrates the point that, when performing convolution, it's important to distinguish between signals that are "causal" (like an FID -- consisting of real and imag that are Hermite transform pairs) vs. "non-causal" (e.g. take the real part or the energy of a causal signal, or analyze a noise PSD). We show the time-domain signal by way of explanation as to how these are treated differently. .. GENERATED FROM PYTHON SOURCE LINES 13-39 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/images/sphx_glr_convolution_001.png :alt: Time domain :srcset: /auto_examples/images/sphx_glr_convolution_001.png, /auto_examples/images/sphx_glr_convolution_001_2_00x.png 2.00x :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_convolution_002.png :alt: Fourier transform :srcset: /auto_examples/images/sphx_glr_convolution_002.png, /auto_examples/images/sphx_glr_convolution_002_2_00x.png 2.00x :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none 1: Time domain |||s 2: Fourier transform |||Hz | .. code-block:: Python from pylab import * from pyspecdata import * t = nddata(r_[0:4:1024j],'t').set_units('t','s') signal = exp(-1j*2*pi*100*t-20*t/pi) signal.add_noise(0.01) with figlist_var() as fl: fl.next('Time domain') fl.plot(signal, label='original') fl.next('Fourier transform', legend=True) signal.ft('t', shift=True) signal_real_copy = signal.real signal_real_copy_noncausal = signal.real fl.plot(signal, label='original') signal.convolve('t',5) signal_real_copy.convolve('t',5) signal_real_copy_noncausal.convolve('t',5, enforce_causality=False) fl.plot(signal, label='after convolve') fl.plot(signal_real_copy, label='real copy, after convolve') fl.plot(signal_real_copy_noncausal, ':', label='real copy, after convolve, treat as non-causal') fl.next('Time domain') signal.ift('t') signal_real_copy.ift('t') signal_real_copy_noncausal.ift('t') fl.plot(signal, label='after convolve') fl.plot(signal_real_copy, label='real copy, after convolve') fl.plot(signal_real_copy_noncausal, ':', label='real copy, after convolve, treat as non-causal') .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.006 seconds) .. _sphx_glr_download_auto_examples_convolution.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: convolution.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: convolution.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_