[FieldTrip] Rejecting BrainVision-marked 'Bad Intervals'
Daniel Matthes
dmatthes at cbs.mpg.de
Wed Oct 17 14:48:29 CEST 2018
Hi Kate,
I did it in the following way:
First, I did a regular import by ignoring the 'Bad Interval' markers.
% -------------------------------------------------------------------------
% Data import
% -------------------------------------------------------------------------
cfg = [];
cfg.dataset = headerfile;
cfg.trialfun = 'ft_trialfun_brainvision_segmented';
cfg.stimformat = 'S %d';
cfg.showcallinfo = 'no';
cfg = ft_definetrial(cfg);
data = ft_preprocessing(cfg);
After that step I have all trials in my data structure, also the trials which have bad intervals.
In the second step I did this with the data:
% -------------------------------------------------------------------------
% Estimate artifacts
% -------------------------------------------------------------------------
events = data.cfg.event; % extract all events from the data structure
artifact = zeros(length(events), 2); % allocate memory for the artifact array
j = 1;
for i=1:1:length(events)
if(strcmp(events(i).type, 'Bad Interval')) % search for bad interval events
artifact(j,1)=events(i).sample; % create artifact matrix
artifact(j,2)=events(i).sample + events(i).duration - 1;
j = j +1;
end
end
artifact = artifact(1:j-1, :); % prune the artifact array to its actual size
% -------------------------------------------------------------------------
% Revise data
% -------------------------------------------------------------------------
cfg = [];
cfg.event = events;
cfg.artfctdef.reject = 'complete';
cfg.artfctdef.feedback = 'no';
cfg.artfctdef.xxx.artifact = artifact;
cfg.showcallinfo = 'no';
data = ft_rejectartifact(cfg, data);
These line are removing all trials with bad intervals completely from the data structure. But if you set the option cfg.artfctdef.reject to another value i.e. 'partial', you can also remove only the bad parts of certain trials
I wrote this code some time ago, today I would replace the for-cycle with some more effective code. But in general it should work.
All the best,
Daniel
----- Original Message -----
From: "K S" <katemsto at gmail.com>
To: "bioeng yoosofzadeh" <bioeng.yoosofzadeh at gmail.com>
Cc: fieldtrip at science.ru.nl
Sent: Wednesday, October 17, 2018 12:01:46 PM
Subject: Re: [FieldTrip] Rejecting BrainVision-marked 'Bad Intervals'
Hi Vahab,
Thanks for the response.
The data is already epoched so I tried ft_redefine trial as you suggested. I think the problem is that the segments marked as artefact are also marked with triggers. I therefore need some way of saying:
"cfg.trials = {'s 1', 's 2'} except those also marked 'Bad Interval'"
I even tried cfg.trials = not('Bad Interval') - it doesn't work. I tried it also with ft_rejectartifact but I'm not sure how to get it to recognise the 'Bad Interval' marking.
Any ideas?
Many thanks,
Kate
On Tue, Oct 16, 2018 at 10:13 PM Vahab Yousofzadeh < bioeng.yoosofzadeh at gmail.com > wrote:
Hi Kate,
if it is a continuous data (before epoching), you can treat bad
segments as an artifact (e.g. eog or muscle, etc) and do something
like this,
% artifact_EOG = [100 500]; % in sample
cfg = [];
cfg.artfctdef.eog.artifact = artifact_EOG;
cfg.artfctdef.reject = 'value';
% cfg.artfctdef.value = 0; % replacing values with nan or 0
data_continuous_eog_clean = ft_rejectartifact(cfg, data); % data is
the output from ft_preprocessing.
% inspecting cleaned data
cfg = [];
cfg.continuous = 'yes';
cfg.viewmode = 'vertical'; % all channels seperate
cfg.blocksize = 5; % view the continous data in 30-s blocks
ft_databrowser(cfg, data_continuous_eog_clean);
if the data is epoched, simply use ft_redefinetrial.
Best,
Vahab
--
Kate Stone
PhD candidate
Vasishth Lab | Department of Linguistics
Potsdam University, 14467 Potsdam, Germany
https://auskate.github.io
_______________________________________________
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