<div dir="auto"><div>Brilliant! Thanks Daniel, this worked perfectly.</div><div dir="auto"><br><br><div class="gmail_quote" dir="auto"><div dir="ltr">On Wed., 17 Oct. 2018, 15:35 Daniel Matthes, <<a href="mailto:dmatthes@cbs.mpg.de">dmatthes@cbs.mpg.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Kate,<br>
<br>
I did it in the following way:<br>
<br>
First, I did a regular import by ignoring the 'Bad Interval' markers.<br>
<br>
% -------------------------------------------------------------------------<br>
% Data import<br>
% -------------------------------------------------------------------------<br>
<br>
cfg              = [];<br>
cfg.dataset      = headerfile;<br>
cfg.trialfun     = 'ft_trialfun_brainvision_segmented';<br>
cfg.stimformat   = 'S %d';<br>
cfg.showcallinfo = 'no';<br>
<br>
cfg = ft_definetrial(cfg);<br>
data = ft_preprocessing(cfg);<br>
<br>
After that step I have all trials in my data structure, also the trials which have bad intervals.<br>
<br>
In the second step I did this with the data:<br>
<br>
% -------------------------------------------------------------------------<br>
% Estimate artifacts<br>
% -------------------------------------------------------------------------<br>
events = data.cfg.event;                                                    % extract all events from the data structure<br>
artifact = zeros(length(events), 2);                                        % allocate memory for the artifact array<br>
j = 1;<br>
<br>
for i=1:1:length(events)<br>
  if(strcmp(events(i).type, 'Bad Interval'))                                % search for bad interval events          <br>
    artifact(j,1)=events(i).sample;                                         % create artifact matrix<br>
    artifact(j,2)=events(i).sample + events(i).duration - 1;<br>
    j = j +1;<br>
  end<br>
end<br>
<br>
artifact = artifact(1:j-1, :);                                              % prune the artifact array to its actual size<br>
<br>
% -------------------------------------------------------------------------<br>
% Revise data<br>
% -------------------------------------------------------------------------<br>
cfg                           = [];<br>
cfg.event                     = events;<br>
cfg.artfctdef.reject          = 'complete';<br>
cfg.artfctdef.feedback        = 'no';<br>
cfg.artfctdef.xxx.artifact    = artifact;<br>
cfg.showcallinfo              = 'no';<br>
<br>
data = ft_rejectartifact(cfg, data);<br>
<br>
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<br>
<br>
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.<br>
<br>
All the best,<br>
Daniel<br>
<br>
----- Original Message -----<br>
From: "K S" <<a href="mailto:katemsto@gmail.com" target="_blank" rel="noreferrer">katemsto@gmail.com</a>><br>
To: "bioeng yoosofzadeh" <<a href="mailto:bioeng.yoosofzadeh@gmail.com" target="_blank" rel="noreferrer">bioeng.yoosofzadeh@gmail.com</a>><br>
Cc: <a href="mailto:fieldtrip@science.ru.nl" target="_blank" rel="noreferrer">fieldtrip@science.ru.nl</a><br>
Sent: Wednesday, October 17, 2018 12:01:46 PM<br>
Subject: Re: [FieldTrip] Rejecting BrainVision-marked 'Bad Intervals'<br>
<br>
Hi Vahab, <br>
<br>
Thanks for the response. <br>
<br>
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: <br>
<br>
"cfg.trials = {'s 1', 's 2'} except those also marked 'Bad Interval'" <br>
<br>
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. <br>
<br>
Any ideas? <br>
<br>
Many thanks, <br>
Kate <br>
<br>
<br>
On Tue, Oct 16, 2018 at 10:13 PM Vahab Yousofzadeh < <a href="mailto:bioeng.yoosofzadeh@gmail.com" target="_blank" rel="noreferrer">bioeng.yoosofzadeh@gmail.com</a> > wrote: <br>
<br>
<br>
Hi Kate, <br>
<br>
if it is a continuous data (before epoching), you can treat bad <br>
segments as an artifact (e.g. eog or muscle, etc) and do something <br>
like this, <br>
<br>
% artifact_EOG = [100 500]; % in sample <br>
<br>
cfg = []; <br>
cfg.artfctdef.eog.artifact = artifact_EOG; <br>
cfg.artfctdef.reject = 'value'; <br>
% cfg.artfctdef.value = 0; % replacing values with nan or 0 <br>
data_continuous_eog_clean = ft_rejectartifact(cfg, data); % data is <br>
the output from ft_preprocessing. <br>
<br>
% inspecting cleaned data <br>
cfg = []; <br>
cfg.continuous = 'yes'; <br>
cfg.viewmode = 'vertical'; % all channels seperate <br>
cfg.blocksize = 5; % view the continous data in 30-s blocks <br>
ft_databrowser(cfg, data_continuous_eog_clean); <br>
<br>
if the data is epoched, simply use ft_redefinetrial. <br>
<br>
Best, <br>
Vahab <br>
<br>
<br>
-- <br>
Kate Stone <br>
PhD candidate <br>
Vasishth Lab | Department of Linguistics <br>
Potsdam University, 14467 Potsdam, Germany <br>
<a href="https://auskate.github.io" rel="noreferrer noreferrer" target="_blank">https://auskate.github.io</a> <br>
<br>
_______________________________________________<br>
fieldtrip mailing list<br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer noreferrer" target="_blank">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
<a href="https://doi.org/10.1371/journal.pcbi.1002202" rel="noreferrer noreferrer" target="_blank">https://doi.org/10.1371/journal.pcbi.1002202</a><br>
_______________________________________________<br>
fieldtrip mailing list<br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer noreferrer" target="_blank">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
<a href="https://doi.org/10.1371/journal.pcbi.1002202" rel="noreferrer noreferrer" target="_blank">https://doi.org/10.1371/journal.pcbi.1002202</a><br>
</blockquote></div></div></div>