[FieldTrip] Reducing edge effects in TF analysis with padding

Schoffelen, J.M. (Jan Mathijs) janmathijs.schoffelen at donders.ru.nl
Thu Feb 20 08:25:47 CET 2025


Hi Sarah,

For ft_preprocessing, the value that you need to specify for cfg.padding is the total length to which the data will be padded, not the length with which the data will be padded. In your case you would need to specify a value of something about 6 or so. Irrespective of this, I would not recommend to apply padding to reduce the fundamental limitation due to the fact that the data are too short for a good estimate of the low frequency components. Note that with too enthusiastic mirror padding you will ‘wrap around’ your data, causing the padded data towards the left to be contaminated with post stimulus data.

Good luck and best wishes,
Jan-Mathijs

On 19 Feb 2025, at 23:21, Pieper, Sarah Morgan via fieldtrip <fieldtrip at science.ru.nl> wrote:

Dear Fieldtrippers,

My name is Sarah Pieper and I'm a graduate student at a neurophysiology lab at Purdue University. I'm currently working on a project where I'm performing time-frequency analysis with Morlet wavelets. I've run the TF analysis in Fieldtrip and am receiving the typical U-shaped power spectrum with NaNs around the edges. I'm hoping to reduce these edge effects at least somewhat with padding, since they are currently contaminating my baseline period, but have not been successful with this.

I'm reading in already preprocessed data from BrainVision Analyzer. I've created segments that correspond to the entire duration of each trial, from -500 ms to 4400 ms, and am interested in analyzing most of it (ideally from -300 ms to around 4000 ms). I'd like to use a baseline of -300 to -100 ms. The sampling rate is 250 Hz.

I've been trying to reduce the edge effects with zero or mirror-padding but find that the results visually look the same with or without padding, with the same edge effects. When looking at the actual power spectrum results, the number of NaNs is also identical with or without padding. Essentially, I'm not recovering any additional power spectrum values with padding and I wanted to ask if I'm performing the padding correctly or if I just shouldn't expect to reduce edge effects with padding.

Here is my zero-padding code:
cfg = [];
cfg.channel = 'EEG';
cfg.method = 'wavelet';
cfg.width = linspace(3, 15, length(3:1:50));
cfg.output = 'pow';
cfg.foi = 3:1:50;
cfg.toi = -0.5:0.048:4.4;
cfg.pad = 4.9;
cfg.padtype = 'zero';
TFRwave = ft_freqanalysis(cfg, eeg_data)
Here is my mirror-padding code. I add the mirror-padding in during the ft_preprocessing step as instructed in the tutorials, then follow up with the TF analysis using ft_freqanalysis like the code above:
cfg = [];
cfg.dataset = 'path to file.dat';
cfg.trialdef.eventtype = 'Stimulus';
cfg.trialdef.eventvalue = 'S 0';
cfg.trialdef.prestim = 0.5;
cfg.trialdef.poststim = 4.4;
[cfg] = ft_definetrial(cfg);
cfg.padding = 0.5;
cfg.padtype = 'mirror';
[eeg_data_padded] = ft_preprocessing(cfg);
Thank you in advance for your help!

Best,
Sarah

_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmailman.science.ru.nl%2Fmailman%2Flistinfo%2Ffieldtrip&data=05%7C02%7Cfieldtrip%40science.ru.nl%7Ccdd57f696b8f42bfc1a108dd517fcbc2%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638756331500643266%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=xBMTOLq34HPPizM9GVutO5RKVYd%2FtVfnUmOrMLP6Aew%3D&reserved=0>
https://doi.org/10.1371/journal.pcbi.1002202<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdoi.org%2F10.1371%2Fjournal.pcbi.1002202&data=05%7C02%7Cfieldtrip%40science.ru.nl%7Ccdd57f696b8f42bfc1a108dd517fcbc2%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638756331500672046%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=UjPya%2BZN69V%2BBvkWXWe%2FsWxUsdbdzroXtTgzvFfcLvQ%3D&reserved=0>

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


More information about the fieldtrip mailing list