.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/example_dering.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_example_dering.py: Ringing artifact reduction example ================================== This example shows how to subtract the impulse response from a filter to reduce ringing artifacts. .. GENERATED FROM PYTHON SOURCE LINES 9-17 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from scipy.signal import butter, lfilter from meegkit.detrend import reduce_ringing rng = np.random.default_rng(9) .. GENERATED FROM PYTHON SOURCE LINES 18-20 Detrending ============================================================================= .. GENERATED FROM PYTHON SOURCE LINES 22-27 Basic example with a linear trend ----------------------------------------------------------------------------- Simulate the effect of filtering a signal containing a discontinuity, and try to remove the resulting ringing artifact by subtracing the opposite of the impulse response. .. GENERATED FROM PYTHON SOURCE LINES 27-40 .. code-block:: Python x = np.arange(1000) < 1 [b, a] = butter(6, 0.2) # Butterworth filter design x = lfilter(b, a, x) * 50 # Filter data using above filter x = np.roll(x, 500) x = x[:, None] + rng.standard_normal((1000, 2)) y = reduce_ringing(x, samples=np.array([500])) plt.figure() plt.plot(x + np.array([-10, 10]), "C0", label="before") plt.plot(y + np.array([-10, 10]), "C1:", label="after") plt.legend() plt.show() .. image-sg:: /auto_examples/images/sphx_glr_example_dering_001.png :alt: example dering :srcset: /auto_examples/images/sphx_glr_example_dering_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.168 seconds) .. _sphx_glr_download_auto_examples_example_dering.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_dering.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_dering.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_