How to determine EEG coherence?

Does anyone have a snippet for determining the spectral coherence of EEG data from two channels? I’m not really sure where to begin and a starting point would be really helpful. Thanks.

1 Like

@HindBrain What are you using for analysis? Python? Matlab? I’m assuming you’re referring to post-processing, not doing it in realtime?

I’m working on implementing something like what Chip Audette used in this experiment, but in Python. If you have Matlab (I don’t), take a look at the Matlab functions he used functions GitHub.

Also, the Wikipedia article on the topic — Coherence (signal processing) — could help.

1 Like

What you’re looking for is probably the matplotlib cohere() function (if you’re using Python), or mscohere() in Matlab. For Python info see here, or here and here for the pyplot version.

A crude measure of the synchrony (but not coherence) of a particular frequency could be had by running two signals through a bandpass filter and then summing them (this could be done sans scripting in Brainbay or Openvibe, for example)

Good luck, and let us know how you make out.

1 Like

There is also a coherence function in scipy.signal. See the docs page.

1 Like

Thanks for the links.

A note for anyone else who tries using the scipy.signal coherence function @AdamM mentioned: it’s is in the development version of Scipy, which you have to build from source. After I figured out why the coherence stuff wasn’t working using a stable versions of Scipi installed with apt-get or pip install, I built it from source and it wasn’t hard.

@HindBrain I have added a basic coherence function to EEGrunt, using pyplot’s cohere function to plot coherence at different frequencies. It’s quite basic. As soon as I get a chance, I’ll looking into writing something to get coherence over time for a specific frequency band (which could be turned into a spectrogram like Chip’s).