[FieldTrip] Problem with downsampling / automatic artifact rejection
Teresa Madsen
braingirl at gmail.com
Mon Mar 27 16:19:03 CEST 2017
I don't see anything obviously wrong with your cfg, but I don't know what
is loaded into the config variable - is it possible config.cfg.trl is
requesting samples that are not present in the input file? If it's based
on the data before downsampling, the sample numbers could be off by a
factor of 250.
If that's not it, here are some more general troubleshooting tips: First,
I would set Matlab to dbstop if warning so it pauses execution at that
warning message. You'll need to dbup at least once to get out of ft_warning,
and then you'll have access to the workspace of the preproc function.
Examine the dat variable for NaNs and see if you can track back to figure
out where they were added. Since dat is an input to that function, you
might start by typing dbup twice to get to the workspace of
ft_artifact_threshold
and verify whether any NaNs are present in dat there.
If neither of those help you figure out the problem, it should at least
give you more info to provide in a bug report to
http://bugzilla.fieldtriptoolbox.org/
Hope that helps,
Teresa
On Mon, Mar 27, 2017 at 5:34 AM, Alexandrina Guran <
alexandrina.guran at uni-luebeck.de> wrote:
> Dear FieldTrip Community,
>
>
>
> My name is Alexandrina Guran, I am a PhD Student at the University of
> Lübeck and I have recently started working with FieldTrip in order to
> preprocess (and later analyse) EEG data. I have encountered an odd problem, that
> I nor people I asked in the lab could solve, also using the help function
> and google:
>
>
>
> After running the epoching (trial length 5s), filtering (high-pass,
> low-pass and notch, for a time-frequency analysis) and downsampling (to 250
> Hz), I wanted to do an automatic artifact rejection, in order to have
> exploratory information of how many of my trials would be affected by
> artifacts and if there were participants that blinked on a majority of
> trials in order to determine whether I should shorten my trial length
> and/or conduct an ICA.
>
>
>
> I used the ft_artifact_threshold function, in Matlab R2016b, with
> different FieldTrip versions (march 2017 as well as end 2016 and end 2015).
>
> However, the automatic artifact detection did not work – that is, it would
> stop rejecting artifacts after a number x of trials (usually between 90 and
> 140 trials), depending on participant. I would get an error message but
> then the artifact rejection would go on, telling me all trials were ok
> (even if I set 1 microvolt as a threshold).
>
> The error message I got is the following:
>
>
>
> “(…) threshold artifact scanning: trial 128 from 320 exceeds max-threshold
>
> threshold artifact scanning: trial 129 from 320 is ok
>
> threshold artifact scanning: trial 130 from 320 is ok
>
> threshold artifact scanning: trial 131 from 320 is ok
>
> Warning: data contains NaNs, no filtering or preprocessing applied
>
> > In ft_warning (line 184)
>
> In preproc (line 283)
>
> In ft_artifact_threshold (line 164)
>
> In preprocessing (line 266)
>
> threshold artifact scanning: trial 132 from 320 is ok
>
> threshold artifact scanning: trial 133 from 320 is ok
>
> threshold artifact scanning: trial 134 from 320 is ok
>
> threshold artifact scanning: trial 135 from 320 is ok
>
> threshold artifact scanning: trial 136 from 320 is ok
>
> threshold artifact scanning: trial 137 from 320 is ok
>
> threshold artifact scanning: trial 138 from 320 is ok
>
> threshold artifact scanning: trial 139 from 320 is ok
>
> threshold artifact scanning: trial 140 from 320 is ok
>
> threshold artifact scanning: trial 141 from 320 is ok
>
> threshold artifact scanning: trial 142 from 320 is ok (…)”
>
>
>
> This was however only the case if I ran the artifact detection on
> down-sampled data. It worked fine with just filtered data.
>
>
>
> However, I checked the preprocessed (downsampled) data for NaNs (using the
> isnan-MATLAB function) and there were none to be found (I also checked
> visually in one dataset).
>
>
>
> Has anyone encountered this problem and found a solution?
>
>
>
> Of course, I considered just doing the downsampling after the automatic
> and visual artifact rejection, but I would like to be sure that the
> downsampling will work correctly at any point of the preprocessing and
> right now I am a little flummoxed at “what is happening” with the data in
> that function.
>
>
>
> Down below you can find code excerpts for both the artifact rejection and
> the downsampling. Both were looped over participants but the error appears
> regardless of that.
>
> Downsampling:
>
>
>
> cfg = [];
>
> cfg.dataset = ['tfdata_filtfilt_'
> num2str(subj(s)) '.mat']; %tfdata_filtfilt_ is the epoched and filtered
> data
>
> cfg.resamplefs = 250;
>
> cfg.detrend = 'no';
>
> cfg.inputfile = ['tfdata_filtfilt_'
> num2str(subj(s)) '.mat'];
>
> cfg.outputfile = ['tfdata_filt_rs_'
> num2str(subj(s)) '.mat'];
>
> datatfrs = ft_resampledata(cfg)
>
>
>
> Artifact rejection
>
> cfg = [];
>
> config = load(['tfcfg_'
> num2str(subj(s)) '.mat']);
>
> cfg.trl = config.cfg.trl;
>
> cfg.continuous = 'no' ;
>
> cfg.artfctdef.threshold.channel = [1:28 33:63]; %exclude eye
> channels 'VEOG1' 'VEOG2' 'HEOG1' 'HEOG2'
>
> cfg.artfctdef.threshold.max = 75;
>
> cfg.artfctdef.threshold.min = -75;
>
> cfg.artfctdef.threshold.bpfilter = 'no';
>
> cfg.inputfile = ['tfdata_filt_rs_'
> num2str(subj(s)) '.mat'];
>
> cfg.outputfile = ['tfdata_artif_'
> num2str(subj(s)) '.mat'];
>
> cfg = ft_artifact_threshold(cfg);
>
> save (cfg.outputfile, 'cfg')
>
>
>
> Since I am new to FieldTrip, I can imagine it to be a “simple/stupid”
> error having to do with the cfg.
>
> Thank you for reading this and trying to help J
>
>
>
> Best regards
>
> Alexandrina
>
>
>
>
>
> --
>
> C.-N. Alexandrina Guran, M.Sc.
>
> PhD student
>
> Institute of Psychology I
>
> University of Lübeck
>
> Maria-Goeppert-Straße 9a
> 23562 Lübeck
>
> Germany
>
>
>
> Building MFC 8, 1st Floor, Room 1
>
> Phone: +49 451 3101 3635 <+49%20451%2031013635>
>
> Fax: +49 451 3101 3604 <+49%20451%2031013604>
>
>
>
>
>
>
>
> _______________________________________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl
> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>
--
Teresa E. Madsen, PhD
Research Technical Specialist: *in vivo *electrophysiology & data analysis
Division of Behavioral Neuroscience and Psychiatric Disorders
Yerkes National Primate Research Center
Emory University
Rainnie Lab, NSB 5233
954 Gatewood Rd. NE
Atlanta, GA 30329
(770) 296-9119
braingirl at gmail.com
https://www.linkedin.com/in/temadsen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20170327/862f6ad3/attachment-0002.html>
More information about the fieldtrip
mailing list