Back to the main page.

Bug 2963 - ft_freqanalysis does not support mirror padding

Reported 2015-09-18 12:27:00 +0200
Modified 2019-08-10 12:30:58 +0200
Product: FieldTrip
Component: core
Version: unspecified
Hardware: PC
Operating System: Windows
Importance: P5 normal
Assigned to:
Depends on:
See also:

Maris - 2015-09-18 12:27:00 +0200

Maris - 2015-09-18 12:41:29 +0200

Created attachment 738 Data structure Run the code below using the data.mat. TFR.powspctrm will contain NaNs on both ends of the matrix; power estimates are given only when the time window (cfg.t_ftimwin) is fully within the data segment. This suggests that no mirror padding has been applied to the data. *Padding options are specified as described in the reference documentation of ft_freqanalysis. cfg = []; cfg.output = 'pow'; = 'all'; cfg.method = 'mtmconvol'; cfg.taper = 'hanning'; cfg.foi = 10; cfg.t_ftimwin = 0.5; cfg.toi = 3.5:0.05:5; cfg.pad = 2.1; % 1.5sec of data + 0.3sec of padding cfg.padtype = 'mirror'; cfg.keeptrials = 'no'; TFR = ft_freqanalysis(cfg, data);

Maris - 2015-09-18 12:43:59 +0200

Created attachment 739 Script (same as in comment)

Jan-Mathijs Schoffelen - 2015-09-18 13:00:29 +0200

Conceptually, the padding option here is meant to allow for spectral interpolation, and not for 'generating missing data' at the edges of the epochs. The NaNs at the edges are explicitly there (and always there!) for those time points that do not have a full t_ftimwin. I don't see actually why anybody would want to use any other padding than zero-padding (which by the way is always padding to the right of the epoch).

Maris - 2015-09-18 13:41:51 +0200

Thank you for the response. What a surprising answer, though! I would really appreciate a little bit of clarification/feedback, if possible. Thanks a lot in advance. I am not sure if I understood correctly what is meant by 'generating missing data'; in my case the padding is done to avoid data segments of radically different frequency content both before and after the period of interest, though technically they are there and could be used. 1 - May I ask why zero padding is always better? When data are zero padded it introduces a discontinuity and adds 'artificial data', while mirror padding duplicates real data, isn't that better?; on top of that, mirror padding also does not have the issue of discontinuity at the edges of the real data segment. 2 - I am aware that when performing frequency analysis the ft_specest_xxx functions are always called with prepadlength = 0. May I ask what is the reason for this? When I have a data segment cut out from the middle of a trial, wouldn't I want to be able to perform spectral interpolation on either end of the data segment? Best wishes, Maris

Jan-Mathijs Schoffelen - 2015-09-18 13:56:44 +0200

Hi Maris, I suggest to move this discussion to the fieldtrip discussion list. Please make an account there (if you don't have one already), and post your questions there.

Robert Oostenveld - 2019-08-10 12:30:58 +0200

This closes a whole series of bugs that have been resolved (either FIXED/WONTFIX/INVALID) for quite some time. If you disagree, please file a new issue on