<div dir="ltr">Dear Iman,<div><br></div><div>I finally tested it with the data.</div><div>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</div><div><br></div><div><div>coherres = sum( coherresout ./ abs(coherresout), 3) / g.trials;</div></div><div><br></div><div>where size(coherresout) is freq x time x trials. In this case,</div><div><br></div><div><div style="font-size:12.6666669845581px">mean(j1+j2+j3+j4+...+jn)</div><div style="font-size:12.6666669845581px"><br></div><div style="font-size:12.6666669845581px">will produce the same results as</div><div style="font-size:12.6666669845581px"><br></div><div style="font-size:12.6666669845581px">mean(mean(j1+j2)+mean(j3+j4)+...+mean(j(n-1)+jn))</div></div><div style="font-size:12.6666669845581px"><br></div><div style="font-size:12.6666669845581px">I also tested 'coher' which you used. Under this condition, line 811 is executed, which is</div><div style="font-size:12.6666669845581px"><br></div><div><div style="font-size:12.6666669845581px">coherres = sum(alltfX .* conj(alltfY), 3) ./ sqrt( sum(abs(alltfX).^2,3) .* sum(abs(alltfY).^2,3) );</div><div style="font-size:12.6666669845581px"><br></div><div style="font-size:12.6666669845581px"><span style="font-size:small">where size(alltfX) is freq x time x trials, therefore same happens.</span><br></div><div style="font-size:12.6666669845581px"><span style="font-size:small"><br></span></div><div>This concludes that you don't need to concern that '<b style="font-size:12.6666669845581px">calculate the coherence for each trial first and then make the average across trials.'</b></div><div style="font-size:12.6666669845581px"><span style="font-size:small"><br></span></div><div style="font-size:12.6666669845581px"><font color="#000000"><span style="font-size:small">Iman, where does 's</span><span style="font-family:Calibri,sans-serif;font-size:14.6666669845581px">um(fft(Y(i, :))/100' come from? newcrossf() does not use Matlab fft().</span></font></div><div style="font-size:12.6666669845581px"><font color="#000000"><span style="font-family:Calibri,sans-serif;font-size:14.6666669845581px"><br></span></font></div><div style="font-size:12.6666669845581px"><font color="#000000"><span style="font-family:Calibri,sans-serif;font-size:14.6666669845581px">Makoto</span></font></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 24, 2015 at 11:06 AM, Iman Mohammad-Rezazadeh <span dir="ltr"><<a href="mailto:irezazadeh@ucdavis.edu" target="_blank">irezazadeh@ucdavis.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Hi,
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">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
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Best<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Iman
<u></u><u></u></span></p>
<p class="MsoNormal"><a name="14ec1416ff3171a8__MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></a></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Makoto Miyakoshi [mailto:<a href="mailto:mmiyakoshi@ucsd.edu" target="_blank">mmiyakoshi@ucsd.edu</a>]
<br>
<b>Sent:</b> Friday, July 24, 2015 10:53 AM</span></p><div><div class="h5"><br>
<b>To:</b> Iman Mohammad-Rezazadeh <<a href="mailto:irezazadeh@UCDAVIS.EDU" target="_blank">irezazadeh@UCDAVIS.EDU</a>><br>
<b>Cc:</b> EEGLAB List <<a href="mailto:eeglablist@sccn.ucsd.edu" target="_blank">eeglablist@sccn.ucsd.edu</a>>; Loo, Sandra <<a href="mailto:SLoo@mednet.ucla.edu" target="_blank">SLoo@mednet.ucla.edu</a>>; Scott Makeig <<a href="mailto:smakeig@ucsd.edu" target="_blank">smakeig@ucsd.edu</a>>; Chantelle C Kinzel <<a href="mailto:ckinzel@mednet.ucla.edu" target="_blank">ckinzel@mednet.ucla.edu</a>>; Michelini, Giorgia <<a href="mailto:giorgia.michelini@kcl.ac.uk" target="_blank">giorgia.michelini@kcl.ac.uk</a>><br>
<b>Subject:</b> Re: A tentative issue in coherence calculation in EEGLAB for epoched data<u></u><u></u></div></div><p></p><div><div class="h5">
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">Dear Iman,<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">If I understand the calculation correctly, you are comparing<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">mean(j1+j2+j3+j4+...+jn)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">with<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">mean(mean(j1+j2)+mean(j3+j4)+...+mean(j(n-1)+jn))<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">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)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Do I understand the problem correctly?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Makoto<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On Fri, Jul 24, 2015 at 10:43 AM, Iman Mohammad-Rezazadeh <<a href="mailto:irezazadeh@ucdavis.edu" target="_blank">irezazadeh@ucdavis.edu</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Hi Makoto ,
</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">It is about the stationarity of EEG signal and basically we cannot assume it is stationary for the
long period of the concatenated data.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Best,</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Iman
</span><u></u><u></u></p>
<p class="MsoNormal"><a name="14ec1416ff3171a8_14ec1322240fcb52_14ec12a9d475fb94__MailE"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span></a><u></u><u></u></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Makoto Miyakoshi [mailto:<a href="mailto:mmiyakoshi@ucsd.edu" target="_blank">mmiyakoshi@ucsd.edu</a>]
<br>
<b>Sent:</b> Thursday, July 23, 2015 6:14 PM</span><u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><br>
<b>To:</b> Iman Mohammad-Rezazadeh <<a href="mailto:irezazadeh@UCDAVIS.EDU" target="_blank">irezazadeh@UCDAVIS.EDU</a>><br>
<b>Cc:</b> EEGLAB List <<a href="mailto:eeglablist@sccn.ucsd.edu" target="_blank">eeglablist@sccn.ucsd.edu</a>>; Loo, Sandra <<a href="mailto:SLoo@mednet.ucla.edu" target="_blank">SLoo@mednet.ucla.edu</a>>; Scott Makeig <<a href="mailto:smakeig@ucsd.edu" target="_blank">smakeig@ucsd.edu</a>>;
Chantelle C Kinzel <<a href="mailto:ckinzel@mednet.ucla.edu" target="_blank">ckinzel@mednet.ucla.edu</a>>; Michelini, Giorgia <<a href="mailto:giorgia.michelini@kcl.ac.uk" target="_blank">giorgia.michelini@kcl.ac.uk</a>><br>
<b>Subject:</b> Re: A tentative issue in coherence calculation in EEGLAB for epoched data<u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">Dear Iman,<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";color:black">> coherres = sum(alltfX .* conj(alltfY), 3) ./ sqrt( sum(abs(alltfX).^2,3) .* sum(abs(alltfY).^2,3) );</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New";color:black">So '</span><span style="font-size:10.0pt;font-family:"Courier New";color:black">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.</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";color:black">Makoto </span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">On Thu, Jul 23, 2015 at 4:03 PM, Iman Mohammad-Rezazadeh <<a href="mailto:irezazadeh@ucdavis.edu" target="_blank">irezazadeh@ucdavis.edu</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Hi,
</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">The way the code scripted is to calculate the spectrum from the whole data at once
</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">[alltfX freqs timesout] = timefreq(X, g.srate, spectraloptions{:})
</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><a name="14ec1416ff3171a8_14ec1322240fcb52_14ec12a9d475fb94_14ebd9"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Not each epoch separately and then make an average
from them. and yes in matters !</span></a><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Best,</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Iman
</span><u></u><u></u></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Makoto Miyakoshi [mailto:<a href="mailto:mmiyakoshi@ucsd.edu" target="_blank">mmiyakoshi@ucsd.edu</a>]
<br>
<b>Sent:</b> Thursday, July 23, 2015 3:44 PM<br>
<b>To:</b> Iman Mohammad-Rezazadeh <<a href="mailto:irezazadeh@UCDAVIS.EDU" target="_blank">irezazadeh@UCDAVIS.EDU</a>><br>
<b>Cc:</b> EEGLAB List <<a href="mailto:eeglablist@sccn.ucsd.edu" target="_blank">eeglablist@sccn.ucsd.edu</a>>; Loo, Sandra <<a href="mailto:SLoo@mednet.ucla.edu" target="_blank">SLoo@mednet.ucla.edu</a>>; Scott Makeig <<a href="mailto:smakeig@ucsd.edu" target="_blank">smakeig@ucsd.edu</a>>;
Chantelle C Kinzel <<a href="mailto:ckinzel@mednet.ucla.edu" target="_blank">ckinzel@mednet.ucla.edu</a>>; Michelini, Giorgia <<a href="mailto:giorgia.michelini@kcl.ac.uk" target="_blank">giorgia.michelini@kcl.ac.uk</a>><br>
<b>Subject:</b> Re: A tentative issue in coherence calculation in EEGLAB for epoched data</span><u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">Dear Iman,<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">I ask you this without testing it, but does the order of the averaging process makes difference in results?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Makoto<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">On Mon, Jul 20, 2015 at 10:09 AM, Iman Mohammad-Rezazadeh <<a href="mailto:irezazadeh@ucdavis.edu" target="_blank">irezazadeh@ucdavis.edu</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Hi EEGLABERs,
<u></u><u></u></p>
<p class="MsoNormal">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:<u></u><u></u></p>
<p class="MsoNormal" style="text-autospace:none">
<span style="font-size:10.0pt;font-family:"Courier New";color:black"> </span><u></u><u></u></p>
<p class="MsoNormal" style="text-autospace:none">
<span style="font-size:10.0pt;font-family:"Courier New";color:black">X = reshape(X, g.frame, g.trials);</span><u></u><u></u></p>
<p class="MsoNormal" style="text-autospace:none">
<span style="font-size:10.0pt;font-family:"Courier New";color:black">[alltfX freqs timesout] = timefreq(X, g.srate, spectraloptions{:});</span><u></u><u></u></p>
<p class="MsoNormal" style="text-autospace:none">
<span style="font-size:10.0pt;font-family:"Courier New";color:black"> </span><u></u><u></u></p>
<p class="MsoNormal" style="text-autospace:none">
<span style="font-size:10.0pt;font-family:"Courier New";color:black">Y = reshape(Y, g.frame, g.trials);</span><u></u><u></u></p>
<p class="MsoNormal" style="text-autospace:none">
<span style="font-size:10.0pt;font-family:"Courier New";color:black">[alltfY] = timefreq(Y, g.srate, spectraloptions{:});</span><u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">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.<u></u><u></u></p>
<p class="MsoNormal" style="text-autospace:none">
<span style="font-size:10.0pt;font-family:"Courier New";color:black"> </span><u></u><u></u></p>
<p class="MsoNormal" style="text-autospace:none">
<span style="font-size:10.0pt;font-family:"Courier New";color:black">coherres = sum(alltfX .* conj(alltfY), 3) ./ sqrt( sum(abs(alltfX).^2,3) .* sum(abs(alltfY).^2,3) );</span><u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"><b>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.</b><u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Any thoughts?<u></u><u></u></p>
<p class="MsoNormal"><span style="color:#888888">Iman </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:#888888"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:#888888"> </span><u></u><u></u></p>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><br>
<br clear="all">
<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<p class="MsoNormal">--
<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">Makoto Miyakoshi<br>
Swartz Center for Computational Neuroscience<br>
Institute for Neural Computation, University of California San Diego<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><br>
<br clear="all">
<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<p class="MsoNormal">--
<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">Makoto Miyakoshi<br>
Swartz Center for Computational Neuroscience<br>
Institute for Neural Computation, University of California San Diego<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><br>
<br clear="all">
<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal">-- <u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">Makoto Miyakoshi<br>
Swartz Center for Computational Neuroscience<br>
Institute for Neural Computation, University of California San Diego<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div></div></div>
</div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Makoto Miyakoshi<br>Swartz Center for Computational Neuroscience<br>Institute for Neural Computation, University of California San Diego<br></div></div>
</div>