[FieldTrip] using Matlab instead of Fieldtrip toolboxes

Roy Cox roycox.roycox at gmail.com
Tue Feb 22 18:05:53 CET 2022


I'm having trouble getting Fieldtrip (revision 8108d99ee.) to reliably use
Matlab's builtin signal toolbox, rather than the one in
Fieldtrip/external/signal. I followed the online suggestions (
and checked the info surrounding ft_defaults.

Background: Matab's filtfilt is about twice as fast as Fieldtrip's, which
would make a big difference for our overnight sleep EEG. I tested a
bandpass filter on a small recording while explicitly adding/removing
*Fieldtrip/external/signal* from the path (as NOT recommended, I know).
Doing this right before filtfilt is called (from ft_preprocessing ->
preproc -> ft_preproc_bandpassfilter -> filter_with_correction, line 73):


*tic;filt = filtfilt(B, A, dat')';tocElapsed time is 7.384431 seconds.*


*tic;filt = filtfilt(B, A, dat')';tocElapsed time is 3.328224 seconds.*

I get similar speedups when timing ft_preprocessing, different filters, and
for (much) larger datasets, so definitely worth it.

Now I try to do things the recommended way from a fresh Matlab session
(with all Fieldtrip-related stuff removed from startup.m).

First I check:

*which -all filtfilt*
*C:\Program Files\MATLAB\R2020a\toolbox\signal\signal\filtfilt.m*

Then I initialize Fieldtrip:


and check filtfilt again:

*which -all
Files\MATLAB\R2020a\toolbox\signal\signal\filtfilt.m            %Shadowed*

which makes sense since the default is to use Fieldtrip's filtfilt.

I then do as suggested:

*global ft_defaultft_default.toolbox.signal='matlab';*

and can verify that the global var is correctly set:


*ans =  *

*struct with fields:     images: 'compat'      stats: 'compat'     signal:
'matlab'    cleanup: {}*

But calling *which -all filtfilt *again, the Fieldtrip path has not been
removed. I tried calling *ft_defaults *a second time (perhaps in order for
the new values in *ft_default* to take effect?), but both filtfilt paths
remain. And I verified that Fieldtrip in fact continues to use its own slow
filtfilt implementation when calling *ft_preprocessing*. So it appears that
the contents of *ft_default.toolbox* aren't actually used to update paths,
which may or may not be as intended.

I have to add that at one (and only one) point during my lengthy
explorations Fieldtrip DID pick the requested version (and removed the path
to *\external\signal\ *). But I haven't been able to reproduce since, so
this seems to work only under highly specific conditions.

Explicitly removing the path to *\external\signal\ *using *rmpath* seems to
work, but is also risky because I imagine Fieldtrip may attempt to restore
this path depending on what functions are called elsewhere in a script
(especially if the request for using the Matlab version in
*ft_default.toolbox* is missed/ignored).

Besides physically deleting folders, how do I ensure Fieldtrip ALWAYS uses
Matlab's signal (or stats/image) toolboxes and will NEVER attempt to add
its own versions back to the Matlab path?

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

More information about the fieldtrip mailing list