<div dir="ltr">Thank you, yes so I do get the same figures when I plot the two using ft_connectivityplot while feeding the EEG data. However, my intent is to get the actual numerical PLV values rather than the plot so I believe I should be calling 

plv3 = ft_checkdata(plv3, 'cmbrepresentation', 'full'); to get the channel x channel x frequency representation. The discrepancy happens when I evaluate the numerical values using this method.<div><br></div><div> I did some exploration as I understand it is very difficult to explain the anomaly considering that as you said it should not matter irrespective of whether the data being fed in is EEG or random numbers as the function just sees them as numbers. Upon following the lines of code for 

<span style="font-family:Courier;font-size:10px">ft_connectivityplot</span>   I came to know that inside the function there are instances wherein it first adjusts the data using ft_checkdata and also does some operations on intersecting the channels to make them align. And I suspected there are some internal corrections being done to align the values and suspected it had to do with the naming of the labels. </div><div><br></div><div>So, when I run your script with the following additional lines I do get the same answers in plv3 and plv1 printed out ( changed nchan = 5).<br> plv3 = ft_checkdata(plv3, 'cmbrepresentation', 'full');  <br></div><div><br></div><div><div>disp(plv1.plvspctrm(1,:,1));</div><div>  >>1.0000    0.1000    0.1000    0.5000    0.3000</div><div>    <br>

disp(

plv_csd.plvspctrm(1,:,1));</div><div>     >>NaN    0.1000    0.1000    0.5000    0.3000  <br></div><div></div><div><br></div><div><br></div><div>Then I replaced the following lines accordingly and reran the same set of code<div><br></div><div>for k = 1:nchan<br>     if k==1<br>        data.label{k} =   sprintf('chan%02d',k);<br>    elseif k==2<br>        data.label{k} =   sprintf('Nchan%02d',k);<br>    else<br>        data.label{k} =   sprintf('N1chan%02d',k);<br>    end<br>end</div></div><div>...</div><div>...</div><div>...</div><div><br></div><div>Here, the output is different for both powandcsd as well as fourier when the label size is different.</div><div>  disp(plv1.plvspctrm(1,:,1));  <br></div><div>   >>  1.0000    0.1000    0.1000    0.2000    0.3000<br>  disp(

plv_csd.plvspctrm(1,:,1));  <br>    >>   NaN    0.1000         0         0    0.1000<br></div><div><br></div><div>So by default, the EEG labels are not having the same size, some are two-letter names(Cz)  whereas others are 3 letter names (FCz). So there is an influence on the channel labels on how the results come about and I suspect that is causing this anomaly. </div><div><br></div><div>Now this is with my understanding that I am supposed to call 

<i>plv3 = ft_checkdata(plv3, 'cmbrepresentation', 'full');</i> after powandcsd to get the data  in correct dimension (ch x ch x freq) and I might be wrong if this is not the way to extract the values in the format. If there is another way to get the data, if you could kindly inform me, that will be greatly appreciated. <div><div><div><div><div><div><div><div><br></div><div> </div><div><br></div></div></div></div></div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Aug 3, 2020 at 11:18 AM Schoffelen, J.M. (Jan Mathijs) <<a href="mailto:jan.schoffelen@donders.ru.nl">jan.schoffelen@donders.ru.nl</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">



<div style="overflow-wrap: break-word;">
Hi Akshay,
<div><br>
</div>
<div>I cannot reproduce your problem. A data structure is a data structure, so I don’t see why a FT-structure that some numbers in a trial cell-array should behave different when it is obtained from EEGLAB or from ft_connectivitysimulation. For that
 matter, it shouldn’t make a difference whether you just put in random numbers. Using the below snippet of code I can reproduce your observation that it shouldn’t matter whether plv is computed from singletrial powandcsd, or from singletrial fourier.</div>
<div><br>
</div>
<div>Best wishes,</div>
<div>JM</div>
<div><br>
</div>
<div><br>
</div>
<div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;color:rgb(34,139,34)">
% create some data</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
nsmp = 1000;</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
ntrl = 20;</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
nchan = 3;</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
<span style="color:rgb(0,0,255)">for</span> k = 1:ntrl</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
  trial{1,k} = randn(nchan,nsmp);</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
  time{1,k}  = (0:(nsmp-1))./1000;</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;color:rgb(0,0,255)">
end</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
data = [];</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
data.trial = trial;</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
data.time  = time;</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
<span style="color:rgb(0,0,255)">for</span> k = 1:nchan</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
  data.label{k} = sprintf(<span style="color:rgb(160,32,240)">'chan%02d'</span>,k);</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;color:rgb(0,0,255)">
end</div>
<p style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;color:rgb(0,0,255);min-height:12px">
 <br>
</p>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;color:rgb(34,139,34)">
% spectral transformation</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
cfg = [];</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
cfg.method = <span style="color:rgb(160,32,240)">'mtmfft'</span>;</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
cfg.output = <span style="color:rgb(160,32,240)">'fourier'</span>;</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
cfg.pad = 1;</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
cfg.tapsmofrq = 1;</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
freq1 = ft_freqanalysis(cfg, data);</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
cfg.output = <span style="color:rgb(160,32,240)">'powandcsd'</span>;</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
freq2 = ft_freqanalysis(cfg, data);</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
cfg.keeptrials = <span style="color:rgb(160,32,240)">'yes'</span>;</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
freq3 = ft_freqanalysis(cfg, data);</div>
<p style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;min-height:12px">
 <br>
</p>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;color:rgb(34,139,34)">
% connectivity estimation</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
cfg = [];</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
cfg.method = <span style="color:rgb(160,32,240)">'plv'</span>;</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
plv1 = ft_connectivityanalysis(cfg, freq1);</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
plv2 = ft_connectivityanalysis(cfg, freq2); % this one is not correct, since wrong normalisation</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
plv3 = ft_connectivityanalysis(cfg, freq3);</div>
<p style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;min-height:12px">
 <br>
</p>
<p style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;min-height:12px">
 <br>
</p>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;color:rgb(34,139,34)">
% these should be the same</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
cfg = [];</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
cfg.parameter = <span style="color:rgb(160,32,240)">'plvspctrm'</span>;</div>
<div style="margin:0px;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
ft_connectivityplot(cfg, plv1, plv3);</div>
<div style="margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Courier;min-height:14px">
<br>
</div>
</div>
<div style="margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Courier;min-height:14px">
<br>
</div>
<div><br>
</div>
<div><br>
<div><br>
<blockquote type="cite">
<div>On 3 Aug 2020, at 15:38, Akshay Ravindran <<a href="mailto:akshay.s.ravindran@gmail.com" target="_blank">akshay.s.ravindran@gmail.com</a>> wrote:</div>
<br>
<div>
<div dir="auto">
<div>Hi Jan,
<div dir="auto"><br>
</div>
<div dir="auto">Thanks for the explanation. However yes so I do do understand the normalization done in PLV and for the same reason I had done keep_trials='yes' for powandcsd. I forgot to write it in the line of code below. I was getting that difference
 when using powandcsd though.</div>
<div dir="auto"><br>
</div>
<div dir="auto">The Nan and 1, I understood came from the way the implementation was done but my concern was the discrepancy in the off diagonal element which was the same for the artificial data whereas for actual EEG, they came out to be quite different.
 Is there something I can do to make it replicable? Maybe can I send the data?</div>
<div dir="auto"><br>
</div>
<div dir="auto"><br>
</div>
<br>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Mon, Aug 3, 2020, 4:03 AM Schoffelen, J.M. (Jan Mathijs) <<a href="mailto:jan.schoffelen@donders.ru.nl" target="_blank">jan.schoffelen@donders.ru.nl</a>> wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div style="overflow-wrap: break-word;">Hi Akshay,
<div><br>
</div>
<div>I understand your question, but honestly the pasted code is not sufficient for me to try and reproduce. Nonetheless, a few things can be said:</div>
<div><br>
</div>
<div>PLV is a measure (as is wPLI) that requires single trial spectrally resolved data as an input. This is because the algorithmic steps that are needed to compute the connectivity measure include a per-trial normalisation of the fourier coefficients
 by their magnitude (plv), or some other fancy non-linear manipulation of the single trial phase difference estimates (wPLI). If you ask ft_freqanalysis to output ‘powandcsd’, without explicitly specifying cfg.keeptrials = ‘yes’, then the single trial dimension
 is lost for posterity, and the consequent computation of the PLV/wPLI is nonsense (unless you used as an input a single epoch’s spectrally transformed data with massive multitapering, keeping the information of the individual tapers, but that’s a different
 story altogether). In other words, where you mention that you think that ‘fourier’ is the right way to implement these, you are right, but as an alternative you could have used ‘powandcsd’ + ‘keeptrials = ‘yes’’.</div>
<div><br>
</div>
<div>The NaNs versus 1 are easily explained by the fact that with ‘powandcsd’ the diagonal elements are explicitly set to NaN (i.e. they are not computed), whereas in the ‘fourier’ case they are, and they trivially result in an all(ones).</div>
<div><br>
</div>
<div>Best wishes,</div>
<div>Jan-Mathijs</div>
<div><br>
<div><br>
<blockquote type="cite">
<div>On 2 Aug 2020, at 23:35, Akshay Ravindran <<a href="mailto:akshay.s.ravindran@gmail.com" rel="noreferrer" target="_blank">akshay.s.ravindran@gmail.com</a>> wrote:</div>
<br>
<div>
<div dir="ltr">
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">Good Evening,<br>
</div>
<div dir="ltr">
<div><br>
</div>
I tried estimating the functional connectivity using different phase-based measures like PLV and wPLI_debiased. I tried testing the two measures using<i> cfg.output</i> set to either <i>'fourier' or</i> <i>'powandcsd'
</i>as I have seen people implementing PLV with both. However, I am getting quite varying results using either of these on an EEG data saved in .set file loaded and run using the commands shown at the end of this question.  
<div><br>
</div>
<div>Even though I think <i>'fourier'</i> is the right way to implement these, to test for the validity of it, I tested this on the artificial data created using the
<i>ft_connectivitysimulation function</i> ( 3 channel, 200 Hz Fs, the same number of trials as EEG, default noise covariance and params as in the example). In this case however, I am getting the very same results using either output (off-diagonal elements
 are the same in either; diagonal elements are NAN in using powandcsd whereas 1 while using Fourier).</div>
<div><br>
<div><b><i>My question is mainly the following</i></b></div>
<div><u>1) Am I missing something while testing on EEG data? If not,  why is there a discrepancy found while testing on EEG but not on the simulated data? </u>
<div><u>2) Is there any recommended instance of using 'powandcsd ' over 'fourier'  in any of the connectivity measures?</u></div>
<div><br>
</div>
<div>
<div><br>
</div>
<div>% EEG sampled at 200 Hz, 60 channels with events. The epoching is fine as the ERP was validated after epoching. <br>
<div>data              = ft_connectivitysimulation(cfg);
<div>
<div>cfg = [];<br>
cfg.channel = ['all']; <br>
cfg.dataset                 = 'Dataset_Epochs.set';<br>
cfg.trialfun                = 'ft_trialfun_general'; % this is the default<br>
cfg.trialdef.eventtype      = 'trigger';<br>
cfg.trialdef.eventvalue     = 'Onset'; <br>
cfg.trialdef.prestim        = 0.2; % in seconds<br>
cfg.trialdef.poststim       = 0.6; % in seconds<br>
cfg = ft_definetrial(cfg);<br>
data= ft_preprocessing(cfg); </div>
<div><br>
</div>
<div>
<div><br>
</div>
<div>cfg           = [];</div>
<div>cfg.pad       = 'nextpow2'; <br>
cfg.method    = 'mtmfft';<br>
cfg.taper     = 'hanning';<br>
cfg.output    = 'fourier';; % Tried replacing this with powandcsd and both yielded different results<br>
cfg.keeptrials  = 'yes'<br>
cfg.tapsmofrq = 1;<br>
spectral_decomp          = ft_freqanalysis(cfg, data); </div>
<div>% Compute the functional connectivity using PLV               <br>
cfg            = [];<br>
cfg.method    = 'plv'<br>
</div>
<div>fc  = ft_connectivityanalysis(cfg, spectral_decomp);            </div>
</div>
<div><br>
</div>
<div><br>
</div>
<div>To further test if it is something with the particular dataset, I also tried on separate continuous EEG data  which was segmented in fieldtrip. However this yielded similar quite varying results when using either output</div>
<div> % cfg.dataset                 = 'Dataset_RS.set';  <br>
</div>
<div>
<div> % [data] = ft_preprocessing(cfg)  <br>
</div>
<div></div>
%cfg = [];<br>
%cfg.length  = 6;<br>
%cfg.overlap = 0;<br>
%data_segmented = ft_redefinetrial(cfg, data);</div>
<div><br>
</div>
<div> Thanks,</div>
<div>
<div><br>
</div>
-- <br>
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div style="color:rgb(80,0,80);font-size:12.8px"><span style="font-size:12.8px">Regards,</span></div>
<div style="color:rgb(80,0,80);font-size:12.8px"><span style="font-size:12.8px"><br>
</span></div>
<div style="color:rgb(80,0,80);font-size:12.8px">ASR</div>
<div style="color:rgb(80,0,80);font-size:12.8px"><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div dir="ltr">
<div dir="ltr">
<div>
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div style="color:rgb(80,0,80);font-size:12.8px"><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
_______________________________________________<br>
fieldtrip mailing list<br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer" target="_blank">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
<a href="https://doi.org/10.1371/journal.pcbi.1002202" rel="noreferrer" target="_blank">https://doi.org/10.1371/journal.pcbi.1002202</a><br>
</div>
</blockquote>
</div>
<br>
</div>
</div>
_______________________________________________<br>
fieldtrip mailing list<br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer noreferrer" target="_blank">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
<a href="https://doi.org/10.1371/journal.pcbi.1002202" rel="noreferrer noreferrer" target="_blank">https://doi.org/10.1371/journal.pcbi.1002202</a><br>
</blockquote>
</div>
</div>
</div>
_______________________________________________<br>
fieldtrip mailing list<br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" target="_blank">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
<a href="https://doi.org/10.1371/journal.pcbi.1002202" target="_blank">https://doi.org/10.1371/journal.pcbi.1002202</a><br>
</div>
</blockquote>
</div>
<br>
</div>
</div>

_______________________________________________<br>
fieldtrip mailing list<br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer" target="_blank">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
<a href="https://doi.org/10.1371/journal.pcbi.1002202" rel="noreferrer" target="_blank">https://doi.org/10.1371/journal.pcbi.1002202</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div style="color:rgb(80,0,80);font-size:12.8px"><span style="font-size:12.8px">Regards,</span></div><div style="color:rgb(80,0,80);font-size:12.8px"><br></div><div style="color:rgb(80,0,80);font-size:12.8px">Akshay Sujatha Ravindran<br></div><div style="color:rgb(80,0,80);font-size:12.8px"><br></div><div style="color:rgb(80,0,80);font-size:12.8px"><div>Graduate Research Assistant</div><div>Department of Electrical & Computer Engineering</div><div>Laboratory for Noninvasive Brain-Machine Interface Systems </div><div>University of Houston</div><div>Engineering Building 2, E 413</div><div><br></div></div><div style="color:rgb(80,0,80);font-size:12.8px">President | BRAIN Student Group (UoH)  </div><div style="color:rgb(80,0,80);font-size:12.8px">Vice President | Graduate and Professional Students Association (UoH)  <br></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>