<div dir="ltr">Dear Jan,<div><br></div><div>Here's a follow up question on this thread. </div><div><br></div><div>I understand now that 'mtmfft' provides an estimate of the spectrum using the whole trial. I also understand that if I want to estimate the wPLI for a specific time window within my trial, I should either 1) use a time-resolved method when calling <i>ft_freqanalysis </i>(e.g. wavelet) or 2) call <i>ft_selectdata </i>prior to using 'mtmfft' in ft_freqanalysis. </div><div><br></div><div>Because it is less computationally demanding, I tried the second option. However, I've noticed that <i>ft_freqanalysis </i>throws an error if I try to use <i>ft_selectdata</i> with a time window shorter than one second. After inspecting the output structure of <i>ft_selectdata</i><i>, </i>it seems as though the function performs an average on the second dimension for the first trial only. When I use a latency over a second, this does not happen and all trials have the same dimensions. My question is: am I doing anything wrong or have I again made a wrong assumption while implementing this pipeline? Is there any reason for this strange output? See code snippet below. Thanks a lot in advance! </div><div><br> <font color="#000000">cfg = [ ];<br> data = ft_preprocessing(cfg,rwdata);<br> <br> % resample data<br> cfg = [];<br> cfg.resamplefs = 250;<br> data = ft_resampledata(cfg, data);</font></div><div><font color="#000000"><br></font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#000000">data =</font></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#000000"><br></font></div></blockquote></blockquote></blockquote></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><font color="#000000">struct with fields:<br></font></blockquote></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#000000"><br></font></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#000000"> fsample: 250</font></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#000000"> trial: {1×117 cell}</font></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#000000"> time: {1×117 cell}</font></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#000000"> label: {100×1 cell}</font></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#000000"> cfg: [1×1 struct]</font></div><div><font color="#000000"><br></font></div></blockquote></blockquote><div><font color="#000000"> % select the portion of the data I want to compute the wPLI for </font></div><div><font color="#000000"> cfg = [ ];<br> cfg.latency = .15:.25; <<<<<<<<<<<<<< if I use 0:1 or 1:1.5, <i>ft_freqanaylisis</i> runs without any problem, but if I use any other latency within 1 second it doesn't work.<br> data = ft_selectdata(cfg,data);</font></div><div><font color="#000000"> </font></div><div><font color="#000000"> % here's the output structure</font></div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font color="#000000">data =</font></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font color="#000000"><br></font></div></blockquote></blockquote></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><font color="#000000">struct with fields:<br></font></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font color="#000000"><br></font></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font color="#000000"> fsample: 250</font></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font color="#000000"> trial: {1×117 cell}</font></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font color="#000000"> time: {1×117 cell}</font></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font color="#000000"> label: {100×1 cell}</font></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font color="#000000"> cfg: [1×1 struct]</font></div><div><font color="#000000"><br></font></div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><font color="#000000">data.trial<br></font></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font color="#000000"><br>ans =<br> 1×117 cell array<br> Columns 1 through 9<br><br></font></div></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font color="#000000"> {100×1 double} {100×1251 double} {100×1251 double} % averaged first trial in the 2nd dimension instead of selecting the time interval of interest</font></div></blockquote></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font color="#000000"><br></font></div></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><font color="#000000">data.time<br></font></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font color="#000000">ans =<br> 1×117 cell array<br> Columns 1 through 10<br><br></font></div></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font color="#000000"> {[0.1480]} {1×1251 double} {1×1251 double}</font></div></blockquote></blockquote></blockquote></div></blockquote></blockquote><font color="#000000"> <br> % Now call the ft_freqanalysis function <br> cfg = [ ];<br> cfg.output = 'fourier';<br> cfg.method = 'mtmfft';<br> cfg.taper = 'dpss';<br> cfg.foi = linspace(1,31,60);<br> cfg.tapsmofrq = 4;<br> tf_data = ft_freqanalysis(cfg,data);</font></div><div><font color="#000000"><br></font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#000000">Error using dpss>parseinputs (line 308)</font></div><div><font color="#000000">Time-bandwidth product NW must be a positive number.</font></div></blockquote><div><font color="#000000"><br></font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#000000">Error in dpss (line 62)</font></div><div><font color="#000000">[method,k,Ni,traceFlag,N,NW] = parseinputs(N,NW,varargin{:});</font></div></blockquote><div><font color="#000000"><br></font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#000000">Error in ft_specest_mtmfft>double_dpss (line 362)</font></div><div><font color="#000000">tap = dpss(double(a), double(b), varargin{:});</font></div></blockquote><div><font color="#000000"><br></font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#000000">Error in ft_specest_mtmfft (line 151)</font></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#000000"> tap = double_dpss(ndatsample,ndatsample*(tapsmofrq./fsample))';</font></div></blockquote><div><font color="#000000"><br></font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#000000">Error in ft_freqanalysis (line 563)</font></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#000000"> [spectrum,ntaper,foi] = ft_specest_mtmfft(dat, time, 'taper', cfg.taper, options{:}, 'feedback', fbopt);</font></div></blockquote><div><font color="#000000"><br></font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#000000">Error in Connectivity_wPLI (line 68)</font></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#000000"> tf_data = ft_freqanalysis(cfg,data);</font></div></blockquote><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><br></blockquote><div>All best,</div><div><br></div><div><div><div dir="ltr" data-smartmail="gmail_signature"><div dir="ltr"><font size="4"><b>Sergio. </b></font><br><div><div><br><div></div><div></div></div></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">El mié, 15 sept 2021 a las 15:09, SERGIO OSORIO GALEANO (<<a href="mailto:srosorio@uc.cl" target="_blank">srosorio@uc.cl</a>>) escribió:<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 dir="ltr"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>Yes, you made a mistake in the (assumptions underlying) the implementation: the cfg.toi that you supply before ft_freqanalysis is not going to have any effect if you use ‘mtmfft’ as a method, since this method just provides a single estimate of the spectrum using the whole ’trial’ for the estimation.</div></blockquote><div><br></div>Oh, that makes perfect sense. Cheers Jan! Really appreciate it. <div><b><br clear="all"></b><div><div dir="ltr"><div dir="ltr"><b>Sergio.</b><div><div><br><div></div><div></div></div></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">El mié, 15 sept 2021 a las 14:29, Schoffelen, J.M. (Jan Mathijs) via fieldtrip (<<a href="mailto:fieldtrip@science.ru.nl" target="_blank">fieldtrip@science.ru.nl</a>>) escribió:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Sergio,<br>
> <br>
> 1) Regardless of whether I use my full time window of interest (0-1.5 s) or whether I estimate wPLI for two separate shorter time windows (0-.7 s and .7-1.5 s), the results are always identical to one another. Is this normal behaviour in wPLI analyses or is there something potentially wrong with how I've implemented it? <br>
<br>
Yes, you made a mistake in the (assumptions underlying) the implementation: the cfg.toi that you supply before ft_freqanalysis is not going to have any effect if you use ‘mtmfft’ as a method, since this method just provides a single estimate of the spectrum using the whole ’trial’ for the estimation.<br>
<br>
> 2) I notice that wPLI values are way lower for low-frequencies (4-7hz) than for higher-frequencies (8-12hz and 15-30hz). While this could be a real effect associated with my task, the fact that this result is consistent across different conditions makes me wonder whether I've done something wrong in the ft_freqanalysis configuration. <br>
<br>
I think that this is just a property of the data.<br>
<br>
Best wishes,<br>
Jan-Mathijs<br>
<br>
<br>
> <br>
> Thanks a lot in advance for any help anyone can provide! <br>
> <br>
> -----------<br>
> <br>
> cfg = [ ];<br>
> data = ft_preprocessing(cfg,rwdata);<br>
> <br>
> %resample data<br>
> cfg = [ ];<br>
> cfg.resamplefs = 250;<br>
> data = ft_resampledata(cfg, data);<br>
> <br>
> data =<br>
> struct with fields:<br>
> <br>
> fsample: 250<br>
> trial: {1×117 cell}<br>
> time: {1×117 cell}<br>
> label: {100×1 cell}<br>
> cfg: [1×1 struct]<br>
> <br>
> % next, call the ft_freqanalysis function in our source data<br>
> cfg = [ ];<br>
> cfg.output = 'fourier';<br>
> cfg.method = 'mtmfft';<br>
> cfg.taper = 'dpss';<br>
> cfg.foi = linspace(4,30,30);<br>
> cfg.tapsmofrq = 4;<br>
> cfg.toi = 0:.02:1.5; % try 0:.02:.7 and .7:.02:1.5<br>
> tf_data = ft_freqanalysis(cfg,data);<br>
> <br>
> tf_data = <br>
> struct with fields:<br>
> <br>
> label: {100×1 cell}<br>
> dimord: 'rpttap_chan_freq'<br>
> freq: [1×30 double]<br>
> fourierspctrm: [4563×100×30 double]<br>
> cumsumcnt: [117×1 double]<br>
> cumtapcnt: [117×1 double]<br>
> cfg: [1×1 struct]<br>
> <br>
> % estimate wPLI values<br>
> cfg = [ ];<br>
> cfg.method = 'wpli_debiased'; <br>
> connect_data = ft_connectivityanalysis(cfg,tf_data);<br>
> <br>
> connect_data = <br>
> struct with fields:<br>
> <br>
> label: {100×1 cell}<br>
> dimord: 'chan_chan_freq'<br>
> wpli_debiasedspctrm: [100×100×30 double]<br>
> freq: [1×30 double]<br>
> cfg: [1×1 struct]<br>
> <br>
> Best,<br>
> <br>
> Sergio.<br>
> <br>
> _______________________________________________<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://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!v6GcyYsHF6VUmzXm8BB3M6rFfwWnSYCxD7hg5IzSXjBU2SvnlyfRyykO5BhpyzahCLvCtBzdjU2HPc4$" rel="noreferrer" target="_blank">https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!v6GcyYsHF6VUmzXm8BB3M6rFfwWnSYCxD7hg5IzSXjBU2SvnlyfRyykO5BhpyzahCLvCtBzdjU2HPc4$</a> <br>
<br>
<br>
_______________________________________________<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>
</blockquote></div>