<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0"><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;">Dear </span><span style="color: rgb(33, 33, 33); font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif, serif, EmojiFont; font-size: 15px;"><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;">Jan-Mathijs, </span><span style="color: rgb(33, 33, 33); font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif, serif, EmojiFont; font-size: 15px;"><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;">Raphaël,
 and </span><span style="color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">Stephen,</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="color: rgb(33, 33, 33); font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif, serif, EmojiFont; font-size: 15px;"><span style="color: rgb(33, 33, 33); font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif, serif, EmojiFont; font-size: 15px;"><span style="color: rgb(31, 73, 125); font-family: Calibri, sans-serif, serif, EmojiFont; font-size: 14.6667px;"><br>
</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="color: rgb(33, 33, 33); font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif, serif, EmojiFont; font-size: 15px;"><span style="color: rgb(33, 33, 33); font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif, serif, EmojiFont; font-size: 15px;"><span style="color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">Thanks
 so much for your insightful replies!</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="color: rgb(33, 33, 33); font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif, serif, EmojiFont; font-size: 15px;"><span style="color: rgb(33, 33, 33); font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif, serif, EmojiFont; font-size: 15px;"><span style="color: rgb(31, 73, 125); font-family: Calibri, sans-serif, serif, EmojiFont; font-size: 14.6667px;"><br>
</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="color: rgb(33, 33, 33); font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif, serif, EmojiFont; font-size: 15px;"><span style="color: rgb(33, 33, 33); font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif, serif, EmojiFont; font-size: 15px;"><span style="color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">I
 need to analyze the whole duration of the different trials, so I think the suggestion to run freqanalysis looping over trials is really suitable!</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="color: rgb(33, 33, 33); font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif, serif, EmojiFont; font-size: 15px;"><span style="color: rgb(33, 33, 33); font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif, serif, EmojiFont; font-size: 15px;"><span style="color: rgb(31, 73, 125); font-family: Calibri, sans-serif, serif, EmojiFont; font-size: 14.6667px;"><br>
</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="color: rgb(33, 33, 33); font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif, serif, EmojiFont; font-size: 15px;"><span style="color: rgb(33, 33, 33); font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif, serif, EmojiFont; font-size: 15px;"><span style="color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">I'm
 using these parameters:</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="color: rgb(33, 33, 33); font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif, serif, EmojiFont; font-size: 15px;"><span style="color: rgb(33, 33, 33); font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif, serif, EmojiFont; font-size: 15px;"><span style="color: rgb(31, 73, 125); font-family: Calibri, sans-serif, serif, EmojiFont; font-size: 14.6667px;"></span></span></span></p>
<div><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;"><i>cfgft = [];</i></span></div>
<div><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;"><i>cfgft.method = 'wavelet';</i></span></div>
<div><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;"><i>cfgft.output = 'pow';</i></span></div>
<div><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;"><i>cfgft.foi = 2:1:40;</i></span></div>
<div><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;"><i>cfgft.width = 6;</i></span></div>
<div><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;"><i>cfgft.pad = 'nextpow2';</i></span></div>
<div><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;"><i>cfgft.keeptrials = 'yes';</i></span></div>
<div><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;"><i>cfgft.toi = data.time{1};</i></span></div>
<div><br>
</div>
<div><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;">But I get this error at some point:</span></div>
<div>
<div><span style="color: rgb(255, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;">Error using  ./ </span></div>
<div><span style="color: rgb(255, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;">Matrix dimensions must agree.</span></div>
<div><br>
</div>
<div><span style="color: rgb(255, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;">Error in ft_freqanalysis (line 435)</span></div>
<div><span style="color: rgb(255, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;">    fboi   = round(cfg.foi ./ (data.fsample ./ (cfg.pad*data.fsample))) + 1;</span></div>
<br>
</div>
<div><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;">This trial is quite long</span><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;"> (</span><span><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;">10267
 timepoints divided by </span><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;">500 sampling rate = 20 seconds), so I can't think of </span><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;">why
 I get this error?</span></span></div>
<div><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;">I think there is a problem with the padding, anyone has any suggestion?</span></div>
<div><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;">Also, do</span><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;">es the </span><span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;"><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;">cfgft.toi
 need to be exactly the time resolution of my data (0.0020 sec)</span><span style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;">, or can I use a lower resolution by changing the cfgft.toi?</span></span></div>
<div><span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;"><br>
</span></div>
<div><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">Thank you very very much for all your help!</span></div>
<div><span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;"><br>
</span></div>
<div><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">Best,</span></div>
<div><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">Ioanna</span></div>
<div><br>
</div>
<br>
<p></p>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> fieldtrip <fieldtrip-bounces@science.ru.nl> on behalf of Stephen Whitmarsh <stephen.whitmarsh@gmail.com><br>
<b>Sent:</b> 26 June 2019 10:58:32<br>
<b>To:</b> 'FieldTrip discussion list'<br>
<b>Subject:</b> Re: [FieldTrip] TFR with different trial lengths</font>
<div> </div>
</div>
<style>
<!--
@font-face
        {font-family:Wingdings}
@font-face
        {font-family:"Cambria Math"}
@font-face
        {font-family:Calibri}
p.x_MsoNormal, li.x_MsoNormal, div.x_MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif}
a:link, span.x_MsoHyperlink
        {color:#0563C1;
        text-decoration:underline}
a:visited, span.x_MsoHyperlinkFollowed
        {color:#954F72;
        text-decoration:underline}
p
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif}
p.x_msonormal0, li.x_msonormal0, div.x_msonormal0
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif}
span.x_EmailStyle19
        {font-family:"Calibri",sans-serif;
        color:#1F497D}
span.x_EmailStyle20
        {font-family:"Calibri",sans-serif;
        color:windowtext}
.x_MsoChpDefault
        {font-size:10.0pt}
@page WordSection1
        {margin:1.0in 1.0in 1.0in 1.0in}
div.x_WordSection1
        {}
-->
</style>
<div lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="x_WordSection1">
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D">Dear Ionna,</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D">First of all, in general FieldTrip works very well with different trial durations (that’s why there is a ‘time’ field for every trial in a ‘raw’ data structure),
 at least in those functions where it makes sense, although it’s definitely something to always check (never hurts).</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D">Secondly, in my memory at least, ‘mtmfft’ returns NaNs where there is no data, but the implementation of ‘tfr’ might be different and I trust that you have
 0s </span><span style="font-size:11.0pt; font-family:Wingdings; color:#1F497D">J</span><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D"> But it’s something to keep in mind as this suggests that you might have unexpected results
 if you change methods. It also emphasizes that you are asking freqanalysis to calculate power of data that doesn’t exist and although it seems handy, it might not be the most consistent way of scripting your analysis in the end. In particular when you will
 be averaging, calculating relative differences (baseline correction e.g.), etc., where you might not keep track of the fact that you are using 0s as if this was true data.</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D">In such situations as you describe, I myself typically do two different analysis: first I preprocess and epoch the stimulus-locked timecourse data once using
 the full (different) trial lengths, and then split my time-frequency-analysis up into one stimulus-locked analysis, and one response-locked analysis  (after re-aligning stimulus-locked data to the end of the trial), both using the shortest time duration. This
 allows me to easily average the time-frequency-data over trials without having different time-points/windows that I would have gotten if I was trying to response-lock TFR data that was calculated on stimulus-locked data. This is especially the case when using
 sliding time-windows (method = ‘mtmfft’) where those time-windows won’t perfectly align in time. (and using sliding time-windows with mtmfft, using steps of e.g. 0.05s will be more memory-efficient than calculating a wavelet for every time-point). Also, it
 would mean that all my power-estimates over time will have the same amount of trials.</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D">You can also ofcourse, if you really want to, loop over trials and append the trials (powspctrm and time) afterwards.</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D">Although not a direct answer to your question perhaps, I hope this helps.</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D">Cheers,</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D">Stephen</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D"> </span></p>
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_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"> fieldtrip <fieldtrip-bounces@science.ru.nl>
<b>On Behalf Of </b>Ioanna Zioga<br>
<b>Sent:</b> Wednesday, June 26, 2019 11:12 AM<br>
<b>To:</b> fieldtrip@science.ru.nl<br>
<b>Subject:</b> [FieldTrip] TFR with different trial lengths</span></p>
</div>
</div>
<p class="x_MsoNormal"> </p>
<div id="x_divtagdefaultwrapper">
<p><span style="font-family:"Calibri",sans-serif; color:black">Hello Fieldtrip community!</span></p>
<p><span style="font-family:"Calibri",sans-serif; color:black"> </span></p>
<p><span style="font-family:"Calibri",sans-serif; color:black">I want to do TFR analysis on datasets with trials with different lengths (as I'm analysing the time period from the onset of a stimulus until participant's response, which differs from trial to
 trial).</span></p>
<p><span style="font-family:"Calibri",sans-serif; color:black"> </span></p>
<p><span style="font-family:"Calibri",sans-serif; color:black">These are the parameters:</span></p>
<div>
<p class="x_MsoNormal"><span style="font-family:"Calibri",sans-serif; color:black">cfgft                   = [];</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-family:"Calibri",sans-serif; color:black">cfgft.method    = 'tfr';</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-family:"Calibri",sans-serif; color:black">cfgft.output      = 'pow';</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-family:"Calibri",sans-serif; color:black">cfgft.foi              = exp(linspace(log(2),log(45),50));</span></p>
</div>
<div>
<p class="x_MsoNormal"><b><span style="font-family:"Calibri",sans-serif; color:black">cfgft.toi              = [];</span></b><span style="font-family:"Calibri",sans-serif; color:black"></span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-family:"Calibri",sans-serif; color:black">cfgft.width         = 6;</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-family:"Calibri",sans-serif; color:black">cfgft.keeptrials  = 'yes';</span></p>
</div>
<p class="x_MsoNormal"><span style="font-family:"Calibri",sans-serif; color:black"> </span></p>
<p><span style="font-family:"Calibri",sans-serif; color:black">The result I get from the freqanalysis (powspctrm) is a
<b>trial x chan x freq x time </b>matrix, in which the <b>time </b>is the time of the trial with the largest duration. The datapoints of the trials with smaller durations are filled with zeros.</span></p>
<p><span style="font-family:"Calibri",sans-serif; color:black"> </span></p>
<p><span style="font-family:"Calibri",sans-serif; color:black">I would prefer to get the powspctrm without the zeros at the end, but maybe I can just exclude them later on from the analysis?</span></p>
<p><span style="font-family:"Calibri",sans-serif; color:black">Do you know if Fieldtrip works fine with trials of different durations? And if there is any other more efficient way to analyse trials with different durations?</span></p>
<p><span style="font-family:"Calibri",sans-serif; color:black"> </span></p>
<p><span style="font-family:"Calibri",sans-serif; color:black">Any help would be extremely appreciated, thanks so much in advance!</span></p>
<p><span style="font-family:"Calibri",sans-serif; color:black"> </span></p>
<p><span style="font-family:"Calibri",sans-serif; color:black">Best wishes,</span></p>
<p><span style="font-family:"Calibri",sans-serif; color:black">Ioanna</span></p>
<p><span style="font-family:"Calibri",sans-serif; color:black"> </span></p>
</div>
</div>
</div>
</body>
</html>