Understanding the multiband extension of GEDAI🔗

This tutorial demonstrates how to use multiband GEDAI. Multiband GEDAI is a frequency-specific denoising method that extends the generalized eigenvalue decomposition approach of GEDAI. Its approach focuses on isolating and removing artifacts within specific frequency bands. For that, the multiband GEDAI first decomposes the EEG data into its frequency components using wavelet transform, then applies GEDAI to each frequency band separately. Finally, the denoised frequency components are recombined to reconstruct the cleaned EEG signal.

Note

This purpose of this tutorial is to explain the differrent parameters of the MultibandGedai model and help you better understand the underlying algorithm. If you want to learn how to use Multiband GEDAI in a practical, end-to-end offline denoising workflow, please refer to the Practical Pipelines section.

%%

import matplotlib.pyplot as plt
from mne.io import read_raw

from gedai import MultibandGedai
from gedai.data import get_contaminated_eeg_set_path
from gedai.viz import plot_mne_style_overlay_interactive

n_jobs = -1
raw = read_raw(str(get_contaminated_eeg_set_path()), preload=True)

For simplicity, we will only use the first 30 seconds of the data in this tutorial. In practice, it is recommended to use the full recording for fitting the GEDAI model, as this allows the model to better capture the noise characteristics of the data.

raw.crop(0, 30)
General
Filename(s) SNR=0.35481 contamination=25 clean_EEG_dataset_2.set + EOG_EMG_NOISE_dataset_1.set
MNE object type RawEEGLAB
Measurement date Unknown
Participant Unknown
Experimenter Unknown
Acquisition
Duration 00:00:31 (HH:MM:SS)
Sampling frequency 200.00 Hz
Time points 6,001
Channels
EEG
Head & sensor digitization 30 points
Filters
Highpass 0.00 Hz
Lowpass 100.00 Hz


GEDAI🔗

To use spectral GEDAI, we initialize the MultibandGedai object by specifying the wavelet_level parameter, which defines the number of frequency bands to decompose the EEG data into. Each level corresponds to a specific frequency band, allowing for targeted denoising within those bands. It is also possible to define the type of wavelet used for the decomposition by setting the wavelet_type parameter.

multiband_gedai = MultibandGedai(wavelet_type="haar", wavelet_level=8)

Model Fitting🔗

The fitting process of spectral GEDAI is similar to that of the standard GEDAI. For each wavelet level (i.e., frequency band), the fitting process estimates the optimal threshold to distinguish between signal and noise components.

multiband_gedai.fit_raw(
    raw, duration=2.0, sensai_method="gridsearch", n_jobs=n_jobs, verbose=True
)
    343 x 343 full covariance (kind = 1) found.
[multiband.fit_raw] WARNING: Requested duration 2.000s adjusted to 2.560s (512 samples) to satisfy wavelet level 8 requirements.
Not setting metadata
43 matching events found
No baseline correction applied
0 projection items activated
Using data from preloaded Raw for 43 events and 512 original time points ...
0 bad epochs dropped
[multiband.fit_epochs] INFO: Setting average reference.
EEG channel type selected for re-referencing
Applying average reference.
Applying a custom ('EEG',) reference.
[multiband._ensure_wavelet_low_cutoff] INFO: Setting wavelet_low_cutoff to 0.7827788649706457 Hz based on epoch duration and sampling frequency.

  0%|          |  : 0/43 [00:00<?,       ?it/s]
  9%|▉         |  : 4/43 [00:04<00:47,    1.23s/it]
 19%|█▊        |  : 8/43 [00:07<00:30,    1.13it/s]
 28%|██▊       |  : 12/43 [00:09<00:23,    1.32it/s]
 37%|███▋      |  : 16/43 [00:11<00:18,    1.43it/s]
 47%|████▋     |  : 20/43 [00:13<00:15,    1.51it/s]
 56%|█████▌    |  : 24/43 [00:15<00:12,    1.57it/s]
 65%|██████▌   |  : 28/43 [00:17<00:09,    1.62it/s]
 74%|███████▍  |  : 32/43 [00:19<00:06,    1.65it/s]
 84%|████████▎ |  : 36/43 [00:22<00:04,    1.68it/s]
 93%|█████████▎|  : 40/43 [00:24<00:01,    1.70it/s]
100%|██████████|  : 43/43 [00:24<00:00,    1.78it/s]
[multiband.fit_epochs] INFO: Wavelet index 0 (0.00-0.39 Hz) will be zeroed out during transformation because its upper frequency 0.39 Hz is below the low cutoff 0.78 Hz.
[multiband.fit_epochs] INFO: Wavelet index 1 (0.39-0.78 Hz) will be zeroed out during transformation because its upper frequency 0.78 Hz is below the low cutoff 0.78 Hz.
[gedai.fit_epochs] INFO: Setting average reference.

  0%|          |  : 0/180 [00:00<?,       ?it/s]
  2%|▏         |  : 4/180 [00:00<00:02,   71.11it/s]
  7%|▋         |  : 12/180 [00:00<00:01,   85.16it/s]
 16%|█▌        |  : 28/180 [00:00<00:01,   94.28it/s]
 33%|███▎      |  : 60/180 [00:00<00:01,  100.79it/s]
 51%|█████     |  : 92/180 [00:00<00:00,  102.35it/s]
 69%|██████▉   |  : 124/180 [00:01<00:00,   99.31it/s]
 87%|████████▋ |  : 156/180 [00:01<00:00,   92.72it/s]
100%|██████████|  : 180/180 [00:01<00:00,  107.60it/s]
[gedai.fit_epochs] INFO: Setting average reference.

  0%|          |  : 0/180 [00:00<?,       ?it/s]
  2%|▏         |  : 4/180 [00:00<00:02,   86.27it/s]
  7%|▋         |  : 12/180 [00:00<00:01,   85.92it/s]
 16%|█▌        |  : 28/180 [00:00<00:01,   94.03it/s]
 33%|███▎      |  : 60/180 [00:00<00:01,  100.65it/s]
 51%|█████     |  : 92/180 [00:00<00:00,  102.30it/s]
 69%|██████▉   |  : 124/180 [00:01<00:00,   99.46it/s]
 87%|████████▋ |  : 156/180 [00:01<00:00,   92.54it/s]
100%|██████████|  : 180/180 [00:01<00:00,  107.44it/s]
[gedai.fit_epochs] INFO: Setting average reference.

  0%|          |  : 0/180 [00:00<?,       ?it/s]
  2%|▏         |  : 4/180 [00:00<00:02,   78.95it/s]
  7%|▋         |  : 12/180 [00:00<00:01,   86.56it/s]
 16%|█▌        |  : 28/180 [00:00<00:01,   92.47it/s]
 33%|███▎      |  : 60/180 [00:00<00:01,   99.58it/s]
 51%|█████     |  : 92/180 [00:00<00:00,   99.97it/s]
 69%|██████▉   |  : 124/180 [00:01<00:00,   95.99it/s]
 87%|████████▋ |  : 156/180 [00:01<00:00,   90.11it/s]
100%|██████████|  : 180/180 [00:01<00:00,  104.65it/s]
[gedai.fit_epochs] INFO: Setting average reference.

  0%|          |  : 0/180 [00:00<?,       ?it/s]
  2%|▏         |  : 4/180 [00:00<00:02,   80.60it/s]
  7%|▋         |  : 12/180 [00:00<00:02,   81.76it/s]
 16%|█▌        |  : 28/180 [00:00<00:01,   89.27it/s]
 33%|███▎      |  : 60/180 [00:00<00:01,   94.61it/s]
 51%|█████     |  : 92/180 [00:00<00:00,   94.57it/s]
 69%|██████▉   |  : 124/180 [00:01<00:00,   91.13it/s]
 87%|████████▋ |  : 156/180 [00:01<00:00,   86.99it/s]
100%|██████████|  : 180/180 [00:01<00:00,  100.89it/s]
[gedai.fit_epochs] INFO: Setting average reference.

  0%|          |  : 0/180 [00:00<?,       ?it/s]
  2%|▏         |  : 4/180 [00:00<00:02,   85.61it/s]
  7%|▋         |  : 12/180 [00:00<00:01,   90.37it/s]
 16%|█▌        |  : 28/180 [00:00<00:01,   97.66it/s]
 33%|███▎      |  : 60/180 [00:00<00:01,  102.28it/s]
 51%|█████     |  : 92/180 [00:00<00:00,  100.67it/s]
 69%|██████▉   |  : 124/180 [00:01<00:00,   95.22it/s]
 87%|████████▋ |  : 156/180 [00:01<00:00,   89.83it/s]
100%|██████████|  : 180/180 [00:01<00:00,  104.47it/s]
[gedai.fit_epochs] INFO: Setting average reference.

  0%|          |  : 0/180 [00:00<?,       ?it/s]
  2%|▏         |  : 4/180 [00:00<00:02,   86.01it/s]
  7%|▋         |  : 12/180 [00:00<00:01,   89.91it/s]
 16%|█▌        |  : 28/180 [00:00<00:01,   93.87it/s]
 33%|███▎      |  : 60/180 [00:00<00:01,  100.93it/s]
 51%|█████     |  : 92/180 [00:00<00:00,   97.34it/s]
 69%|██████▉   |  : 124/180 [00:01<00:00,   92.74it/s]
 87%|████████▋ |  : 156/180 [00:01<00:00,   88.06it/s]
100%|██████████|  : 180/180 [00:01<00:00,  102.35it/s]
[gedai.fit_epochs] INFO: Setting average reference.

  0%|          |  : 0/180 [00:00<?,       ?it/s]
  2%|▏         |  : 4/180 [00:00<00:01,   88.20it/s]
  7%|▋         |  : 12/180 [00:00<00:01,   91.23it/s]
 16%|█▌        |  : 28/180 [00:00<00:01,   94.86it/s]
 33%|███▎      |  : 60/180 [00:00<00:01,   97.55it/s]
 51%|█████     |  : 92/180 [00:00<00:00,   94.79it/s]
 69%|██████▉   |  : 124/180 [00:01<00:00,   90.55it/s]
 87%|████████▋ |  : 156/180 [00:01<00:00,   86.13it/s]
100%|██████████|  : 180/180 [00:01<00:00,  100.11it/s]

Note

Since multiband GEDAI uses spectral decomposition, the fitting process will automatically adjust the epoch duration to ensure that each epoch contains a number of samples appropriate for the wavelet decomposition.

fig = multiband_gedai.plot_fit()
plt.show()
  • Band 3: 0.78-1.56 Hz
  • Band 4: 1.56-3.12 Hz
  • Band 5: 3.12-6.25 Hz
  • Band 6: 6.25-12.50 Hz
  • Band 7: 12.50-25.00 Hz
  • Band 8: 25.00-50.00 Hz
  • Band 9: 50.00-100.00 Hz

Transform the Data (Denoising)🔗

Once fitted, the Multiband GEDAI model can be used to remove artifacts and noise from the data. The transform operation projects out the noise components while preserving the brain signals for each frequency band separately before recombining them.

denoised_raw = multiband_gedai.transform_raw(raw, n_jobs=n_jobs, verbose=False)

Warning

Since the Multiband GEDAI operates on epoched data internally, some frequency content more particularly in lower frequency bands may be not be captured properly if the epoch duration is too short. On the other hand, using very long epochs may prevent to capture short transient artifacts. Setting the wavelet_low_cutoff parameter to a value of the order of 1 / epoch_duration can help mitigate this issue by excluding lower frequency bands that may not be well estimated during the fitting process.

plot_mne_style_overlay_interactive(raw, denoised_raw)
10 gedai multiband
(<Figure size 1200x1750 with 1 Axes>, <Axes: xlabel='Time (s)', ylabel='Channels'>)

Total running time of the script: (1 minutes 13.255 seconds)

Estimated memory usage: 442 MB

Gallery generated by Sphinx-Gallery