<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
Hi Helin,
<div><br>
</div>
<div>If you want, of course you can implement trial-masked robust detrending in your own code and/or using functionality from NoiseTools and the ADAM toolbox :). If you want to do this by means of a high-level FieldTrip call, in the current state of the codebase,
something like the following should - in principle - be possible:</div>
<div><br>
</div>
<div>cfg = [];</div>
<div>cfg.custom.funhandle =@fancyfunctionthatdoessomething;</div>
<div>cfg.custom.varargin = opts; % with opts being a structure containing fields that specificy additional options for the function -> this should be changed into a cell array but requires minor tweaks to the fieldtrip code FIXME</div>
<div>dataout = ft_preprocessing(cfg, datain);</div>
<div><br>
</div>
<div>if you have a matlab m-file, called fancyfunctionthatdoessomething, which takes as input arguments a (single trial) data matrix as a first input argument, with the channels defined in the rows, + an optional additional opts structure, with fields specifying
additional options, then the lower level preproc function in fieldtrip/private (which takes care of the specified ‘ft_preprocessing cfg-options’, will execute the function for you in a for-loop across the elements of your data.trial cell-array. </div>
<div><br>
</div>
<div><br>
</div>
<div>The above recipe is an undocumented option, which may come across as a bit of an over-engineered functionality. Specifically, you would achieve the very same if you were to write a matlab script as follows:</div>
<div><br>
</div>
<div>for i = 1:numel(data.trial)</div>
<div> datapreprocessed.trial{i} = fancyfunctionthatdoessomething(data.trial{i}, opts);</div>
<div>end</div>
<div><br>
</div>
<div>What I can see as an advantage for using the custom function handle, and going through ft_preprocessing, is that there will be a trace of the exact processing steps in the output data object (in dataout.cfg.previous). Always good for reproducibility etc.</div>
<div><br>
</div>
<div>In your specific use case, you would need to write a wrapper function around nt_detrend that estimates the polynomial coefficients on the masked that, and subsequently applies the modelled polynome to the unmasked data. </div>
<div><br>
</div>
<div>Best wishes and happy computing,</div>
<div><br>
</div>
<div>Jan-Mathijs</div>
<div><br>
</div>
<div><br>
</div>
<div><br id="lineBreakAtBeginningOfMessage">
<div><br>
<blockquote type="cite">
<div>On 22 Nov 2025, at 14:44, Helin Erden via fieldtrip <fieldtrip@science.ru.nl> wrote:</div>
<br class="Apple-interchange-newline">
<div>
<div>
<div>
<div dir="ltr">Dear community,</div>
<div dir="ltr"><br>
</div>
<div dir="ltr">I am doing an EEG-MVPA study, using Fieldtrip for preprocessing. To target slow drifts, instead of using high-pass filtering + baseline correction, I was wondering if I could implement “trial-masked” robust detrending in Fieldtrip as in this
paper: </div>
<div dir="ltr"><br>
</div>
<div dir="ltr"><a href="https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.sciencedirect.com%2Fscience%2Farticle%2Fpii%2FS0165027021000157&data=05%7C02%7Cfieldtrip%40science.ru.nl%7C92621d5644d24bdaeb4708de2c0744ef%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638996606892816562%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=fRO5kQmyTflo7dMrj7wNWMQ8vKawuBrYe2HjAPUbIwM%3D&reserved=0" originalsrc="https://www.sciencedirect.com/science/article/pii/S0165027021000157" originalsrc="https://www.sciencedirect.com/science/article/pii/S0165027021000157" target="_blank">van
Driel, J., Olivers, C. N. L., & Fahrenfort, J. J. (2021). High-pass filtering artifacts in multivariate classification of neural time series data. Journal of Neuroscience Methods, 352, 109080. https://doi.org/10.1016/j.jneumeth.2021.109080</a> <br>
<div><br>
</div>
<div dir="auto"><br>
</div>
<div dir="auto">I believe nt_detrend from Noisetools can be used with Fieldtrip structures, but I am especially wondering if combining it with trial-masking is possible in Fieldtrip, and which functions would help. Thank you in advance for any help or advice.</div>
<div dir="auto"><br>
</div>
<div dir="auto"></div>
<div dir="auto">Best,</div>
<div dir="auto">Helin</div>
</div>
</div>
</div>
_______________________________________________<br>
fieldtrip mailing list<br>
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip<br>
https://doi.org/10.1371/journal.pcbi.1002202<br>
</div>
</blockquote>
</div>
<br>
</div>
</body>
</html>