[FieldTrip] Strange behavior of mtmconvol

Schoffelen, J.M. (Jan Mathijs) janmathijs.schoffelen at donders.ru.nl
Thu Dec 8 14:19:22 CET 2022


Hi Martin,

The short answer to your question “does mtmconvol remove 1/f?” is “no”, unless you specify cfg.polyremoval = 1. And even then it is not removing 1/f, but it removes the linear trend from the data, which indeed might tamper with the overall spectral shape, depending on the data.

Looking at your code (trying to resist the urge ask back a few questions, e.g. “what’s the question behind your question?” , “why do you want to use superlets?”, “why don’t you just use ‘mtmfft’ if you want a time unresolved spectrum?” “etc?”), and dismissing a few suboptimalities in the definition of the options, and guessing a bit what you try to compare, I wrote some code myself:

clear all;
data.time{1} = (0:99999)./1000;
data.label{1} = 'chan01';
data.trial{1} = 1;
for k = 2:100000
  data.trial{1}(k)=randn(1)+1.*data.trial{1}(k-1);
end


cfg        = [];
cfg.length = 10;
data       = ft_redefinetrial(cfg, data);
data.time(2:end) = data.time(1);

cfg           = [];
cfg.method    = 'mtmfft';
cfg.tapsmofrq = 1;
cfg.foilim    = [4 100];
freqmtmfft    = ft_freqanalysis(cfg, data);

% fixed window per frequency
cfg           = [];
cfg.method    = 'mtmconvol';
cfg.foi       = 4:0.5:100;
cfg.t_ftimwin = ones(1,numel(cfg.foi)).*2;
cfg.tapsmofrq = ones(1,numel(cfg.foi));
cfg.toi       = 0:0.1:10;
freqmtmconvol1 = ft_freqanalysis(cfg, data);
cfg.tapsmofrq(:) = 2;
freqmtmconvol1b = ft_freqanalysis(cfg, data);

% window changes per frequency -> this leads to a per-frequency different
% intrinsic spectral resolution, which might complicate across frequency
% bin direct comparisons of magnitude because each bin actually represents
% a surface with a varying width
cfg.t_ftimwin = 4./cfg.foi;
cfg.tapsmofrq = cfg.foi.*0.5;
freqmtmconvol2 = ft_freqanalysis(cfg, data);

% wavelet
cfg = removefields(cfg, {'tapsmofrq' 't_ftimwin'});
cfg.method = 'wavelet';
freqwavelet = ft_freqanalysis(cfg, data);

% superlet
cfg.method  = 'superlet';
cfg.combine = 'additive';
cfg.order   = round(linspace(1,40,numel(cfg.foi)));
freqsuperlet = ft_freqanalysis(cfg, data);

figure;
subplot(221); plot(freqmtmfft.freq, log10(freqmtmfft.powspctrm));
subplot(222); plot(freqmtmconvol1.freq,log10(squeeze(nanmean(freqmtmconvol1.powspctrm,3))));
hold on; plot(freqmtmconvol1.freq,log10(squeeze(nanmean(freqmtmconvol1b.powspctrm,3))));
subplot(223); plot(freqmtmconvol2.freq,log10(squeeze(nanmean(freqmtmconvol2.powspctrm,3))));
subplot(224); plot(freqwavelet.freq,log10(squeeze(nanmean(freqwavelet.powspctrm,3))));
hold on; plot(freqsuperlet.freq,log10(squeeze(nanmean(freqsuperlet.powspctrm,3))));




The resulting figure does not show anything too much out of order when comparing the different spectral analysis methods, apart from a difference in scaling, and a zigzag in the application of ‘mtmconvol’, but only when a frequency specific time window is used. In all reconstructions, the 1/f is clearly present.

[cid:CAD8ED7C-D7DE-4E07-A429-BC536CFD319A]


So my first thought was: “shi*** data from Stockholm”.

But only then I saw cfg.polyremoval = 1….

If you specify this value, you actually do something that is equivalent to a ‘detrend’, which removes the linear trend from each of the epochs. Repeating the exercise above with cfg.polyremoval=1 everywhere (exercise to the reader) will not yield qualitatively very different images using the dummy data I generated. Of note, however, will be the observation that the polyremoval does have a quantitative effect on the ‘mtm<method>’ methods, but not on the ‘wavelet/superlet’.

Back to Stockholm...




Best wishes,
Jan-Mathijs




On 7 Dec 2022, at 14:26, Martin Schaefer via fieldtrip <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>> wrote:

Dear fieldtrip community,

I'm getting strange results when I compute the powerspectrum of my data with the mtmconvol method.
When I plot my results over time and frequencies, I get most power in the higher frequencies, compared to the wavelet, tfr, or superlet methods where I get most power in the lower frequencies.
When I look at just the power over frequencies, it looks like mtmconvol removes 1/f. Is this indeed the case? If so, why does it do this?
I attached plots of the powerspectrum for the mtmconvol method, superlet method, and superlet method adjusted for 1/f by multiplying the power with the frequency which makes it look a lot more like the mtmconvol results.

My settings:
fieldtrip-20220401

cfg                    = [];
cfg.output          = 'pow';
cfg.keeptrials      = 'yes';
cfg.channel         = 'all';
cfg.method         = 'mtmconvol'; /'superlet'
cfg.taper             = 'dpss';
cfg.foi                 = 4:.5:100;
cfg.t_ftimwin       = 7./cfg.foi;
cfg.toi                = 'all';
cfg.polyremoval    = 1;
cfg.pad               = 11;
cfg.tapsmofrq      = 0.3.*cfg.foi ;

% for 'superlet' method
cfg.width            = 3;
cfg.gwidth          = 3;
cfg.combine         = 'additive';
cfg.order            = round(linspace(1,40,numel(cfg.foi)));

ft_freqanalysis(cfg, data);

I'm grateful for any input.

Best regards,
Martin


------------
Martin Schaefer | PhD Student
https://www.perceptionlab.se/<https://urldefense.com/v3/__https://www.perceptionlab.se/__;!!HJOPV4FYYWzcc1jazlU!6E0MVBn8an3EeOuwe7vCNsQsy0cLjZpH2MLR-NtvwNdNIHOO6ol1OnAuFcvnb4HliBgtbubbaas5o203LnHjnfIyfMAhtNXs6kt_Bw$>
Department of Clinical Neuroscience (CNS), K8
Karolinska Institutet | 17 177 Stockholm | Nobels väg 9
martin.schaefer at ki.se<mailto:artin.arshamian at ki.se>
______________________________________
Karolinska Institutet – a Medical University



När du skickar e-post till Karolinska Institutet (KI) innebär detta att KI kommer att behandla dina personuppgifter. Här finns information om hur KI behandlar personuppgifter<https://urldefense.com/v3/__https://ki.se/medarbetare/integritetsskyddspolicy__;!!HJOPV4FYYWzcc1jazlU!6E0MVBn8an3EeOuwe7vCNsQsy0cLjZpH2MLR-NtvwNdNIHOO6ol1OnAuFcvnb4HliBgtbubbaas5o203LnHjnfIyfMAhtNWe5uWFFg$>.

Sending email to Karolinska Institutet (KI) will result in KI processing your personal data. You can read more about KI’s processing of personal data here<https://urldefense.com/v3/__https://ki.se/en/staff/data-protection-policy__;!!HJOPV4FYYWzcc1jazlU!6E0MVBn8an3EeOuwe7vCNsQsy0cLjZpH2MLR-NtvwNdNIHOO6ol1OnAuFcvnb4HliBgtbubbaas5o203LnHjnfIyfMAhtNUtA_RZmg$>.
<powerspectrum mtmconvol.jpg><powerspectrum superlet 1 over f adjusted.jpg><powerspectrum superlet.jpg>_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!6E0MVBn8an3EeOuwe7vCNsQsy0cLjZpH2MLR-NtvwNdNIHOO6ol1OnAuFcvnb4HliBgtbubbaas5o203LnHjnfIyfMAhtNUSrmmIgQ$


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20221208/bc39db56/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot 2022-12-08 at 14.06.21.png
Type: image/png
Size: 42632 bytes
Desc: Screenshot 2022-12-08 at 14.06.21.png
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20221208/bc39db56/attachment.png>


More information about the fieldtrip mailing list