Spectral connectivity

Hi,
I’m trying to analyze EEG coherence from raw data acquired using ADInstruments’ LabChart.
I pick 30s epochs of raw data during resting state from two channels and export it to a txt file.
I use the spectral_connectivity function on list of epochs. Each element on this list is an array of 2 by 30000 (sampling freq: 1kHz). It appears to work fine when I’m using multiple epochs but when I take just one it show coh to be 1. over all chosen frequencies-- which means I’m not doing something right.

Here is the code I’m using:

import numpy as np
from pathlib import Path
from mne.connectivity import spectral_connectivity

fmin = (0.5, 4, 8, 12, 30, 60)
fmax = (4, 8, 12, 30, 50, 100)
sfreq = 1000
indices1 = (np.array([0]), np.array([1]))

lst = []

n = int(input("Enter number of epochs: "))

for i in range(0, n):
    ele = str(input())

    lst.append(ele)  

data_set = [np.loadtxt(p, usecols=(1, 2)).transpose() for p in lst]

coh, freqs, times, n_epochs, n_tapers = spectral_connectivity(
    data_set,
    method="coh",
    mode="fourier",
    indices=indices1,
    sfreq=sfreq,
    fmin=fmin,
    fmax=fmax,
    faverage=True,
    n_jobs=1,
)

I looked your coherence example (" Compute coherence in source space using a MNE inverse solution"), which, as far as I understands, deals with event related data. I scammed through the irrelevant parts and got to “Choose channels for coherence estimation” which I think might be related to my problem.

so I guess my question is-
Am I using the correct form of input data? why is not working on 1 epoch and whats stc and inverse operator has to do with it… since I have a basic background in signal processing I was looking for a rather straight answer on the web and couldnt find one.

Hope I was clear enough… Be happy to provide txt files of raw data if needed.
Thank you!! :blush: :blush:

Hello, I’m just pinging @agramfort, maybe he has an idea…

hi,

yes it’s because we average over epochs and not across the time dimension.
If you have one epoch it’s then just one that you get.

Alex