<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii"><meta name="Generator" content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
span.EmailStyle19
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.EmailStyle20
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style></head><body lang="EN-US" link="#0563C1" vlink="#954F72"><div class="WordSection1"><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Dear Ionna,<o:p></o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p><p class="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).<o:p></o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p><p class="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.<o:p></o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p><p class="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.<o:p></o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p><p class="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.<o:p></o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p><p class="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.<o:p></o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Cheers,<o:p></o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Stephen<o:p></o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p><div><div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in"><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"> 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<o:p></o:p></span></p></div></div><p class="MsoNormal"><o:p> </o:p></p><div id="divtagdefaultwrapper"><p><span style="font-family:"Calibri",sans-serif;color:black">Hello Fieldtrip community!<o:p></o:p></span></p><p><span style="font-family:"Calibri",sans-serif;color:black"><o:p> </o:p></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).<o:p></o:p></span></p><p><span style="font-family:"Calibri",sans-serif;color:black"><o:p> </o:p></span></p><p><span style="font-family:"Calibri",sans-serif;color:black">These are the parameters:<o:p></o:p></span></p><div><p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;color:black">cfgft                   = [];<o:p></o:p></span></p></div><div><p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;color:black">cfgft.method    = 'tfr';<o:p></o:p></span></p></div><div><p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;color:black">cfgft.output      = 'pow';<o:p></o:p></span></p></div><div><p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;color:black">cfgft.foi              = exp(linspace(log(2),log(45),50));<o:p></o:p></span></p></div><div><p class="MsoNormal"><b><span style="font-family:"Calibri",sans-serif;color:black">cfgft.toi              = [];</span></b><span style="font-family:"Calibri",sans-serif;color:black"><o:p></o:p></span></p></div><div><p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;color:black">cfgft.width         = 6;<o:p></o:p></span></p></div><div><p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;color:black">cfgft.keeptrials  = 'yes';<o:p></o:p></span></p></div><p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;color:black"><o:p> </o:p></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.<o:p></o:p></span></p><p><span style="font-family:"Calibri",sans-serif;color:black"><o:p> </o:p></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?<o:p></o:p></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?<o:p></o:p></span></p><p><span style="font-family:"Calibri",sans-serif;color:black"><o:p> </o:p></span></p><p><span style="font-family:"Calibri",sans-serif;color:black">Any help would be extremely appreciated, thanks so much in advance!<o:p></o:p></span></p><p><span style="font-family:"Calibri",sans-serif;color:black"><o:p> </o:p></span></p><p><span style="font-family:"Calibri",sans-serif;color:black">Best wishes,<o:p></o:p></span></p><p><span style="font-family:"Calibri",sans-serif;color:black">Ioanna<o:p></o:p></span></p><p><span style="font-family:"Calibri",sans-serif;color:black"><o:p> </o:p></span></p></div></div></body></html>