[FieldTrip] Change in output of ft_freqanalysis

Schoffelen, J.M. (Jan Mathijs) janmathijs.schoffelen at donders.ru.nl
Sat Mar 4 14:42:00 CET 2023


Dear Alison,

Thanks for your detailed report.

Given that you did not send along any time domain data in the data you shared, I tried to reproduce your observation by simulating some data, and then passing those data on to ft_freqanalysis, in 4 different versions of the fieldtrip code: 20171231, 20181231, 20191231, and today’s version. I did not manage to reproduce your issue, that is, all four sets of spectra are numerically identical. Based on this, there is no reason to suspect that something changed in the code.

Next, I inspected some of the data that you shared, specifically the files:

S005_Action_FreqCorr.mat
S005_Action_FreqCorrFFT_Boot_2018.mat
S005_Action_FreqCorrFFT_Boot_2019.mat

I can confirm that the power spectra look different, but upon inspection of the cfg’s of the data objects; <variable>.cfg -> so were the cfgs!

In other words, my working hypothesis is now that the cfg details cause the changes in the spectra.

The specification of cfg.taper/cfg.tapsmofrq influences the shape of the spectra, but I won’t discuss that aspect any further here.

Specifically what seems to explain your observations, are the different values of the cfg.pad parameter.  This value has an effect on the overall scaling of the spectra, which could explain the vertical shift of some of the spectra that you reported (BTW, as a side note, I don’t understand why the values in the spectra are < 0 for the higher frequencies: this suggests that the numbers were post-processed in some way, because power is always postive, so I suspect an undocumented/unmentioned log10 transform or so).

In more detail: if you increase the padding parameter, the extra zero-padding ramps up the spectral resolution of the power spectrum, which means that all signal power is to be divided across a larger amount of frequency bins. This reduces the amount of energy per bin, and may explain the overall shift down if the padding is increased. This is because the integral of the power spectrum (i.e. the sum across all frequency bins - which amounts to more bins than you may have requested for your output) should amount to the total variance of the underlying signal. If I subtract the ‘2018’ file’s power spectrum from the ‘2019’ file’s power spectrum I get an on average difference of 0.3, which is in line with the log10(2) difference implied by an increase of the padding parameter from 8 to 16.

Now, what was a bit confusing to me is the fact that I noticed the difference in padding when looking at the value of  <variable>.cfg.pad. This is the number that is used in the algorithm, and which relates to the lengthy paragraph above. When I looked a bit further, in <variable>.cfg.callinfo.usercfg.pad I noticed the ’nextpow2’, which is the default value that you also reported in your e-mail. So, somehow FieldTrip’s translation of ’nextpow2’ into a numeric value for padding was different in the two versions. Then I recursed into the function call history, and noticed that the call to ft_freqanalysis was preceded by a call to ft_timelockanalysis. Now my suspicion is that it could be that there was a change in the code of ft_timelockanalysis, between end 2018 and 2019. This indeed seems to be the case. The cfg to ft_timelockanalysis contained an option cfg.latency = [1 9]. This option, however, was not functional in the 2018 version (I tried it myself and got a warning that the option cfg.latency was forbidden, and removed from the cfg). In the 2019 version the latency selection was functional. In other words, when subjecting the data to ft_timelockanalysis of 2018 did NOT lead to a cutting of 8 seconds of data, and hence to potentially longer than 8 seconds of data that served as an input into ft_freqanalysis, which consequently translated ’nextpow2’ into 16 seconds of padded with 0’s data, rather than the value of 8 in the 2019 version.

I hope this helps, I am going back to BWV867 now.

Best wishes,
Jan-Mathijs










On 3 Mar 2023, at 20:50, Harris, Alison via fieldtrip <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>> wrote:

Dear FieldTrip community,

My name is Alison Harris and I have been using FieldTrip functions for time-frequency analysis for several years now as part of my EEG research. However, I recently attempted to re-analyze some old data using ft_freqanalysis in the latest version of FieldTrip, and the output does not match my earlier results.

I am trying to perform a frequency analysis for a motor execution task with alternating 8-s periods of finger-tapping and rest. The two conditions are preprocessed in EEGLAB and then separately imported to FieldTrip for frequency analysis. The cfg and command are as follows:

    freqcfg = [];
    freqcfg.method = 'mtmfft';
    freqcfg.output = 'pow';
    freqcfg.keeptrials       = 'no';
    freqcfg.keeptapers       = 'no';
    freqcfg.foi = [1:30];
    freqcfg.taper = 'dpss';
    freqcfg.tapsmofrq  = 1;
    freqcfg.pad              = 'nextpow2';
    freqcfg.feedback         = 'text';
    [freqdata] = ft_freqanalysis(freqcfg,tldata);

When I initially ran this analysis in 2019, the power spectra for action and rest conditions were largely overlapping. However, when I reran the analysis earlier this week (using the same data and cfg), the two power spectra were offset, such that one power spectrum was noticeably lower on the y-axis than the other. For the two participants I examined, there was not a consistent pattern in terms of which power spectrum was offset: the power spectrum for the finger-tapping condition was higher in one, whereas the resting power spectrum was lower in the other.

I then tested out my program with two earlier versions of FieldTrip that were available for download: fieldtrip-20191231 and fieldtrip-20191213. The change in the output of ft_freqanalysis seems to date to the 2019 version, as the 2018 output looked more similar to my existing results from a previous version of FieldTrip. I also tried specifying the “polyremoval” parameter, and redid the preprocessing in EEGLAB with and without detrending, but none of these changes seem to fundamentally affect the offset of the power spectra.

Here is a link with data from two participants and plots of the power spectra from before and after 2019: https://urldefense.com/v3/__https://claremontmckenna.box.com/s/gu796rvvsgipnwkm4cb13k5fhtdpu5f0__;!!HJOPV4FYYWzcc1jazlU!44iEww9Z3aCrSCYnc1aeDeI7PUp1OlDKBKaK-t-xXeDkwZkdp3bZ2qVDyEfuuP8DfWa1CVGQWvEufVwm4VsrTBxaMNAzkuoGP5cs7g$ <https://urldefense.com/v3/__https://claremontmckenna.box.com/s/gu796rvvsgipnwkm4cb13k5fhtdpu5f0__;!!HJOPV4FYYWzcc1jazlU!_AWV1fOSVX5tHme3OeHf6q76srFJ4TcvvLtenRnbF2VDh6fOQW4CMFSLoytvKYc-XQQjU18ERSfYG-nv1jeraFpKi4vjyHuaNupSNy8$>.

Is there some difference in how the ft_freqanalysis command is called from 2019 onward that would explain this output?

Thank you for your help!
Alison Harris

--
Alison Harris, PhD
Ostby-Cook Associate Professor of Psychology & George R. Roberts Fellow
Claremont McKenna College
850 Columbia Avenue
Claremont, CA 91711
Phone: (909) 607-9397
Email: aharris at cmc.edu<mailto:aharris at cmc.edu>
Web: https://urldefense.com/v3/__https://www1.cmc.edu/pages/faculty/aharris__;!!HJOPV4FYYWzcc1jazlU!44iEww9Z3aCrSCYnc1aeDeI7PUp1OlDKBKaK-t-xXeDkwZkdp3bZ2qVDyEfuuP8DfWa1CVGQWvEufVwm4VsrTBxaMNAzkurQlo_2_w$ <https://urldefense.com/v3/__https://www1.cmc.edu/pages/faculty/aharris__;!!HJOPV4FYYWzcc1jazlU!_AWV1fOSVX5tHme3OeHf6q76srFJ4TcvvLtenRnbF2VDh6fOQW4CMFSLoytvKYc-XQQjU18ERSfYG-nv1jeraFpKi4vjyHua46XzWYw$>



_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!6-XHrlUkkd_1vVSBACjQ5qHDM_nHf2XPA6MhiyMtazq0wT8M-I6yHJf_JCkX0wwtBcqY4Id84no93eWi4zDChGcV9iQ5SThIWVw8vg$

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


More information about the fieldtrip mailing list