.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/ssa/plot_01_ssa_basics.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_ssa_plot_01_ssa_basics.py: Basic SSA decomposition and frequency-guided cleaning ===================================================== This network-free example separates a slow synthetic drift from an alpha rhythm. The frequency grouping is an mne-denoise extension, not a grouping rule prescribed by Basic SSA. .. GENERATED FROM PYTHON SOURCE LINES 9-54 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/ssa/images/sphx_glr_plot_01_ssa_basics_001.png :alt: Frequency-guided Basic SSA :srcset: /auto_examples/ssa/images/sphx_glr_plot_01_ssa_basics_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/ssa/images/sphx_glr_plot_01_ssa_basics_002.png :alt: PSD Comparison :srcset: /auto_examples/ssa/images/sphx_glr_plot_01_ssa_basics_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none Additive reconstruction error: 2.520e-14 Dropped frequencies: [0.5 0.5]
| .. code-block:: Python import numpy as np from mne_denoise.ssa import SingularSpectrumAnalysis, ssa_decompose from mne_denoise.viz import plot_psd_comparison, plot_signal_overlay sfreq = 200.0 times = np.arange(1200) / sfreq alpha = np.sin(2 * np.pi * 10.0 * times) drift = 4.0 * np.sin(2 * np.pi * 0.5 * times) rng = np.random.default_rng(4) observed = drift + alpha + 0.05 * rng.standard_normal(times.size) components, info = ssa_decompose(observed, window_seconds=0.5, sfreq=sfreq) reconstruction_error = np.max(np.abs(components.sum(axis=0) - observed)) print(f"Additive reconstruction error: {reconstruction_error:.3e}") cleaner = SingularSpectrumAnalysis( sfreq=sfreq, window_seconds=0.5, drop_freq_max=3.0, ) cleaned = cleaner.fit_transform(observed[np.newaxis])[0] print(f"Dropped frequencies: {cleaner.dropped_frequencies_[0]}") plot_signal_overlay( observed, cleaned, times, reference=alpha, before_label="Observed", after_label="Basic SSA", reference_label="Alpha reference", scale_after=False, title="Frequency-guided Basic SSA", show=False, ) plot_psd_comparison( observed, cleaned, sfreq=sfreq, fmin=0, fmax=25, show=False, ) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.581 seconds) .. _sphx_glr_download_auto_examples_ssa_plot_01_ssa_basics.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_ssa_basics.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_ssa_basics.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_ssa_basics.zip `