[FieldTrip] Downsampling Issue

Alain de Cheveigne alain.de.cheveigne at ens.psl.eu
Fri May 13 16:21:36 CEST 2022


Hi Jan-Mathjis, 

While you're at it you might consider fixing an issue with resample which is that the antialiasing filter is too high.  

The -6dB cutoff is at Nyquist, implying that power just beyond Nyquist is not attenuated much, which can lead to aliased components that can be confusing.  

The simple fix is to set it a bit lower, as in the version attached. 

Best, 
Alain

-------------- next part --------------
A non-text attachment was scrubbed...
Name: nt_resample.m
Type: application/octet-stream
Size: 5477 bytes
Desc: not available
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20220513/6dd046c8/attachment.obj>
-------------- next part --------------


> On 13 May 2022, at 13:44, Schoffelen, J.M. (Jan Mathijs) via fieldtrip <fieldtrip at science.ru.nl> wrote:
> 
> Thanks Eleanor,
> 
> Coincidentally just now one of our toolkit participants ran in exactly the same error.
> 
> It is caused by the fact that FieldTrip expects that a resample.m function exists in the signal processing toolbox. Your installation of Matlab does not contain this toolbox, so Matlab falls back the the version of resample.m in the timeseries toolbox. This file, however, is incompatible with FieldTrip’s expectations unfortunately. 
> 
> A workaround for now could be to get yourself a copy of the octave (i.e. open source) version of the resample version (https://sourceforge.net/p/octave/signal/ci/default/tree/inst/resample.m), and adjust it a little bit so that it works in matlab.
> 
> This is what I will do (and include it in FieldTrip), to avoid this problem in the future.
> 
> I will create an issue on  https://github.com/fieldtrip/fieldtrip/issues/2027  where you can track the progress.
> 
> Best wishes,
> 
> Jan-Mathijs
> 
> 
> 
>> On 13 May 2022, at 10:25, Eleanor Moses via fieldtrip <fieldtrip at science.ru.nl> wrote:
>> 
>> Hi Jan-Mathijs,
>> 
>> sorry for my misunderstanding, this is what I get using both resampledata and resample.
>> 
>> >> which resampledata
>> 'resampledata' not found.
>> >> which resample
>> C:\Program Files\MATLAB\R2021b\toolbox\matlab\timeseries\@timeseries\resample.m  % timeseries method
>> >> 
>> 
>> Do you have any suggestions on how to ensure that I end up in the correct .m file when I call this function?
>> 
>> Best wishes,
>> 
>> Eleanor
>> 
>> Eleanor Moses BPsych(Hons)
>> PhD Candidate
>> School of Psychology
>> The University of Queensland
>> Brisbane QLD 4072 Australia
>> Email: eleanor.moses at uqconnect.edu.au
>> 
>> From: fieldtrip <fieldtrip-bounces at science.ru.nl> on behalf of Schoffelen, J.M. (Jan Mathijs) via fieldtrip <fieldtrip at science.ru.nl>
>> Sent: 13 May 2022 17:50
>> To: FieldTrip discussion list <fieldtrip at science.ru.nl>
>> Cc: Schoffelen, J.M. (Jan Mathijs) <janmathijs.schoffelen at donders.ru.nl>
>> Subject: Re: [FieldTrip] Downsampling Issue
>>  
>> Sorry Eleanor, I was unclear. I meant to ask about the ‘resample’ function. The fact that you get an error internally when this function is called, makes me suspect that you end up in a wrong (overloaded but with different functionality) m-file.
>> 
>> Best wishes,
>> Jan-Mathijs
>> 
>> 
>>> On 13 May 2022, at 04:18, Eleanor Moses via fieldtrip <fieldtrip at science.ru.nl> wrote:
>>> 
>>> Hi Jan-Mathijs,
>>> 
>>> thankyou for your reply. This is what I get (just the one version). 
>>> 
>>> >> which ft_resampledata
>>> C:\Users\Ellie\AppData\Roaming\MathWorks\MATLAB Add-Ons\Collections\fieldtrip-20220426\ft_resampledata.m
>>> 
>>> I have also added the relevant fieldtrip directories using ft_defaults. 
>>> 
>>> Thankyou 
>>> 
>>> Eleanor Moses BPsych(Hons)
>>> PhD Candidate
>>> School of Psychology
>>> The University of Queensland
>>> Brisbane QLD 4072 Australia
>>> Email: eleanor.moses at uqconnect.edu.au
>>> 
>>> From: fieldtrip <fieldtrip-bounces at science.ru.nl> on behalf of Schoffelen, J.M. (Jan Mathijs) via fieldtrip <fieldtrip at science.ru.nl>
>>> Sent: 12 May 2022 00:36
>>> To: FieldTrip discussion list <fieldtrip at science.ru.nl>
>>> Cc: Schoffelen, J.M. (Jan Mathijs) <janmathijs.schoffelen at donders.ru.nl>
>>> Subject: Re: [FieldTrip] Downsampling Issue
>>>  
>>> Hi Eleanor,
>>> 
>>> Could it be that you have an unexpected version of resampledata on your matlab path? What do you get if you type which resampledata on the matlab command line?
>>> 
>>> Best wishes,
>>> Jan-Mathijs
>>> 
>>>> On 11 May 2022, at 10:45, Eleanor Moses via fieldtrip <fieldtrip at science.ru.nl> wrote:
>>>> 
>>>> Dear community,
>>>> 
>>>> I am new to fieldtrip and am trying to preprocess my EEG data so that it was be compatible with later analysis using cosmomvpa.
>>>> However, I keep running into the same error with the ft_resampledata function.
>>>> 
>>>> When I attempt to downsample, this is the error I get
>>>> 
>>>> Check for incorrect argument data type or missing argument in call to function 'resample'.
>>>> 
>>>> Error in ft_resampledata (line 231)
>>>>         newdat = transpose(resample(transpose(olddat),fsres,fsorig));
>>>> 
>>>> Error in Fieldtrip_Test (line 27)
>>>> data_eeg = ft_resampledata(cfg, data_eeg);
>>>> 
>>>> 
>>>> I have checked previous posts to the community, to check that I am not encourting previously posted errors (I am downsampling from 1024Hz to 512, or have tried to 256, so this is a neat integer division which was a problem previously discussed that produced this error with ft_resampledata).
>>>> I have ensured that I have specified all necessary configurations (cfg.resamplefs = 512; cfg.detrend = 'no';) and aside from this am using the default configurations.
>>>> When I remove the resampling section from my preprocessing pipeline script, it otherwise works fine, and works with mvpa functions from cosmomvpa.
>>>> I tried to apply the ft_resampledata function after the ft_preprocessing function as the help ft_resampledata notes indicate that data should be
>>>> resampled as obtained from the ft_preprocessing function, but encounter the same error even if I rearrange when I use ft_resampledata (before pre-proc, right after importing data).
>>>> 
>>>> I also encounter this error when I try to run tutorial fieldtrip preprocessing scripts that I have downloaded from the cosmomvpa website - so the error isn't unique to my script.
>>>> 
>>>> 
>>>> I have included the data structure and cfg's for the function below. 
>>>> 
>>>> % Raw data configuration
>>>> %            hdr: [1×1 struct]
>>>> %          label: {73×1 cell}
>>>> %           time: {[0 9.7656e-04 0.0020 0.0029 0.0039 0.0049 0.0059 0.0068 0.0078 0.0088 0.0098 0.0107 … ]}
>>>> %          trial: {[73×391168 double]}
>>>> %        fsample: 1024
>>>> %     sampleinfo: [1 391168]
>>>> %            cfg: [1×1 struct]
>>>> 
>>>> 
>>>> cfg = [];
>>>> cfg.resamplefs = 256;
>>>> cfg.detrend = 'no'; 
>>>> data_eeg = ft_resampledata(cfg, data_eeg);
>>>> 
>>>> Any help would be greatly appreciated, kind regards
>>>> 
>>>> Eleanor Moses 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> Eleanor Moses BPsych(Hons)
>>>> PhD Candidate
>>>> School of Psychology
>>>> The University of Queensland
>>>> Brisbane QLD 4072 Australia
>>>> Email: eleanor.moses at uqconnect.edu.au
>>>> 
>>>> _______________________________________________
>>>> 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_puilsIXBSl-VOPdSiXILpOMezgn_ng1hMy0gaxjp0fc3pv8jiBwG1L_o4YBZTBM2aSjSABeEueTp4obfl-YYHVJS2isgYDW59U3Q$
>>> 
>>> _______________________________________________
>>> fieldtrip mailing list
>>> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>> https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!5vIRskZ8q-baSkTYVKHdrn-tPB6p06Sv84lJkNyIKzG_beWjwUTiOQ6UhsjasLhUt88MSABz0VqCVPID_otcJjv5FbnjGvV39_0KNA$ 
>> 
>> _______________________________________________
>> fieldtrip mailing list
>> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>> https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!4Iz5S1yy8Ou8y0y1U0BAziooHkywyx4mU2t3DfZq7lbeZLAwvMlidcY8wfjXpWlrmeCjqdTNdrcXj7JXFCWee4khcfTNxaB_ZKJZCQ$
> 
> _______________________________________________
> fieldtrip mailing list
> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
> https://doi.org/10.1371/journal.pcbi.1002202



More information about the fieldtrip mailing list