.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/ssa/plot_02_local_ssa_properties.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_02_local_ssa_properties.py: Local SSA properties on a synthetic signal =========================================== This is an algorithm demonstration, not a replication of Teixeira et al.'s figures. The desired signal is broadband so that the example exercises the paper's high-energy-structure-versus-residual assumption without constructing an unrealistically perfect separability case. .. GENERATED FROM PYTHON SOURCE LINES 10-47 .. image-sg:: /auto_examples/ssa/images/sphx_glr_plot_02_local_ssa_properties_001.png :alt: Teixeira local SSA synthetic demonstration :srcset: /auto_examples/ssa/images/sphx_glr_plot_02_local_ssa_properties_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Correlation with broadband reference: 0.975 Reference gain: 0.941 MDL dimensions: [2 1 1 1 1 2]
| .. code-block:: Python import numpy as np from mne_denoise.ssa import LocalSingularSpectrumAnalysis from mne_denoise.viz import plot_signal_overlay sfreq = 128.0 times = np.arange(1000) / sfreq rng = np.random.default_rng(8) neural = 0.5 * rng.standard_normal(times.size) artifact = 6.0 * np.sin(2 * np.pi * 0.5 * times) observed = neural + artifact + 0.05 * rng.standard_normal(times.size) cleaner = LocalSingularSpectrumAnalysis( window_length=41, n_clusters=6, random_state=0, ) cleaned = cleaner.fit_transform(observed[np.newaxis])[0] correlation = np.corrcoef(cleaned, neural)[0, 1] gain = np.dot(cleaned, neural) / np.dot(neural, neural) print(f"Correlation with broadband reference: {correlation:.3f}") print(f"Reference gain: {gain:.3f}") print(f"MDL dimensions: {cleaner.subspace_dimensions_[0]}") plot_signal_overlay( observed, cleaned, times, reference=neural, before_label="Observed", after_label="Local SSA residual", reference_label="Broadband reference", scale_after=False, title="Teixeira local SSA synthetic demonstration", show=False, ) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.366 seconds) .. _sphx_glr_download_auto_examples_ssa_plot_02_local_ssa_properties.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_local_ssa_properties.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_local_ssa_properties.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_local_ssa_properties.zip `