Extracting spectral connectivty features of single trials

I am working with EEG and EMG data (during gait) and I want to calculate the corticomuscular coherence using the mne_connectivity.spectral_connectivity functions.

I have seen that there is two functions I could use, namely,

  • mne_connecticity.spectral_connectivity_epochs (for time locked events, averaging over trials)
  • mne_connectivity.spectral_connectivity_time

I have my data epoched in gait cycles and I want to incorporate the connectivity features to my pipeline. However, I am not sure what is the correct way of doing it since my data is indeed time locked (to the different gait events) but the feature extraction is epoch specific so I cannot average across them. Which function/approach should I take?

If you need a connectivity value for each epoch, then only spectral_connectivity_time() supports this. This can be done with either the multitaper or Morlet wavelet modes with average=False.

However, this will not provide you with connectivity values over the timecourse of each epoch.

If the data of each epoch is homogeneous (i.e. contains data from a similar part of the gait cycle), then aggregating over this information to get the epoch-resolved connectivity is fine. That is to say: there is no issue applying spectral_connectivity_time() to time-locked events in principle.

What is not possible is to have both an epoch- and timecourse-resolved connectivity output.

Hope this helps!

It does help, thanks a lot!

1 Like

So now, I would like to compute the connectivity averaged over epochs using spectral_connectivity_epochs(). However, I have some concerns since my epochs have different lengths.

I have tried to run spectral_connectivty_epochs individually in each epoch to then interpolate the connectivity matrix (to the max time interval normalizing to 0-100% of the epoch) and average them. However, the output when using cwt_morlet is always 1. I don´t know if this expected since I am only feeding one epoch (which is likely to produce unreliable results) or if it still should produce more meaningful results.

The second approach that I was thinking of was to zero-padd the shorter epochs to match the lengths and then feed them into spectral_connectivity_epochs. However, I am not sure of what implications this could have in the connectivity output.

Thanks in advance for the feedback

Sorry, I didn’t see this.


I have tried to run spectral_connectivty_epochs individually in each epoch to then interpolate the connectivity matrix (to the max time interval normalizing to 0-100% of the epoch) and average them. However, the output when using cwt_morlet is always 1. I don´t know if this expected since I am only feeding one epoch (which is likely to produce unreliable results) or if it still should produce more meaningful results.

I don’t believe connectivity estimation using Morlet wavelets works with a single epoch.


The second approach that I was thinking of was to zero-padd the shorter epochs to match the lengths and then feed them into spectral_connectivity_epochs. However, I am not sure of what implications this could have in the connectivity output.

So using a method other than Morlet wavelets this could work for coherence (results would not be identical to if there was no zero-padding, but would likely be similar).

However with a time-frequency method my concern would be if there are times which are consistently padded over a large number of epochs, then averaging the connectivity across epochs would suppress any estimates of connectivity during these times.


Of course, the safest approach would be to trim everything down to the shortest epoch duration available.

1 Like