[FieldTrip] Possible bug in mtmconvol padding option

Schoffelen, J.M. (Jan Mathijs) jan.schoffelen at donders.ru.nl
Thu Feb 27 09:29:15 CET 2020

Hi Mireia,

Indeed the cfg.pad parameter operates on the full epoch length, not on the sliding window length. This is per design, and it is not a bug.

Although I don’t fully understand the deeper reason of why you want to do what you want to do, one way to get there would be to handcraft your own procedure, and create the TFRs in a computationally inefficient for-loop. This would require a lot of data bookkeeping on your end.


for k = 1:the-number-of-time-point-onto-which-you-want-to-estimate-your-tfr

  cfg = [];
  cfg.latency = timepoint(k)+[-0.25 0.25-1./data.fsample];
  tmpdata = ft_selectdata(cfg, data);

  cfg = [];
  cfg.pad = 0.5;
  cfg.method = ‘mtmfft’;
  tmpfreq(k) = ft_freqanalysis(cfg, tmpdata);


freq = tmpfreq(1);
freq.powspctrm = cat( 3-or-4-depending-on-whether-you-did-cfg.keeptrials=‘yes’-previously, tmpfreq.powspctrm);
freq.time = timepoint;
freq.dimord = (‘rpt_)chan_freq_time’;

Sounds like an overkill to me, though.

Best wishes, and good luck,


PS: Please feel free to suggest an update to the help-section of the ft_freqanalysis function, to explain better the cfg.pad parameter. We look forward to a PR!

On 24 Feb 2020, at 18:17, TORRALBA CUELLO, MIREIA <mireia.torralba at upf.edu<mailto:mireia.torralba at upf.edu>> wrote:

I am a Fieldtrip user and I came across this error

ft_error('the specified padding is too short');

when calculating power spectrum using this code:


As I see it, the padding should work in each of my time windows (0.5 seconds length each) and therefore the error should not appear, but when I inspected which is the segment padded by the function I saw
that what is being padded to 1 is the whole segment. I think this is not right, as what I would like is to increase my frequency resolution by padding each of the timewindows where I calculate the spectrum. The problem I have is that I want to use as a baseline another segment which has 0.5 seconds length, and as the frequency extracted by mtmconvol depends on the length of the segment, I am getting different frequency resolutions for the baseline and the target data.

Can anyone help me?
Thanks and best regards.


Mireia Torralba Cuello
Multisensory Research Group
Center for Brain and Cognition, Universitat Pompeu Fabra
Address: Edifici Mercè Rodoreda 24.313
        c\ Ramon Trias Fargas, 25-27
        08005 Barcelona
Tel +34 935422745

fieldtrip mailing list

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20200227/23037329/attachment.htm>

More information about the fieldtrip mailing list