<div dir="ltr"><div>Dear Jan and anyone reading this thread in the future,</div><div><br></div>Sorry, I hadn't seen this email before. Actually, this solved the issue. In conclusion, specifying the parameter in an unconventional way caused the error. I also noticed that shorter latencies will require accommodating the smoothing parameter.<div><br></div><div>Thank you very much again! <br><div><br clear="all"><div><div dir="ltr" data-smartmail="gmail_signature"><div dir="ltr"><b><font size="4">Sergio A. Osorio</font></b><div><div>Laboratory for Cognitive and Evolutionary Neuroscience<br></div><div>Center for Medical Research - Faculty of Medicine</div></div>Pontificia Universidad Católica de Chile<div><b><font size="4"><img src="https://docs.google.com/uc?export=download&id=1OQHsbxZhdStfXHspAWfa0MDdBX9f6jXb&revid=0BzBWIjzXUIlcamV1a20wbWc0T3ZtM1JqdjRuUzNqV1psV3FzPQ" width="200" height="87"></font></b><div><br><div></div><div></div></div></div></div></div></div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">El jue, 23 sept 2021 a las 5:17, 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">
<div>
Hi Sergio,
<div><br>
<div>As an addition to the previous e-mail: please define cfg.latency as a 2-element vector with a begin and end point, not as a multiple-element vector, as per the documentation. </div>
<div><br>
</div>
<div>Best wishes,</div>
<div>Jan-Mathijs<br>
<div><br>
<blockquote type="cite">
<div>On 23 Sep 2021, at 03:08, SERGIO OSORIO GALEANO via fieldtrip <<a href="mailto:fieldtrip@science.ru.nl" target="_blank">fieldtrip@science.ru.nl</a>> wrote:</div>
<br>
<div>
<div dir="ltr" style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
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<span> </span><i>ft_freqanalysis<span> </span></i>(e.g.
wavelet) or 2) call<span> </span><i>ft_selectdata<span> </span></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<span> </span><i>ft_freqanalysis<span> </span></i>throws an error if I try
to use<span> </span><i>ft_selectdata</i><span> </span>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>
<span> </span><font>cfg = [ ];<br>
data = ft_preprocessing(cfg,rwdata);<br>
<span> </span><br>
% resample data<br>
cfg = [];<br>
cfg.resamplefs = 250;<br>
data = ft_resampledata(cfg, data);</font></div>
<div><font><br>
</font></div>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font>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><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>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><br>
</font></div>
</blockquote>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font> fsample: 250</font></div>
</blockquote>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font> trial: {1×117 cell}</font></div>
</blockquote>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font> time: {1×117 cell}</font></div>
</blockquote>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font> label: {100×1 cell}</font></div>
</blockquote>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font> cfg: [1×1 struct]</font></div>
<div><font><br>
</font></div>
</blockquote>
</blockquote>
<div><font> % select the portion of the data I want to compute the wPLI for </font></div>
<div><font> cfg = [ ];<br>
cfg.latency = .15:.25; <<<<<<<<<<<<<< if I use 0:1 or 1:1.5,<span> </span><i>ft_freqanaylisis</i><span> </span>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> </font></div>
<div><font> % here's the output structure</font></div>
<div>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font>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><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>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><br>
</font></div>
</blockquote>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font> fsample: 250</font></div>
</blockquote>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font> trial: {1×117 cell}</font></div>
</blockquote>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font> time: {1×117 cell}</font></div>
</blockquote>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font> label: {100×1 cell}</font></div>
</blockquote>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font> cfg: [1×1 struct]</font></div>
<div><font><br>
</font></div>
<div>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<font>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><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> {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><br>
</font></div>
</blockquote>
</blockquote>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<font>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>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> {[0.1480]} {1×1251 double} {1×1251 double}</font></div>
</blockquote>
</blockquote>
</blockquote>
</div>
</blockquote>
</blockquote>
<font> <span> </span><br>
% Now call the ft_freqanalysis function<span> </span><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><br>
</font></div>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font>Error using dpss>parseinputs (line 308)</font></div>
<div><font>Time-bandwidth product NW must be a positive number.</font></div>
</blockquote>
<div><font><br>
</font></div>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font>Error in dpss (line 62)</font></div>
<div><font>[method,k,Ni,traceFlag,N,NW] = parseinputs(N,NW,varargin{:});</font></div>
</blockquote>
<div><font><br>
</font></div>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font>Error in ft_specest_mtmfft>double_dpss (line 362)</font></div>
<div><font>tap = dpss(double(a), double(b), varargin{:});</font></div>
</blockquote>
<div><font><br>
</font></div>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font>Error in ft_specest_mtmfft (line 151)</font></div>
</blockquote>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font> tap = double_dpss(ndatsample,ndatsample*(tapsmofrq./fsample))';</font></div>
</blockquote>
<div><font><br>
</font></div>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font>Error in ft_freqanalysis (line 563)</font></div>
</blockquote>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font> [spectrum,ntaper,foi] = ft_specest_mtmfft(dat, time, 'taper', cfg.taper, options{:}, 'feedback', fbopt);</font></div>
</blockquote>
<div><font><br>
</font></div>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font>Error in Connectivity_wPLI (line 68)</font></div>
</blockquote>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><font> tf_data = ft_freqanalysis(cfg,data);</font></div>
</blockquote>
<div><br>
</div>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<br>
</blockquote>
<div>All best,</div>
<div><br>
</div>
<div>
<div>
<div dir="ltr">
<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 style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
<div class="gmail_quote" style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
<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>
><span> </span><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?<span> </span><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.<span> </span><br>
<br>
I think that this is just a property of the data.<br>
<br>
Best wishes,<br>
Jan-Mathijs<br>
<br>
<br>
><span> </span><br>
> Thanks a lot in advance for any help anyone can provide!<span> </span><br>
><span> </span><br>
> -----------<br>
><span> </span><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>
><span> </span><br>
> data =<br>
> struct with fields:<br>
><span> </span><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>
><span> </span><br>
> tf_data =<span> </span><br>
> struct with fields:<br>
><span> </span><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';<span> </span><br>
> connect_data = ft_connectivityanalysis(cfg,tf_data);<br>
><span> </span><br>
> connect_data =<span> </span><br>
> struct with fields:<br>
><span> </span><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>
><span> </span><br>
> Best,<br>
><span> </span><br>
> Sergio.<br>
><span> </span><br>
> _______________________________________________<br>
> fieldtrip mailing list<br>
><span> </span><a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer" target="_blank">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
><span> </span><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><span> </span><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://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!usewI1PbndK5LPja3Ngfqvfn3tRpdRV73OimKW6NrcohdNrX6G3vkgQuzYR9QRioc7pHSLvRNfscdfs$" rel="noreferrer" target="_blank">https://doi.org/10.1371/journal.pcbi.1002202</a><br>
</blockquote>
</div>
</blockquote>
</div>
<span style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline">_______________________________________________</span><br style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
<span style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline">fieldtrip
mailing list</span><br style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
<span style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline"><a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" target="_blank">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a></span><br style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
<a href="https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!usewI1PbndK5LPja3Ngfqvfn3tRpdRV73OimKW6NrcohdNrX6G3vkgQuzYR9QRioc7pHSLvRNfscdfs$" style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!usewI1PbndK5LPja3Ngfqvfn3tRpdRV73OimKW6NrcohdNrX6G3vkgQuzYR9QRioc7pHSLvRNfscdfs$</a><span style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline"></span></div>
</blockquote>
</div>
<br>
</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>
</blockquote></div>