Trial definition and artifact rejection

Robert Oostenveld r.oostenveld at FCDONDERS.RU.NL
Mon Aug 6 17:40:19 CEST 2007

Dear Cristine

On 6 Aug 2007, at 16:42, Christine Tillmann wrote:

> I have a question concerning data preprocessing;
> does anybody know how to specify different time windows
> for 1) the definition of correct trials and 2) artifact rejection?

I presume that you are referring to the automatic artifact detection

> So far, I have used a function that looks for correct data segments
> defined by a stimulus trigger and the button press following within a
> 1sec window after the trigger. These segments are then further
> analysed
> with artifact rejection. Since I lose a lot of trials with this
> procedure because reaction times seem to be a little longer, I
> wanna use
> a longer time window, e.g. 2 sec., for defining correct trials, and
> then
> shorten the segments again so that the artifact rejection and all
> further analysis steps are only performed with 1sec. long windows....
> I would be glad if anyone had an idea how to solve this problem!

By default the artifact_xxx functions scan the segments that you have
marked in cfg.trl (i.e. using definetrial and your custom trial
function) plus some additional padding. See figure 1 on http://
This also means that you can specify a different cfg.trl for the
artifact_xxx detection functions than in rejectartifact. E.g. you can do

cfg = []
cfg = ...
cfg1 = definetrial(cfg)  % condition 1
cfg2 = definetrial(cfg)  % condition 2
cfg.trl = [cfg1.trl; cfg2.trl];;
cfg = artifact_eog(cfg); % scan all trials for artifacts simultaneously
cfg.trl = cfg1.trl       % condition 1
cfg1_clean = rejectartifact(cfg);
cfg.trl = cfg2.trl       % condition 2
cfg2_clean = rejectartifact(cfg);
data1 = preprocessing(cfg1_clean)
data2 = preprocessing(cfg2_clean)

The padded data is read into memory, bandpass filterend and hilbert
transformed to estimate the instntaneous amplitude of the signal in
that specific frequency band. The filtering and hilbert
transformation often results in edge artifacts, hence the filter
padding is required. The filter padding is removed from each segment
before further processing and thersholding of the data. That you
loose a lot of trials may be related to not specifying enough filter
padding. Shortening the trials then will not help. If you specify, then you can look in detail at the
reason why trials are rejected.

Note that the output of artifact_xxx is an updated
structure. You can look in (and e.g.
preprocess those segments) to see where the artifacts were. That is a
Nx2 matrix similar to "trl" (see definetrial) but without the offset
in the last column (which should be added, e.g. with zeros, if you
wish to use it to read in he data with preprocessing).

If the automatic artifact rejection is too difficult to get to work
on your data (it was designed for continuous CTF data and is not
guaranteed to work on other data), then I suggest that you use

best regards,

The aim of this list is to facilitate the discussion between users of the FieldTrip  toolbox, to share experiences and to discuss new ideas for MEG and EEG analysis. See also and

More information about the fieldtrip mailing list