[FieldTrip] Change in output of ft_freqanalysis

Schoffelen, J.M. (Jan Mathijs) janmathijs.schoffelen at donders.ru.nl
Sat Mar 4 20:25:56 CET 2023


Dear Alison,

Thanks for the feedback, and good to hear that you now found (and fixed) the root cause of the issue!

Best wishes, and keep up the good work.

Jan-Mathijs


PS: one important take home message of all this is that - when comparing power spectra between groups/conditions - the 0-padding should be the same across conditions compared.

On 4 Mar 2023, at 19:57, Harris, Alison <Alison.Harris at ClaremontMcKenna.edu<mailto:Alison.Harris at ClaremontMcKenna.edu>> wrote:

Dear Jan-Mathijs,

Thank you for your response! (And, yes, I had forgotten to mention that the data is log10 transformed after the call to ft_freqstatistics.)

Now that I know what to look for in the cfg, I can see that the pad length is different between the 2018 and 2019 versions, and I can see the latency issue from ft_timelockanalysis as well. If I encounter any issues going forward, I will make sure to double-check the cfg first!

However, I was still curious as to why the pad lengths were different for the two conditions (finger-tapping vs. rest) within the 2019 version of FieldTrip. After inspecting the cfg information as you suggested, I found an issue with the cfg latency related to the epoch time limits I had specified in EEGLAB. Now that is fixed, the difference in padlength between the two conditions appears fully resolved.

Thank you again for your help!
Alison

--
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/__http://www1.cmc.edu/pages/faculty/AHarris__;!!HJOPV4FYYWzcc1jazlU!8LXPpKB98F5mHtfzaSvM5MlIv_kF0vQY93O697dhahSj-KracGDrjkC-VL0HBjIPk7olYagCwf2-LHgGlo3yVMNA2OW5e1FtRN4wFg$ <https://urldefense.com/v3/__http://www1.cmc.edu/pages/faculty/AHarris__;!!HJOPV4FYYWzcc1jazlU!52Ow35M2EdLFn-nJgEpnXNu1mWR09SR0lMlWGFt0sRkCMp3CbLax81t55CUXqXaTmc4fAji1WD4IbSFVcKPc01q5684GbfvPSVHtEbB_k4NCsg0TXw$>

From: fieldtrip <fieldtrip-bounces at science.ru.nl<mailto:fieldtrip-bounces at science.ru.nl>> On Behalf Of Schoffelen, J.M. (Jan Mathijs) via fieldtrip
Sent: Saturday, March 4, 2023 5:42 AM
To: FieldTrip discussion list <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>>
Cc: Schoffelen, J.M. (Jan Mathijs) <janmathijs.schoffelen at donders.ru.nl<mailto:janmathijs.schoffelen at donders.ru.nl>>
Subject: Re: [FieldTrip] Change in output of ft_freqanalysis

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!8LXPpKB98F5mHtfzaSvM5MlIv_kF0vQY93O697dhahSj-KracGDrjkC-VL0HBjIPk7olYagCwf2-LHgGlo3yVMNA2OW5e1EHq5gK5g$ <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!8LXPpKB98F5mHtfzaSvM5MlIv_kF0vQY93O697dhahSj-KracGDrjkC-VL0HBjIPk7olYagCwf2-LHgGlo3yVMNA2OW5e1GyWhWf4A$ <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$<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/a42438d9/attachment.htm>


More information about the fieldtrip mailing list