I would like to calculate average beta coherence on two channels from the eeg epoched data. Specifically, I am interested in the coherence of c3 and c4 channels (using connectivity_methods = [“coh”] and mode="multitaper) in the beta frequency. Please can you lmk if this is the right way to calculate coherence ? Also is it typical to calculate coherence epoch by epoch or can this be done on the raw (preprocessed) signal? I was just wondering if it would be better to filter the raw signal in the beta frequency rather than doing it epoch by epoch. Because if I need to filter epoch by epoch, then there would be some amount edge distortions.
epochs=mne.io.read_epochs_eeglab(os.path.join(directory, filename))
picks=['C3','C4']
data= epochs.get_data(picks=picks)
Freq_Bands = {"beta": [13.0, 30.0]}
n_freq_bands = len ( Freq_Bands )
fmin = tuple ( [list ( Freq_Bands.values () ) [f] [0] for f in range ( len ( Freq_Bands ) )] )
fmax = tuple ( [list ( Freq_Bands.values () ) [f] [1] for f in range ( len ( Freq_Bands ) )] )
sfreq=epochs.info['sfreq']
ch_names=epochs.info['ch_names']
connectivity_methods = ["coh"]
n_con_methods = len ( connectivity_methods )
con, freqs, times, n_epochs, n_tapers = spectral_connectivity (
data, method=connectivity_methods,
mode="multitaper", sfreq=2000, fmin=fmin, fmax=fmax,
faverage=True, verbose=0 )
con.mean()
The paper looks into beta coherence for all channels, but I am interested not only at the global beta coherence (all channels) but also just the motor cortex area, so I want to focus on c3 and c4 channels.
yes, it is generally better to filter the raw object rather than filtering the epochs, for exactly the reason you mentioned (edge artifacts). But you can do this and then still do your coherence analysis on epochs: the sequence of events is
bandpass filter the raw object: raw.filter(fmin, fmax, ...)
extract epochs: epochs = mne.Epochs(raw, ...)
extract data: data = epochs.get_data(picks=['C3', 'C4'])
pragmatic answer: because spectral_connectivity accepts either an Epochs object or a NumPy array of shape n_epochs, n_signals, n_times.
I think you could do it on raw data by simply adding a np.newaxis to the beginning of the array, but I don’t know what implications that would have for the speed of computation and/or the validity of the result. Maybe @adam2392 knows those implications?
Maybe the other expert can correct me. But what I can summaries from previous post that it is possible to do connectivity across time as long as the window is long enough to compensate for the bias in the connectivity.