[Eeglablist] A tentative issue in coherence calculation in EEGLAB for epoched data
Iman Mohammad-Rezazadeh
irezazadeh at ucdavis.edu
Fri Jul 24 13:28:05 PDT 2015
Thank you Makoto ! You are email is very helpful.
I think the way that newcrossf calculates the cross-spectral density is different than method by Matlab function ‘cpsd’ , so I am still not clear about it !
Best,
Iman
From: Makoto Miyakoshi [mailto:mmiyakoshi at ucsd.edu]
Sent: Friday, July 24, 2015 12:33 PM
To: Iman Mohammad-Rezazadeh <irezazadeh at UCDAVIS.EDU>
Cc: EEGLAB List <eeglablist at sccn.ucsd.edu>; Loo, Sandra <SLoo at mednet.ucla.edu>; Scott Makeig <smakeig at ucsd.edu>; Chantelle C Kinzel <ckinzel at mednet.ucla.edu>; Michelini, Giorgia <giorgia.michelini at kcl.ac.uk>
Subject: Re: A tentative issue in coherence calculation in EEGLAB for epoched data
Dear Iman,
I finally tested it with the data.
First of all, the default 'type' option is 'phasecoher' (i.e. phase coupling factor) and not 'coher' (which is linear coherence). Under this condition, line 824 is executed, which is
coherres = sum( coherresout ./ abs(coherresout), 3) / g.trials;
where size(coherresout) is freq x time x trials. In this case,
mean(j1+j2+j3+j4+...+jn)
will produce the same results as
mean(mean(j1+j2)+mean(j3+j4)+...+mean(j(n-1)+jn))
I also tested 'coher' which you used. Under this condition, line 811 is executed, which is
coherres = sum(alltfX .* conj(alltfY), 3) ./ sqrt( sum(abs(alltfX).^2,3) .* sum(abs(alltfY).^2,3) );
where size(alltfX) is freq x time x trials, therefore same happens.
This concludes that you don't need to concern that 'calculate the coherence for each trial first and then make the average across trials.'
Iman, where does 'sum(fft(Y(i, :))/100' come from? newcrossf() does not use Matlab fft().
Makoto
On Fri, Jul 24, 2015 at 11:06 AM, Iman Mohammad-Rezazadeh <irezazadeh at ucdavis.edu<mailto:irezazadeh at ucdavis.edu>> wrote:
Hi,
Suppose the data Y contains of 100 epochs and each epoch is 1000 points. Size Y is (100 x 1000). Now, if we create X from Y and consider X as a (1 , (100x1000) ) matrix then the fft(X) on the whole length of it is different that Sum(fft(Y(i, :))/100
Best
Iman
From: Makoto Miyakoshi [mailto:mmiyakoshi at ucsd.edu<mailto:mmiyakoshi at ucsd.edu>]
Sent: Friday, July 24, 2015 10:53 AM
To: Iman Mohammad-Rezazadeh <irezazadeh at UCDAVIS.EDU<mailto:irezazadeh at UCDAVIS.EDU>>
Cc: EEGLAB List <eeglablist at sccn.ucsd.edu<mailto:eeglablist at sccn.ucsd.edu>>; Loo, Sandra <SLoo at mednet.ucla.edu<mailto:SLoo at mednet.ucla.edu>>; Scott Makeig <smakeig at ucsd.edu<mailto:smakeig at ucsd.edu>>; Chantelle C Kinzel <ckinzel at mednet.ucla.edu<mailto:ckinzel at mednet.ucla.edu>>; Michelini, Giorgia <giorgia.michelini at kcl.ac.uk<mailto:giorgia.michelini at kcl.ac.uk>>
Subject: Re: A tentative issue in coherence calculation in EEGLAB for epoched data
Dear Iman,
If I understand the calculation correctly, you are comparing
mean(j1+j2+j3+j4+...+jn)
with
mean(mean(j1+j2)+mean(j3+j4)+...+mean(j(n-1)+jn))
They should produce the same results (if j is a data chunk, then they should have the same number of data points... which holds anyway)
Do I understand the problem correctly?
Makoto
On Fri, Jul 24, 2015 at 10:43 AM, Iman Mohammad-Rezazadeh <irezazadeh at ucdavis.edu<mailto:irezazadeh at ucdavis.edu>> wrote:
Hi Makoto ,
It is about the stationarity of EEG signal and basically we cannot assume it is stationary for the long period of the concatenated data.
Best,
Iman
From: Makoto Miyakoshi [mailto:mmiyakoshi at ucsd.edu<mailto:mmiyakoshi at ucsd.edu>]
Sent: Thursday, July 23, 2015 6:14 PM
To: Iman Mohammad-Rezazadeh <irezazadeh at UCDAVIS.EDU<mailto:irezazadeh at UCDAVIS.EDU>>
Cc: EEGLAB List <eeglablist at sccn.ucsd.edu<mailto:eeglablist at sccn.ucsd.edu>>; Loo, Sandra <SLoo at mednet.ucla.edu<mailto:SLoo at mednet.ucla.edu>>; Scott Makeig <smakeig at ucsd.edu<mailto:smakeig at ucsd.edu>>; Chantelle C Kinzel <ckinzel at mednet.ucla.edu<mailto:ckinzel at mednet.ucla.edu>>; Michelini, Giorgia <giorgia.michelini at kcl.ac.uk<mailto:giorgia.michelini at kcl.ac.uk>>
Subject: Re: A tentative issue in coherence calculation in EEGLAB for epoched data
Dear Iman,
> coherres = sum(alltfX .* conj(alltfY), 3) ./ sqrt( sum(abs(alltfX).^2,3) .* sum(abs(alltfY).^2,3) );
So 'sum(alltfX .* conj(alltfY), 3)' sums all data points? If so, as long as the number of data points distribute uniformly across all trials, the mean of the mean is the same as the grand mean. Am I wrong? Please correct me.
Makoto
On Thu, Jul 23, 2015 at 4:03 PM, Iman Mohammad-Rezazadeh <irezazadeh at ucdavis.edu<mailto:irezazadeh at ucdavis.edu>> wrote:
Hi,
The way the code scripted is to calculate the spectrum from the whole data at once
[alltfX freqs timesout] = timefreq(X, g.srate, spectraloptions{:})
Not each epoch separately and then make an average from them. and yes in matters !
Best,
Iman
From: Makoto Miyakoshi [mailto:mmiyakoshi at ucsd.edu<mailto:mmiyakoshi at ucsd.edu>]
Sent: Thursday, July 23, 2015 3:44 PM
To: Iman Mohammad-Rezazadeh <irezazadeh at UCDAVIS.EDU<mailto:irezazadeh at UCDAVIS.EDU>>
Cc: EEGLAB List <eeglablist at sccn.ucsd.edu<mailto:eeglablist at sccn.ucsd.edu>>; Loo, Sandra <SLoo at mednet.ucla.edu<mailto:SLoo at mednet.ucla.edu>>; Scott Makeig <smakeig at ucsd.edu<mailto:smakeig at ucsd.edu>>; Chantelle C Kinzel <ckinzel at mednet.ucla.edu<mailto:ckinzel at mednet.ucla.edu>>; Michelini, Giorgia <giorgia.michelini at kcl.ac.uk<mailto:giorgia.michelini at kcl.ac.uk>>
Subject: Re: A tentative issue in coherence calculation in EEGLAB for epoched data
Dear Iman,
I ask you this without testing it, but does the order of the averaging process makes difference in results?
Makoto
On Mon, Jul 20, 2015 at 10:09 AM, Iman Mohammad-Rezazadeh <irezazadeh at ucdavis.edu<mailto:irezazadeh at ucdavis.edu>> wrote:
Hi EEGLABERs,
I have been looking into ‘newcrossf’ function and the way it calculates coherence for epoched data. Basically, it uses the ‘timefreq’ function to calculate the time/frequency decomposition the data. ‘timefreq’ function treats the epoched data as a continuous one:
X = reshape(X, g.frame, g.trials);
[alltfX freqs timesout] = timefreq(X, g.srate, spectraloptions{:});
Y = reshape(Y, g.frame, g.trials);
[alltfY] = timefreq(Y, g.srate, spectraloptions{:});
and calculates the its spectrum using the whole data which is now concatenated version of all trials. So, for each of channel’s pair (X and Y , for example) the spectrum is calculated as described above and then the joint time-freq decomposition is calculated for coherence value.
coherres = sum(alltfX .* conj(alltfY), 3) ./ sqrt( sum(abs(alltfX).^2,3) .* sum(abs(alltfY).^2,3) );
However, similar to the ERSP concept, each trial/epoch might be different than others [because of perturbations in subjects’ mental status, mental fatigue, etc] and thus I think it is more appropriate to calculate the coherence for each trial first and then make the average across trials.
Any thoughts?
Iman
--
Makoto Miyakoshi
Swartz Center for Computational Neuroscience
Institute for Neural Computation, University of California San Diego
--
Makoto Miyakoshi
Swartz Center for Computational Neuroscience
Institute for Neural Computation, University of California San Diego
--
Makoto Miyakoshi
Swartz Center for Computational Neuroscience
Institute for Neural Computation, University of California San Diego
--
Makoto Miyakoshi
Swartz Center for Computational Neuroscience
Institute for Neural Computation, University of California San Diego
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sccn.ucsd.edu/pipermail/eeglablist/attachments/20150724/2283a218/attachment.html>
More information about the eeglablist
mailing list