<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
From the ‘help’ section of ft_freqanalysis:
<div class=""><br class="">
</div>
<br class="">
%   cfg.pad         = number, 'nextpow2', or 'maxperlen' (default),<b class=""><font color="#ff0f51" class=""> length<br class="">
%                      in seconds to which the data can be padded out.</font></b> The<br class="">
%                      padding will determine your spectral resolution. If you<br class="">
%                      want to compare spectra from data pieces of different<br class="">
%                      lengths, you should use the same cfg.pad for both, in<br class="">
%                      order to spectrally interpolate them to the same<br class="">
%                      spectral resolution.  The new option 'nextpow2' rounds<br class="">
%                      the maximum trial length up to the next power of 2.  By<br class="">
%                      using that amount of padding, the FFT can be computed<br class="">
%                      more efficiently in case 'maxperlen' has a large prime<br class="">
%                      factor sum.<br class="">
<br class="">
Thus, the number you give in will be the total length of the vector after padding. This number should therefore be at least as long as the longest trial in your data. Which is also what the error message reflects. 
<div class=""><br class="">
</div>
<div class="">Best wishes,</div>
<div class="">Jan-Mathijs</div>
<div class=""><br class="">
<div class=""><br class="">
<br class="">
<blockquote type="cite" class="">On 28 Jun 2019, at 00:08, Ioanna Zioga <<a href="mailto:i.zioga@qmul.ac.uk" class="">i.zioga@qmul.ac.uk</a>> wrote:<br class="">
<br class="">
Dear Fieldtrip community!<br class="">
<br class="">
I would like to ask for your advice on zero padding when doing TFR analysis.<br class="">
<br class="">
I'm analysing trials of different lengths, so I loop over the trials to run ft_freqanalysis.<br class="">
I read in the tutorials that the padding length should be >= to the length of the trial.<br class="">
<br class="">
Therefore, I prepared these parameters:<br class="">
<br class="">
cfg = [];<br class="">
cfg.method = 'wavelet';<br class="">
cfg.output = 'pow';<br class="">
cfg.foi = [2:1:40];<br class="">
cfg.width = 6;<br class="">
cfg.keeptrials = 'yes';<br class="">
cfg.toi = data.time{1};<br class="">
cfg.pad = round(length(data.time{1}(1,:))/500)+5; % duration of trial plus 5 seconds<br class="">
% my sampling rate is 500<br class="">
res = ft_freqanalysis(cfg,data);<br class="">
<br class="">
Even if I add 5 seconds more to the length of the cfg.pad, SOMETIMES (and I <br class="">
cannot figure out a pattern..), I get this error:<br class="">
Error using ft_specest_wavelet (line 60)<br class="">
the padding that you specified is shorter than the data<br class="">
<br class="">
Error in ft_freqanalysis (line 505)<br class="">
        [spectrum,foi,toi] = ft_specest_wavelet(dat, time, 'timeoi', cfg.toi, 'width', cfg.width, 'gwidth', cfg.gwidth,options{:},<br class="">
        'feedback', fbopt);<br class="">
<br class="">
The length of the above trial was 20 seconds (+5 secs padding).<br class="">
Do you have any idea what is the problem?<br class="">
<br class="">
Freqanalysis runs smoothly in trials with other trials with smaller or longer duration, and I can't find a pattern of when this error comes up..<br class="">
<br class="">
Any idea would be extremely helpful, thanks so so much in advance!<br class="">
<br class="">
Best,<br class="">
Ioanna<br class="">
<br class="">
_______________________________________________<br class="">
fieldtrip mailing list<br class="">
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" class="">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br class="">
https://doi.org/10.1371/journal.pcbi.1002202<br class="">
</blockquote>
<br class="">
</div>
</div>
</body>
</html>