# Spectral connectivity

**URL:** <https://mne.discourse.group/t/spectral-connectivity/2754>\
**Category:** Support & Discussions\
**Tags:** connectivity\
**Created:** [February 26, 2021, 5:20am UTC](https://mne.discourse.group/t/spectral-connectivity/2754 "2021-02-26T05:20:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![morovadia](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/morovadia/32/230_2.png) [@morovadia](https://mne.discourse.group/u/morovadia)\
**Post date:** [February 26, 2021, 5:20am UTC](https://mne.discourse.group/t/spectral-connectivity/2754/1 "2021-02-26T05:20:55Z")

</div>

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:

```python
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!! 😊 😊

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [March 2, 2021, 2:33pm UTC](https://mne.discourse.group/t/spectral-connectivity/2754/2 "2021-03-02T14:33:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![agramfort](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@agramfort](https://mne.discourse.group/u/agramfort)\
**Post date:** [March 2, 2021, 8:12pm UTC](https://mne.discourse.group/t/spectral-connectivity/2754/3 "2021-03-02T20:12:14Z")

</div>

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
