[FieldTrip] some of the requested samples occur twice
Robin
robince at gmail.com
Fri Jun 7 17:03:21 CEST 2013
Hi Jörn,
Thanks.
I am already using negative trlpadding.
In this case I am trying to do the artifact detection on in memory trial
data, because I want to do it after denoise_pca. I am not sure if this is
correct but it seemed to me that denoise_pca is to correct physical
aquisition artifacts so it would be better to do it before trying to
identify biological artifacts that are a part of the recorded signal.
The code I am using is below. If you could point out how to add padding for
the ft*artifact* section so that it can work on in memory data it would be
great.
Thanks,
Robin
%% Automatic artifact rejection
% for each run
run_data = cell(1,length(sub.blocks));
trl_idx = 0;
for ri=1:length(sub.blocks)
% extra data to allow padding in artifact detection
filterpad = 0.2;
prestim = 0.5;
poststim = 0.6;
% extract trials
cfg = [];
cfg.dataset = fullfile(sub.megDataPath, num2str(sub.blocks(ri)), 'c,rfDC');
cfg.trialdef.eventtype = 'TRIGGER';
cfg.trialdef.eventvalue = 192;
cfg.trialdef.prestim = prestim + filterpad;
cfg.trialdef.poststim = poststim + filterpad;
cfg.trialfun = 'ft_trialfun_general';
cfg.continuous = 'yes';
cfg = ft_definetrial(cfg);
% overwrite unnecessary constant eventvalue
% with trial number within this block
cfg.trl(:,4) = (1:size(cfg.trl,1)) + trl_idx;
trl_idx = trl_idx + size(cfg.trl,1);
% remove jump artifact trials
trlidx = ismember(cfg.trl(:,4), good_trials);
cfg.trl = cfg.trl(trlidx, :);
% load
cfg.detrend = 'yes';
% long padding for line noise removal
cfg.dftfilter = 'yes';
cfg.padding = 10;
run_raw = ft_preprocessing(cfg);
% apply denoise_pca
cfg = [];
if isfield(sub,'posthoc_badchannels')
remove_chans = sub.posthoc_badchannels;
else
remove_chans = {};
end
cfg.channel = ft_channelselection([{'all'} remove_chans],
good_meg_channels);
cfg.trials = find(ismember(run_raw.trialinfo, good_trials));
run_clean = ft_denoise_pca(cfg, run_raw);
% artifact detection
cfg = [];
cfg.continuous = 'no'; % some trials are excluded
cfg.trl = run_clean.sampleinfo;
cfg.artfctdef.muscle.trlpadding = -filterpad;
cfg.artfctdef.muscle.cutoff = 20;
[cfg, artifact] = ft_artifact_muscle(cfg, run_clean);
cfg.artfctdef.eog.trlpadding = -filterpad;
cfg.artfctdef.eog.channel = {'A150' 'A124'};
cfg.artfctdef.eog.cutoff = 5;
[cfg, artifact] = ft_artifact_eog(cfg, run_clean);
% reject artifacts
cfg.artfctdef.reject = 'complete';
run_artfree = ft_rejectartifact(cfg, run_clean);
% reduce to the original window
cfg = [];
cfg.toilim = [-prestim poststim];
run_artfree = ft_redefinetrial(cfg, run_artfree);
run_data{ri} = run_artfree;end
On Mon, Jun 3, 2013 at 10:30 AM, "Jörn M. Horschig" <
jm.horschig at donders.ru.nl> wrote:
Hi Robin,
>
> it's not a bug that ft_fetch_data is not allowing for overlap. The
> function needs to be generic and eventually allow for fetching data
> extending over several trial segments. However, what should be the way to
> fetch data that occurs twice, i.e. at the end of one trial and the
> beginning of another? If you have data with overlapping samples, it is not
> straight forward to define data from one trial as to be fetched and ignore
> the other. Since preprocessing options like filters are applied per trial
> segment, data will differ between trial segments if it overlaps. As there
> are a multitude of possibilities to deal with this and none of them is
> perfect (imho neither of them can even be called good), we decided to not
> allow for that.
>
> For your problem, however, imho you can define negative trial padding in
> the function call to ft_artifact_zvalue, which should effectively pad. Have
> you tried this rather than padding manually?
>
> Best,
> Jörn
>
>
> On 5/31/2013 6:14 PM, Robin wrote:
>
>> I have a problem in preprocessing where I am getting this error:
>>
>> """
>> some of the requested samples occur twice in the data
>>
>> Error in ft_artifact_zvalue (line 262)
>> dat{trlop} = ft_fetch_data(data, 'header', hdr, 'begsample',
>> trl(trlop,1)-fltpadding, 'endsample', trl(trlop,2)+fltpadding,
>> 'chanindx', sgnind, 'checkboundary', strcmp(cfg.continuous,'no
>> Error in ft_artifact_muscle (line 158)
>> [tmpcfg, artifact] = ft_artifact_zvalue(tmpcfg, data);
>> """
>>
>> I think this is because I am manually adding some extra padding to the
>> trials so that the artifact filtering can use that padding (I am doing
>> the artifact filtering on data in memory which is output from
>> ft_denoise_pca). So in this case it is not a problem if consecutive
>> trials overlap a bit.
>>
>> I would therefore like to disable this error and wondered what is the
>> best way to do it. I am a bit confused because ft_artifact_zvalue
>> calls ft_fetch data with a "checkboundary" option which looks like it
>> might be what I want (and set correctly), but ft_fetch_data doesn't
>> seem to use that option. Instead it has an allowoverlap option.
>>
>> So for now I will manually add the allowoverlap option to the call in
>> ft_artifact_zvalue, but I wondered what checkboundary doesn't appear
>> in ft_fetch_data or if this might be a bug.
>>
>> Cheers
>>
>> Robin
>> ______________________________**_________________
>> fieldtrip mailing list
>> fieldtrip at donders.ru.nl
>> http://mailman.science.ru.nl/**mailman/listinfo/fieldtrip<http://mailman.science.ru.nl/mailman/listinfo/fieldtrip>
>>
>
>
> --
> Jörn M. Horschig
> PhD Student
> Donders Institute for Brain, Cognition and Behaviour
> Centre for Cognitive Neuroimaging
> Radboud University Nijmegen
> Neuronal Oscillations Group
> FieldTrip Development Team
>
> P.O. Box 9101
> NL-6500 HB Nijmegen
> The Netherlands
>
> Contact:
> E-Mail: jm.horschig at donders.ru.nl
> Tel: +31-(0)24-36-68493
> Web: http://www.ru.nl/donders
>
> Visiting address:
> Trigon, room 2.30
> Kapittelweg 29
> NL-6525 EN Nijmegen
> The Netherlands
>
> ______________________________**_________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl
> http://mailman.science.ru.nl/**mailman/listinfo/fieldtrip<http://mailman.science.ru.nl/mailman/listinfo/fieldtrip>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20130607/db65d038/attachment-0002.html>
More information about the fieldtrip
mailing list