Compute a cross-spectral density (CSD) matrix#

A cross-spectral density (CSD) matrix is similar to a covariance matrix, but in the time-frequency domain. It is the first step towards computing sensor-to-sensor coherence or a DICS beamformer.

This script demonstrates the three methods that MNE-Python provides to compute the CSD:

  1. Using short-term Fourier transform: mne.time_frequency.csd_fourier()

  2. Using a multitaper approach: mne.time_frequency.csd_multitaper()

  3. Using Morlet wavelets: mne.time_frequency.csd_morlet()

# Author: Marijn van Vliet <w.m.vanvliet@gmail.com>
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.
import mne
from mne.datasets import sample
from mne.time_frequency import csd_fourier, csd_morlet, csd_multitaper

print(__doc__)

In the following example, the computation of the CSD matrices can be performed using multiple cores. Set n_jobs to a value >1 to select the number of cores to use.

n_jobs = 1

Loading the sample dataset.

data_path = sample.data_path()
meg_path = data_path / "MEG" / "sample"
fname_raw = meg_path / "sample_audvis_raw.fif"
fname_event = meg_path / "sample_audvis_raw-eve.fif"
raw = mne.io.read_raw_fif(fname_raw)
events = mne.read_events(fname_event)
Opening raw data file /home/circleci/mne_data/MNE-sample-data/MEG/sample/sample_audvis_raw.fif...
    Read a total of 3 projection items:
        PCA-v1 (1 x 102)  idle
        PCA-v2 (1 x 102)  idle
        PCA-v3 (1 x 102)  idle
    Range : 25800 ... 192599 =     42.956 ...   320.670 secs
Ready.

By default, CSD matrices are computed using all MEG/EEG channels. When interpreting a CSD matrix with mixed sensor types, be aware that the measurement units, and thus the scalings, differ across sensors. In this example, for speed and clarity, we select a single channel type: gradiometers.

picks = mne.pick_types(raw.info, meg="grad")

# Make some epochs, based on events with trigger code 1
epochs = mne.Epochs(
    raw,
    events,
    event_id=1,
    tmin=-0.2,
    tmax=1,
    picks=picks,
    baseline=(None, 0),
    reject=dict(grad=4000e-13),
    preload=True,
)
Not setting metadata
72 matching events found
Setting baseline interval to [-0.19979521315838786, 0.0] s
Applying baseline correction (mode: mean)
3 projection items activated
Loading data for 72 events and 722 original time points ...
0 bad epochs dropped

Computing CSD matrices using short-term Fourier transform and (adaptive) multitapers is straightforward:

csd_fft = csd_fourier(epochs, fmin=15, fmax=20, n_jobs=n_jobs)
csd_mt = csd_multitaper(epochs, fmin=15, fmax=20, adaptive=True, n_jobs=n_jobs)
Removing projector <Projection | PCA-v1, active : True, n_channels : 102>
Removing projector <Projection | PCA-v2, active : True, n_channels : 102>
Removing projector <Projection | PCA-v3, active : True, n_channels : 102>
Computing cross-spectral density from epochs...

  0%|          | CSD epoch blocks : 0/72 [00:00<?,       ?it/s]
  1%|▏         | CSD epoch blocks : 1/72 [00:00<00:03,   23.40it/s]
  3%|▎         | CSD epoch blocks : 2/72 [00:00<00:02,   32.35it/s]
  4%|▍         | CSD epoch blocks : 3/72 [00:00<00:01,   37.35it/s]
  6%|▌         | CSD epoch blocks : 4/72 [00:00<00:01,   40.70it/s]
  7%|▋         | CSD epoch blocks : 5/72 [00:00<00:01,   42.61it/s]
  8%|▊         | CSD epoch blocks : 6/72 [00:00<00:01,   43.69it/s]
 10%|▉         | CSD epoch blocks : 7/72 [00:00<00:01,   44.38it/s]
 11%|█         | CSD epoch blocks : 8/72 [00:00<00:01,   44.85it/s]
 12%|█▎        | CSD epoch blocks : 9/72 [00:00<00:01,   45.71it/s]
 14%|█▍        | CSD epoch blocks : 10/72 [00:00<00:01,   45.33it/s]
 15%|█▌        | CSD epoch blocks : 11/72 [00:00<00:01,   44.86it/s]
 17%|█▋        | CSD epoch blocks : 12/72 [00:00<00:01,   45.48it/s]
 18%|█▊        | CSD epoch blocks : 13/72 [00:00<00:01,   46.24it/s]
 19%|█▉        | CSD epoch blocks : 14/72 [00:00<00:01,   46.79it/s]
 21%|██        | CSD epoch blocks : 15/72 [00:00<00:01,   46.07it/s]
 22%|██▏       | CSD epoch blocks : 16/72 [00:00<00:01,   44.68it/s]
 24%|██▎       | CSD epoch blocks : 17/72 [00:00<00:01,   44.30it/s]
 25%|██▌       | CSD epoch blocks : 18/72 [00:00<00:01,   44.77it/s]
 26%|██▋       | CSD epoch blocks : 19/72 [00:00<00:01,   44.75it/s]
 28%|██▊       | CSD epoch blocks : 20/72 [00:00<00:01,   44.97it/s]
 29%|██▉       | CSD epoch blocks : 21/72 [00:00<00:01,   44.38it/s]
 31%|███       | CSD epoch blocks : 22/72 [00:00<00:01,   44.03it/s]
 32%|███▏      | CSD epoch blocks : 23/72 [00:00<00:01,   43.73it/s]
 33%|███▎      | CSD epoch blocks : 24/72 [00:00<00:01,   43.53it/s]
 35%|███▍      | CSD epoch blocks : 25/72 [00:00<00:01,   43.26it/s]
 36%|███▌      | CSD epoch blocks : 26/72 [00:00<00:01,   43.15it/s]
 38%|███▊      | CSD epoch blocks : 27/72 [00:00<00:01,   42.93it/s]
 39%|███▉      | CSD epoch blocks : 28/72 [00:00<00:01,   42.96it/s]
 40%|████      | CSD epoch blocks : 29/72 [00:00<00:00,   43.64it/s]
 42%|████▏     | CSD epoch blocks : 30/72 [00:00<00:00,   44.30it/s]
 43%|████▎     | CSD epoch blocks : 31/72 [00:00<00:00,   44.95it/s]
 44%|████▍     | CSD epoch blocks : 32/72 [00:00<00:00,   45.46it/s]
 46%|████▌     | CSD epoch blocks : 33/72 [00:00<00:00,   45.59it/s]
 47%|████▋     | CSD epoch blocks : 34/72 [00:00<00:00,   46.13it/s]
 49%|████▊     | CSD epoch blocks : 35/72 [00:00<00:00,   46.65it/s]
 50%|█████     | CSD epoch blocks : 36/72 [00:00<00:00,   47.14it/s]
 51%|█████▏    | CSD epoch blocks : 37/72 [00:00<00:00,   47.40it/s]
 53%|█████▎    | CSD epoch blocks : 38/72 [00:00<00:00,   47.59it/s]
 54%|█████▍    | CSD epoch blocks : 39/72 [00:00<00:00,   47.79it/s]
 56%|█████▌    | CSD epoch blocks : 40/72 [00:00<00:00,   48.19it/s]
 57%|█████▋    | CSD epoch blocks : 41/72 [00:00<00:00,   48.35it/s]
 58%|█████▊    | CSD epoch blocks : 42/72 [00:00<00:00,   48.12it/s]
 60%|█████▉    | CSD epoch blocks : 43/72 [00:00<00:00,   48.21it/s]
 61%|██████    | CSD epoch blocks : 44/72 [00:00<00:00,   48.57it/s]
 62%|██████▎   | CSD epoch blocks : 45/72 [00:00<00:00,   49.01it/s]
 64%|██████▍   | CSD epoch blocks : 46/72 [00:00<00:00,   49.34it/s]
 65%|██████▌   | CSD epoch blocks : 47/72 [00:01<00:00,   49.34it/s]
 67%|██████▋   | CSD epoch blocks : 48/72 [00:01<00:00,   48.87it/s]
 68%|██████▊   | CSD epoch blocks : 49/72 [00:01<00:00,   49.28it/s]
 69%|██████▉   | CSD epoch blocks : 50/72 [00:01<00:00,   49.67it/s]
 71%|███████   | CSD epoch blocks : 51/72 [00:01<00:00,   50.04it/s]
 72%|███████▏  | CSD epoch blocks : 52/72 [00:01<00:00,   50.46it/s]
 74%|███████▎  | CSD epoch blocks : 53/72 [00:01<00:00,   50.07it/s]
 75%|███████▌  | CSD epoch blocks : 54/72 [00:01<00:00,   50.15it/s]
 76%|███████▋  | CSD epoch blocks : 55/72 [00:01<00:00,   50.29it/s]
 78%|███████▊  | CSD epoch blocks : 56/72 [00:01<00:00,   50.67it/s]
 79%|███████▉  | CSD epoch blocks : 57/72 [00:01<00:00,   50.49it/s]
 81%|████████  | CSD epoch blocks : 58/72 [00:01<00:00,   49.65it/s]
 82%|████████▏ | CSD epoch blocks : 59/72 [00:01<00:00,   49.85it/s]
 83%|████████▎ | CSD epoch blocks : 60/72 [00:01<00:00,   49.94it/s]
 85%|████████▍ | CSD epoch blocks : 61/72 [00:01<00:00,   49.97it/s]
 86%|████████▌ | CSD epoch blocks : 62/72 [00:01<00:00,   50.38it/s]
 88%|████████▊ | CSD epoch blocks : 63/72 [00:01<00:00,   50.64it/s]
 89%|████████▉ | CSD epoch blocks : 64/72 [00:01<00:00,   50.79it/s]
 90%|█████████ | CSD epoch blocks : 65/72 [00:01<00:00,   50.84it/s]
 92%|█████████▏| CSD epoch blocks : 66/72 [00:01<00:00,   51.09it/s]
 93%|█████████▎| CSD epoch blocks : 67/72 [00:01<00:00,   51.35it/s]
 94%|█████████▍| CSD epoch blocks : 68/72 [00:01<00:00,   51.46it/s]
 96%|█████████▌| CSD epoch blocks : 69/72 [00:01<00:00,   51.55it/s]
 97%|█████████▋| CSD epoch blocks : 70/72 [00:01<00:00,   51.74it/s]
 99%|█████████▊| CSD epoch blocks : 71/72 [00:01<00:00,   51.96it/s]
100%|██████████| CSD epoch blocks : 72/72 [00:01<00:00,   52.16it/s]
100%|██████████| CSD epoch blocks : 72/72 [00:01<00:00,   48.75it/s]
[done]
Removing projector <Projection | PCA-v1, active : True, n_channels : 102>
Removing projector <Projection | PCA-v2, active : True, n_channels : 102>
Removing projector <Projection | PCA-v3, active : True, n_channels : 102>
    Using multitaper spectrum estimation with 7 DPSS windows
Computing cross-spectral density from epochs...

  0%|          | CSD epoch blocks : 0/72 [00:00<?,       ?it/s]
  1%|▏         | CSD epoch blocks : 1/72 [00:00<00:26,    2.71it/s]
  3%|▎         | CSD epoch blocks : 2/72 [00:00<00:20,    3.42it/s]
  4%|▍         | CSD epoch blocks : 3/72 [00:00<00:21,    3.22it/s]
  6%|▌         | CSD epoch blocks : 4/72 [00:01<00:19,    3.50it/s]
  7%|▋         | CSD epoch blocks : 5/72 [00:01<00:18,    3.72it/s]
  8%|▊         | CSD epoch blocks : 6/72 [00:01<00:18,    3.62it/s]
 10%|▉         | CSD epoch blocks : 7/72 [00:02<00:18,    3.49it/s]
 11%|█         | CSD epoch blocks : 8/72 [00:02<00:17,    3.64it/s]
 12%|█▎        | CSD epoch blocks : 9/72 [00:02<00:19,    3.23it/s]
 14%|█▍        | CSD epoch blocks : 10/72 [00:03<00:18,    3.29it/s]
 15%|█▌        | CSD epoch blocks : 11/72 [00:03<00:17,    3.43it/s]
 17%|█▋        | CSD epoch blocks : 12/72 [00:03<00:17,    3.38it/s]
 18%|█▊        | CSD epoch blocks : 13/72 [00:03<00:16,    3.53it/s]
 19%|█▉        | CSD epoch blocks : 14/72 [00:03<00:15,    3.67it/s]
 21%|██        | CSD epoch blocks : 15/72 [00:04<00:15,    3.78it/s]
 22%|██▏       | CSD epoch blocks : 16/72 [00:04<00:14,    3.85it/s]
 24%|██▎       | CSD epoch blocks : 17/72 [00:04<00:13,    3.98it/s]
 25%|██▌       | CSD epoch blocks : 18/72 [00:04<00:13,    4.10it/s]
 26%|██▋       | CSD epoch blocks : 19/72 [00:04<00:12,    4.12it/s]
 28%|██▊       | CSD epoch blocks : 20/72 [00:04<00:12,    4.23it/s]
 29%|██▉       | CSD epoch blocks : 21/72 [00:05<00:11,    4.29it/s]
 31%|███       | CSD epoch blocks : 22/72 [00:05<00:11,    4.35it/s]
 32%|███▏      | CSD epoch blocks : 23/72 [00:05<00:11,    4.23it/s]
 33%|███▎      | CSD epoch blocks : 24/72 [00:05<00:11,    4.32it/s]
 35%|███▍      | CSD epoch blocks : 25/72 [00:06<00:10,    4.41it/s]
 36%|███▌      | CSD epoch blocks : 26/72 [00:06<00:10,    4.50it/s]
 38%|███▊      | CSD epoch blocks : 27/72 [00:06<00:09,    4.57it/s]
 39%|███▉      | CSD epoch blocks : 28/72 [00:06<00:09,    4.64it/s]
 40%|████      | CSD epoch blocks : 29/72 [00:06<00:09,    4.69it/s]
 42%|████▏     | CSD epoch blocks : 30/72 [00:06<00:08,    4.76it/s]
 43%|████▎     | CSD epoch blocks : 31/72 [00:07<00:08,    4.84it/s]
 44%|████▍     | CSD epoch blocks : 32/72 [00:07<00:08,    4.85it/s]
 46%|████▌     | CSD epoch blocks : 33/72 [00:07<00:08,    4.87it/s]
 47%|████▋     | CSD epoch blocks : 34/72 [00:07<00:07,    4.95it/s]
 49%|████▊     | CSD epoch blocks : 35/72 [00:07<00:07,    5.03it/s]
 50%|█████     | CSD epoch blocks : 36/72 [00:08<00:08,    4.33it/s]
 51%|█████▏    | CSD epoch blocks : 37/72 [00:08<00:07,    4.41it/s]
 53%|█████▎    | CSD epoch blocks : 38/72 [00:08<00:07,    4.49it/s]
 54%|█████▍    | CSD epoch blocks : 39/72 [00:08<00:07,    4.57it/s]
 56%|█████▌    | CSD epoch blocks : 40/72 [00:09<00:06,    4.65it/s]
 57%|█████▋    | CSD epoch blocks : 41/72 [00:09<00:06,    4.72it/s]
 58%|█████▊    | CSD epoch blocks : 42/72 [00:09<00:06,    4.79it/s]
 60%|█████▉    | CSD epoch blocks : 43/72 [00:09<00:05,    4.87it/s]
 61%|██████    | CSD epoch blocks : 44/72 [00:09<00:05,    4.93it/s]
 62%|██████▎   | CSD epoch blocks : 45/72 [00:09<00:05,    4.98it/s]
 64%|██████▍   | CSD epoch blocks : 46/72 [00:10<00:05,    5.06it/s]
 65%|██████▌   | CSD epoch blocks : 47/72 [00:10<00:04,    5.13it/s]
 67%|██████▋   | CSD epoch blocks : 48/72 [00:10<00:04,    5.20it/s]
 68%|██████▊   | CSD epoch blocks : 49/72 [00:10<00:04,    5.26it/s]
 69%|██████▉   | CSD epoch blocks : 50/72 [00:10<00:04,    5.33it/s]
 71%|███████   | CSD epoch blocks : 51/72 [00:10<00:03,    5.40it/s]
 72%|███████▏  | CSD epoch blocks : 52/72 [00:10<00:03,    5.45it/s]
 74%|███████▎  | CSD epoch blocks : 53/72 [00:11<00:03,    5.50it/s]
 75%|███████▌  | CSD epoch blocks : 54/72 [00:11<00:03,    5.56it/s]
 76%|███████▋  | CSD epoch blocks : 55/72 [00:11<00:03,    5.58it/s]
 78%|███████▊  | CSD epoch blocks : 56/72 [00:12<00:03,    4.42it/s]
 79%|███████▉  | CSD epoch blocks : 57/72 [00:12<00:03,    4.51it/s]
 81%|████████  | CSD epoch blocks : 58/72 [00:12<00:03,    4.59it/s]
 82%|████████▏ | CSD epoch blocks : 59/72 [00:12<00:02,    4.67it/s]
 83%|████████▎ | CSD epoch blocks : 60/72 [00:13<00:02,    4.74it/s]
 85%|████████▍ | CSD epoch blocks : 61/72 [00:13<00:02,    4.82it/s]
 86%|████████▌ | CSD epoch blocks : 62/72 [00:13<00:02,    4.89it/s]
 88%|████████▊ | CSD epoch blocks : 63/72 [00:13<00:01,    4.96it/s]
 89%|████████▉ | CSD epoch blocks : 64/72 [00:13<00:01,    4.97it/s]
 90%|█████████ | CSD epoch blocks : 65/72 [00:13<00:01,    4.99it/s]
 92%|█████████▏| CSD epoch blocks : 66/72 [00:14<00:01,    4.34it/s]
 93%|█████████▎| CSD epoch blocks : 67/72 [00:14<00:01,    4.40it/s]
 94%|█████████▍| CSD epoch blocks : 68/72 [00:14<00:00,    4.45it/s]
 96%|█████████▌| CSD epoch blocks : 69/72 [00:15<00:00,    4.47it/s]
 97%|█████████▋| CSD epoch blocks : 70/72 [00:15<00:00,    4.54it/s]
 99%|█████████▊| CSD epoch blocks : 71/72 [00:15<00:00,    4.62it/s]
100%|██████████| CSD epoch blocks : 72/72 [00:15<00:00,    4.69it/s]
100%|██████████| CSD epoch blocks : 72/72 [00:15<00:00,    4.60it/s]
[done]

When computing the CSD with Morlet wavelets, you specify the exact frequencies at which to compute it. For each frequency, a corresponding wavelet will be constructed and convolved with the signal, resulting in a time-frequency decomposition.

The CSD is constructed by computing the correlation between the time-frequency representations between all sensor-to-sensor pairs. The time-frequency decomposition originally has the same sampling rate as the signal, in our case ~600Hz. This means the decomposition is over-specified in time and we may not need to use all samples during our CSD computation, just enough to get a reliable correlation statistic. By specifying decim=10, we use every 10th sample, which will greatly speed up the computation and will have a minimal effect on the CSD.

frequencies = [16, 17, 18, 19, 20]
csd_wav = csd_morlet(epochs, frequencies, decim=10, n_jobs=n_jobs)
Removing projector <Projection | PCA-v1, active : True, n_channels : 102>
Removing projector <Projection | PCA-v2, active : True, n_channels : 102>
Removing projector <Projection | PCA-v3, active : True, n_channels : 102>
Computing cross-spectral density from epochs...

  0%|          | CSD epoch blocks : 0/72 [00:00<?,       ?it/s]
  1%|▏         | CSD epoch blocks : 1/72 [00:00<00:07,    9.15it/s]
  3%|▎         | CSD epoch blocks : 2/72 [00:00<00:06,   11.16it/s]
  4%|▍         | CSD epoch blocks : 3/72 [00:00<00:05,   12.03it/s]
  6%|▌         | CSD epoch blocks : 4/72 [00:00<00:05,   12.55it/s]
  7%|▋         | CSD epoch blocks : 5/72 [00:00<00:05,   12.84it/s]
  8%|▊         | CSD epoch blocks : 6/72 [00:00<00:05,   13.05it/s]
 10%|▉         | CSD epoch blocks : 7/72 [00:00<00:04,   13.20it/s]
 11%|█         | CSD epoch blocks : 8/72 [00:00<00:04,   13.31it/s]
 12%|█▎        | CSD epoch blocks : 9/72 [00:00<00:04,   13.40it/s]
 14%|█▍        | CSD epoch blocks : 10/72 [00:00<00:04,   13.45it/s]
 15%|█▌        | CSD epoch blocks : 11/72 [00:00<00:04,   13.38it/s]
 17%|█▋        | CSD epoch blocks : 12/72 [00:00<00:04,   13.46it/s]
 18%|█▊        | CSD epoch blocks : 13/72 [00:00<00:04,   13.51it/s]
 19%|█▉        | CSD epoch blocks : 14/72 [00:01<00:04,   13.53it/s]
 21%|██        | CSD epoch blocks : 15/72 [00:01<00:04,   13.40it/s]
 22%|██▏       | CSD epoch blocks : 16/72 [00:01<00:04,   13.44it/s]
 24%|██▎       | CSD epoch blocks : 17/72 [00:01<00:04,   13.49it/s]
 25%|██▌       | CSD epoch blocks : 18/72 [00:01<00:04,   13.43it/s]
 26%|██▋       | CSD epoch blocks : 19/72 [00:01<00:03,   13.45it/s]
 28%|██▊       | CSD epoch blocks : 20/72 [00:01<00:03,   13.48it/s]
 29%|██▉       | CSD epoch blocks : 21/72 [00:01<00:03,   13.54it/s]
 31%|███       | CSD epoch blocks : 22/72 [00:01<00:03,   13.59it/s]
 32%|███▏      | CSD epoch blocks : 23/72 [00:01<00:03,   13.63it/s]
 33%|███▎      | CSD epoch blocks : 24/72 [00:01<00:03,   13.67it/s]
 35%|███▍      | CSD epoch blocks : 25/72 [00:01<00:03,   13.64it/s]
 36%|███▌      | CSD epoch blocks : 26/72 [00:01<00:03,   13.62it/s]
 38%|███▊      | CSD epoch blocks : 27/72 [00:01<00:03,   13.62it/s]
 39%|███▉      | CSD epoch blocks : 28/72 [00:02<00:03,   13.60it/s]
 40%|████      | CSD epoch blocks : 29/72 [00:02<00:03,   13.59it/s]
 42%|████▏     | CSD epoch blocks : 30/72 [00:02<00:03,   13.57it/s]
 43%|████▎     | CSD epoch blocks : 31/72 [00:02<00:03,   13.57it/s]
 44%|████▍     | CSD epoch blocks : 32/72 [00:02<00:02,   13.57it/s]
 46%|████▌     | CSD epoch blocks : 33/72 [00:02<00:02,   13.61it/s]
 47%|████▋     | CSD epoch blocks : 34/72 [00:02<00:02,   13.65it/s]
 49%|████▊     | CSD epoch blocks : 35/72 [00:02<00:02,   13.62it/s]
 50%|█████     | CSD epoch blocks : 36/72 [00:02<00:02,   13.43it/s]
 51%|█████▏    | CSD epoch blocks : 37/72 [00:02<00:02,   13.47it/s]
 53%|█████▎    | CSD epoch blocks : 38/72 [00:02<00:02,   13.50it/s]
 54%|█████▍    | CSD epoch blocks : 39/72 [00:02<00:02,   13.49it/s]
 56%|█████▌    | CSD epoch blocks : 40/72 [00:02<00:02,   13.44it/s]
 57%|█████▋    | CSD epoch blocks : 41/72 [00:03<00:02,   13.25it/s]
 58%|█████▊    | CSD epoch blocks : 42/72 [00:03<00:02,   13.15it/s]
 60%|█████▉    | CSD epoch blocks : 43/72 [00:03<00:02,   13.05it/s]
 61%|██████    | CSD epoch blocks : 44/72 [00:03<00:02,   13.00it/s]
 62%|██████▎   | CSD epoch blocks : 45/72 [00:03<00:02,   13.05it/s]
 64%|██████▍   | CSD epoch blocks : 46/72 [00:03<00:01,   13.08it/s]
 65%|██████▌   | CSD epoch blocks : 47/72 [00:03<00:01,   13.11it/s]
 67%|██████▋   | CSD epoch blocks : 48/72 [00:03<00:01,   13.10it/s]
 68%|██████▊   | CSD epoch blocks : 49/72 [00:03<00:01,   13.12it/s]
 69%|██████▉   | CSD epoch blocks : 50/72 [00:03<00:01,   13.14it/s]
 71%|███████   | CSD epoch blocks : 51/72 [00:03<00:01,   13.17it/s]
 72%|███████▏  | CSD epoch blocks : 52/72 [00:03<00:01,   13.19it/s]
 74%|███████▎  | CSD epoch blocks : 53/72 [00:03<00:01,   13.23it/s]
 75%|███████▌  | CSD epoch blocks : 54/72 [00:04<00:01,   13.27it/s]
 76%|███████▋  | CSD epoch blocks : 55/72 [00:04<00:01,   13.30it/s]
 78%|███████▊  | CSD epoch blocks : 56/72 [00:04<00:01,   13.34it/s]
 79%|███████▉  | CSD epoch blocks : 57/72 [00:04<00:01,   13.37it/s]
 81%|████████  | CSD epoch blocks : 58/72 [00:04<00:01,   13.39it/s]
 82%|████████▏ | CSD epoch blocks : 59/72 [00:04<00:00,   13.37it/s]
 83%|████████▎ | CSD epoch blocks : 60/72 [00:04<00:00,   13.38it/s]
 85%|████████▍ | CSD epoch blocks : 61/72 [00:04<00:00,   13.37it/s]
 86%|████████▌ | CSD epoch blocks : 62/72 [00:04<00:00,   13.39it/s]
 88%|████████▊ | CSD epoch blocks : 63/72 [00:04<00:00,   13.42it/s]
 89%|████████▉ | CSD epoch blocks : 64/72 [00:04<00:00,   13.46it/s]
 90%|█████████ | CSD epoch blocks : 65/72 [00:04<00:00,   13.48it/s]
 92%|█████████▏| CSD epoch blocks : 66/72 [00:04<00:00,   13.51it/s]
 93%|█████████▎| CSD epoch blocks : 67/72 [00:04<00:00,   13.53it/s]
 94%|█████████▍| CSD epoch blocks : 68/72 [00:05<00:00,   13.53it/s]
 96%|█████████▌| CSD epoch blocks : 69/72 [00:05<00:00,   13.55it/s]
 97%|█████████▋| CSD epoch blocks : 70/72 [00:05<00:00,   13.57it/s]
 99%|█████████▊| CSD epoch blocks : 71/72 [00:05<00:00,   13.58it/s]
100%|██████████| CSD epoch blocks : 72/72 [00:05<00:00,   13.60it/s]
100%|██████████| CSD epoch blocks : 72/72 [00:05<00:00,   13.44it/s]
[done]

The resulting mne.time_frequency.CrossSpectralDensity objects have a plotting function we can use to compare the results of the different methods. We’re plotting the mean CSD across frequencies. mne.time_frequency.CrossSpectralDensity.plot() returns a list of created figures; in this case, each returned list has only one figure so we use a Python trick of including a comma after our variable name to assign the figure (not the list) to our fig variable:

plot_dict = {
    "Short-time Fourier transform": csd_fft,
    "Adaptive multitapers": csd_mt,
    "Morlet wavelet transform": csd_wav,
}
for title, csd in plot_dict.items():
    (fig,) = csd.mean().plot()
    fig.suptitle(title)
  • Short-time Fourier transform, 15.8-20.0 Hz.
  • Adaptive multitapers, 15.8-20.0 Hz.
  • Morlet wavelet transform, 16.0-20.0 Hz.

Total running time of the script: (0 minutes 30.567 seconds)

Estimated memory usage: 248 MB

Gallery generated by Sphinx-Gallery