[FieldTrip] When to detrend/demean

Vitória Magalhães Piai vitoria.piai at gmail.com
Mon Jan 7 14:14:48 CET 2013

Thank you Roemer, Ingrid, and Stephen.

Let me see if I can summarise it all and do a last check.

So for the ERPs, it's better not to detrend, especially if the signal is 
noisy (high amplitude noise) at the end (due to speach artifacts).
I know that using demean with a baseline window is "common sense" but 
I'm a bit against this in many cases.
For example, in my data now, I have a whole semantic context building up 
towards one final word, which people have to produce overtly. I can 
expect (intuitively, theoretically, etc.) that anticipation will be 
going on, inducing changes in the signal. This is relevant cognitive 
stuff, not noise. Yet, it is in my "baseline period" (i.e., before 
people get the cue to say something). If I correct against this 
baseline, I'll not be doing justice to my signal in my opinion.
What I did instead was to collect many trials (120 on average). So even 
without baseline correction, my waves across conditions are lying on top 
of each other until a certain point before the cue. I take this as an 
indication that I have a good SNR and if baseline correction is just to 
ensure that things are the same across conditions pre-stimulus, then it 
suffices for me if my waves are nicely on top of each other pre-stimulus 
(but deviating from each other before the onset of the cue).
I'd like to hear your opinion on this issue, though, if you think this 
still is problematic.

Indeed, Roemer, I had checked these FAQs before and concluded that my 
TFRs passed this specific sanity check as well, but thanx for pointing out.

The question that still remains is regarding demean in the 
preprocessing. FT page shows two possibilities.

Tutorial: ft_preprocessing default (no detrend/demean).

EEG specific:
cfg.demean = 'yes';
cfg.baselinewindow = [-0.2 0];
So the baseline correction is in there already at pre-processing. But 
this seems more specific for a ERP follow-up analysis to me, or isn't 
it? Having it as in the tutorial would be the most neutral/standard way, 
right? So maybe I could add a note to the page, if we agree on this.

Finally, having a demean using the whole trial instead already at 
pre-processing does not seem to create effects across conditions in 
later ERP and TFR analyses (without ICA), I'd conclude from this 
discussion, but please point out if I'm wrong.

Thanx a lot once more,
Cheers, Vitoria

On 1/7/2013 1:43 PM, fieldtrip-request at science.ru.nl wrote:
> Send fieldtrip mailing list submissions to
> 	fieldtrip at science.ru.nl
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
> or, via email, send a message with subject or body 'help' to
> 	fieldtrip-request at science.ru.nl
> You can reach the person managing the list at
> 	fieldtrip-owner at science.ru.nl
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of fieldtrip digest..."
> Today's Topics:
>     1. Re: When to detrend/demean (Roemer van der Meij)
>     2. Re: ??? Re: When to detrend/demean (Roemer van der Meij)
> ----------------------------------------------------------------------
> Message: 1
> Date: Mon, 7 Jan 2013 13:28:01 +0100
> From: Roemer van der Meij <r.vandermeij at donders.ru.nl>
> To: FieldTrip discussion list <fieldtrip at science.ru.nl>
> Subject: Re: [FieldTrip] When to detrend/demean
> Message-ID:
> 	<CA+WpQ37gyb0Twxk3m6-m+9K1qbPDXudSXxKcuYnRtimQ9-Uqjg at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
> Hi Vitoria,
> I have only one thing to add to Ingrid's clear explanation. For frequency
> analysis, it's mostly a matter of noise. If you do not demean, the 0Hz been
> can bleed into all other frequency bins in a funny but patterned way. For
> detrending, the same story applies. When not detrending, the power of the
> center frequency of the linear trend (this frequency is very low), can
> bleed into other bins.
> The FAQs have two great example on this:
> http://fieldtrip.fcdonders.nl/faq/why_does_my_tfr_look_strange
> http://fieldtrip.fcdonders.nl/faq/why_does_my_tfr_look_strange_part_ii
> Both are specific for when using 'mtmconvol' as frequency method (why this
> is so is explained shortly in the first FAQ), although in principle the
> issues could also occur using the other methods.
> Hope it helps!
> All the best,
> Roemer
> On Sun, Jan 6, 2013 at 3:24 AM, Ingrid Nieuwenhuis <
> inieuwenhuis at berkeley.edu> wrote:
>> Hi Vitoria,
>> The problem with these things is, it depends on what your interested in
>> (hypothesis) and which methods you're using to analyze the data (ERP or
>> frequanalysis, with our without ICA). All analysis steps have different pro
>> and cons, so depending on your hypotheses and effects, what's good in one
>> setup can be bad in the next. So you have to think of what the measures do,
>> and how that effects your data.
>> But now for some answers :) I'm just using a lot of experience and some
>> common sense, maybe people can add in some refs and math if they know :)
>> Demeaning just subtracts the mean of the specified time window (or indeed
>> whole trial) from all samples
>> detrending removes linear trend (you can also remove higher order trends,
>> just for completeness)
>> For ERPs you generally do want to demean using the baseline window, so the
>> effect cancels out pre-stim. You don't want to detrend here, since often
>> the ERP can have late components, and the signal might not be back to
>> baseline yet. If you detrend in such a case, you will decrease the value
>> samples late in the trials and increase the values during baseline. You
>> will tilt the data (end down thus start up). But if you expect a linear
>> trend due to equipment drift over longer time, that can muddle the ERP
>> effect, then you might want to detrend. Also when the signal is noisy (high
>> amplitude noise) at the end (due to speach artifacts), detrending might be
>> dangerous.
>> For frequency analysis, demeaning has (as far as I know) no effect, since
>> subtracting a constant does not change the frequency info in the signal. I
>> know people do tend to detrend before freq analysis (so I also tend to do
>> that), but I have to admit, I don't know why really. Maybe to get rid of
>> the drift, so it does not end up in the low frequencies. But again, the
>> effect of detrending (which freqs it affects) depends how long your time
>> window is, and which frequencies your interested in. If you are interested
>> in really low frequencies, detrending might change your effects.
>> Hope this helps somewhat,
>> Ingrid
>> On 1/5/2013 2:21 AM, Vit?ria Magalh?es Piai wrote:
>>> Dear ftrippers,
>>> I'm having a discussion with a colleague on something that is still a bit
>>> unclear to us. Since I trust the knowledge going around here a lot, I
>>> thought it would be my best chance to get a good answer: When should we
>>> demean/detrend?
>>> As relevant background, our EEG datasets involve speech production on
>>> every trial.
>>> We read in the data, use ft_databrowser to mark the artefacts and then do
>>> complete artefact rejection with ft_rejectartifact. The trials often
>>> include speech (onset).
>>> I see in the tutorial that the cfg for preprocessing is pretty simple,
>>> and ft_preprocessing default has no detrend/demean.
>>> But in the FT example 'Reading and pre-processing EEG data', the cfg is
>>> cfg.demean           = 'yes';
>>> cfg.baselinewindow  = [-0.2 0];
>>> In my data, I used cfg.demean = 'yes'; with no cfg for the baseline
>>> window because I don't want to correct the signal with a specific interval
>>> (and I assume this will take the whole segment then).
>>> Our concern is that, given that people speak during part of the trial
>>> (always towards the end), using demean here is not a good idea (the signal
>>> changes induced by moving the jaws, etc., are included in the calculation).
>>> Is this necessarily the case or can it be fixed with subsequent
>>> computations (see below)? Do I need to go through artefact rejection again?
>>> My guess would be that the damage caused by having demean here doesn't
>>> change that much where the eyeblinks are and I always take quite broad
>>> windows to mark the artefacts, so at least for the AR I should be safe, but
>>> I'd like to check that with you guys.
>>> Then, when calculating ERPs, I had both demean and detrend before
>>> timelocking.
>>> But for the TFRs, I didn't do any of these (dunno why). I'm using the
>>> ft_freqanalysis after the 2011 change (removing the first order linear
>>> trend from the time domain data).
>>> Do I need to redo my TFRs or is it enough if I do sanity checks and
>>> everything is in place (like visual alpha and gamma, etc.)?
>>> And my last question, for once and for all, so that I get it right next
>>> time from the start (assuming that I'll always have EEG speech production
>>> data with ERPs and TFRs analysed). Is this the best way to do it?
>>> - preprocess with default (so NO detrend and NO demean)
>>> - then demean and detrend for ft_timelockanalysis and ft_freqanalysis
>>> Thanx a lot, and (keeping to the Dutch tradition) all the best for 2013!
>>> Vitoria
>>> ______________________________**_________________
>>> fieldtrip mailing list
>>> fieldtrip at donders.ru.nl
>>> http://mailman.science.ru.nl/**mailman/listinfo/fieldtrip<http://mailman.science.ru.nl/mailman/listinfo/fieldtrip>
>> --
>> Ingrid Nieuwenhuis PhD
>> Postdoctoral Fellow
>> Sleep and Neuroimaging Laboratory
>> Department of Psychology
>> University of California, Berkeley
>> California 94720-1650
>> Tolman Hall, room 5305
>> ______________________________**_________________
>> fieldtrip mailing list
>> fieldtrip at donders.ru.nl
>> http://mailman.science.ru.nl/**mailman/listinfo/fieldtrip<http://mailman.science.ru.nl/mailman/listinfo/fieldtrip>

More information about the fieldtrip mailing list