[FieldTrip] Errors with downsampling and artifact rejection
Schoffelen, J.M. (Jan Mathijs)
jan.schoffelen at donders.ru.nl
Tue Jun 23 08:42:03 CEST 2020
Hi Gaëlle,
Adding to Stephen’s comment: reading through the code and comments (highly recommended to occasionally do this, then you get a feel what’s going on under the hood) I saw that there’s a discrepancy between the comments in the help section of ft_resampledata, where it states that the default resamplefs=256, and the actually implemented default resamplefs, which is []. Apparently, MATLAB is lenient with respect to mathematical operations involving empty variables. Specifically, it doesn’t throw an error on lines 160/161 in ft_resampledata, where an empty variable is multiplied and divided by a scalar. Long story short, the silently accepted empty variable is the acual cause of the reported problem in ft_resampledata.
I look forward to a PR that fixes this. I suggest making the documentation consistent, i.e. stating that cfg.resamplefs is an argument that needs to be defined, and explicitly check this in the code, i.e. throw an error if it isn’t defined. This is typically done with a call to ft_checkconfig using the key-value pair ‘required’, and ‘resamplefs’ (in this case).
Thanks for your contribution,
Jan-Mathijs
On 22 Jun 2020, at 17:35, Stephen Whitmarsh <stephen.whitmarsh at gmail.com<mailto:stephen.whitmarsh at gmail.com>> wrote:
Dear Gaëlle,
You are using default settings for downsampling, which will then try to downsample to 256Hz. Your original samplerate is 1000Hz, so that isn't a neat integer division.
I tried the following, and could reproduce your problem:
Fs = 1000;
data_eeg = [];
data_eeg.label = {'a','b','c'};
data_eeg.time{1} = 0:1/Fs:10;
data_eeg.trial{1} = rand(length(data_eeg.label),length(data_eeg.time{1}));
data_eeg.Fs = Fs;
data_eeg.sampleinfo = [1, length(data_eeg.time{1})];
% Doesn't work:
cfg = [];
[data_eeg] = ft_resampledata(cfg, data_eeg);
% Does work:
cfg = [];
cfg.resamplefs = 250;
[data_eeg] = ft_resampledata(cfg, data_eeg);
So that deals with your first problem. Not sure why it has a problem with the downsampling to non-integer values, but it's good practice and much faster to stick to that anyway.
Not sure what to do with the artefact detection though, or what you expect; it seems you are running it with some contradictory settings/ways perhaps:
- use cfg.dataset if reading from disk directly OR give datastructure to function is you already have data in memory
- use cfg.continuous when data is not segmented
- the comment "jump" suggests you use settings for SQUID jumps, i.e. optimized for MEG, but that should not give an error :-)
I suspect you probably want to run artefact detection on your segmented data, so remove those references to the data on disk (datafile, headerfile), and the trl from the cfg, and give your segmented data as an argument as you did here:
%[cfg, artifact_jump] = ft_artifact_zvalue(cfg, data_eeg); %no plot error, but each trial has the same graph, also error using zeros
Let us know how it goes,
All the best,
Stephen
Op ma 22 jun. 2020 om 17:02 schreef Gaëlle Leys <gaelle.leys at kuleuven.be<mailto:gaelle.leys at kuleuven.be>>:
Dear Stephen,
I have included the data structures and cfg's involved in the functions.
1) A. data structure for resampling data (raw data after reading it in):
data_eeg =
struct with fields:
hdr: [1×1 struct]
label: {129×1 cell}
time: {[1×245726 double]}
trial: {[129×245726 double]}
fsample: 1000
sampleinfo: [1 245726]
elec: [1×1 struct]
cfg: [1×1 struct]
1) B. cfg for resampling data (I’m using all the default options for resampling):
Cfg=[];
[data_eeg] = ft_resampledata(cfg, data_eeg); % defaults are all OK
2) A. data structure for artifact rejection (my data already epoched):
data_eeg =
struct with fields:
hdr: [1×1 struct]
label: {129×1 cell}
time: {1×108 cell}
trial: {1×108 cell}
fsample: 1000
sampleinfo: [108×2 double]
elec: [1×1 struct]
cfg: [1×1 struct]
2) B. cfg for artifact rejection (taken from the automatic artifact rejection example):
% jump
cfg = [];
cfg.trl = trl;
cfg.datafile = '100_1_20200305.mff';
cfg.headerfile = '100_1_20200305.mff';
cfg.continuous = 'yes';
% channel selection, cutoff and padding
cfg.artfctdef.zvalue.channel = 'EEG';
cfg.artfctdef.zvalue.cutoff = 20;
cfg.artfctdef.zvalue.trlpadding = 0;
cfg.artfctdef.zvalue.artpadding = 0;
cfg.artfctdef.zvalue.fltpadding = 0;
% algorithmic parameters
cfg.artfctdef.zvalue.cumulative = 'yes';
cfg.artfctdef.zvalue.medianfilter = 'yes';
cfg.artfctdef.zvalue.medianfiltord = 9;
cfg.artfctdef.zvalue.absdiff = 'yes';
% make the process interactive
cfg.artfctdef.zvalue.interactive = 'yes';
[cfg, artifact_jump] = ft_artifact_zvalue(cfg); %plot error and error using zeros
%[cfg, artifact_jump] = ft_artifact_zvalue(cfg, data_eeg); %no plot error, but each trial has the same graph, also error using zeros
Kind regards,
Gaëlle Leys
-----Original Message-----
From: fieldtrip <fieldtrip-bounces at science.ru.nl<mailto:fieldtrip-bounces at science.ru.nl>> On Behalf Of fieldtrip-request at science.ru.nl<mailto:fieldtrip-request at science.ru.nl>
Sent: zaterdag 20 juni 2020 12:00
To: fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>
Subject: fieldtrip Digest, Vol 115, Issue 22
Send fieldtrip mailing list submissions to
fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>
To subscribe or unsubscribe via the World Wide Web, visit
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
or, via email, send a message with subject or body 'help' to
fieldtrip-request at science.ru.nl<mailto:fieldtrip-request at science.ru.nl>
You can reach the person managing the list at
fieldtrip-owner at science.ru.nl<mailto:fieldtrip-owner at science.ru.nl>
When replying, please edit your Subject line so it is more specific than "Re: Contents of fieldtrip digest..."
Today's Topics:
1. Errors with downsampling and artifact rejection (Gaëlle Leys)
2. Re: Errors with downsampling and artifact rejection
(Stephen Whitmarsh)
3. MNI coordinates for the EEG easycap-M1 layout
(SILVA PEREIRA, SILVANA)
----------------------------------------------------------------------
Message: 1
Date: Fri, 19 Jun 2020 12:48:26 +0000
From: Gaëlle Leys <gaelle.leys at kuleuven.be<mailto:gaelle.leys at kuleuven.be>>
To: "fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>" <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>>
Subject: [FieldTrip] Errors with downsampling and artifact rejection
Message-ID:
<ccb89b4d31af42d3b4cd22485438f4ef at ICTS-S-EXMBX17.luna.kuleuven.be<mailto:ccb89b4d31af42d3b4cd22485438f4ef at ICTS-S-EXMBX17.luna.kuleuven.be>>
Content-Type: text/plain; charset="iso-8859-1"
Dear Fieldtrip community,
I have recently started with Fieldtrip for my EEG data processing and I am encountering some problems which I can't seem to resolve.
I'm working with mff files from an EGI EEG system. I have no problem reading in and preprocessing the data. However, when trying to downsample and setup the automatic artifact removal, I'm getting some errors.
1) When trying to downsample with the default options, these are the errors that I get:
Error using resample>getSamples (line 357) The number of elements of Tx must match the number of rows of X when X is a matrix
Error in resample>nonUniformResample (line 123) [x, tx] = getSamples(varargin{1:2});
Error in resample (line 116)
[varargout{1:max(1,nargout)}] = nonUniformResample(method,varargin{:});
Error in ft_resampledata (line 228)
newdat = transpose(resample(transpose(olddat),fsres,fsorig));
I have tried downsampling before filtering, after filtering, on continuous data, or already segmented data. None of these things seem to resolve the error.
2) When trying to set up the automatic artifact removal process and choosing yes for the interactive plot, I get a plotting error:
Error using plot
Vectors must be the same length.
Error in ft_artifact_zvalue>redraw_cb (line 973)
plot(opt.h1, xval, yval, 'linestyle', '-', 'color', 'b', 'displayname', 'data');
Error in ft_artifact_zvalue (line 512)
redraw_cb(h);
I've noticed that the xval and yval are different numbers, which of course doesn't allow plotting. It seems like the xval changes according to the epoch length, however the yval remains the same and equals the amount of samples in my continuous data.
3) When choosing no for the interactive plot, I also get an error:
Error using zeros
Size inputs must be integers.
Error in ft_artifact_zvalue (line 568)
dum = zeros(1,max(opt.trl(:,2)));
I've been looking into the functions and where it goes wrong, but I can't seem to pinpoint what exactly is causing these issues. Anyone here that can help or provide me some tips?
Thanks in advance!
Kind regards,
Gaëlle Leys
Research Associate
Brain & Cognition
Tiensestraat 102 box 3714
3000 Leuven
Room PSI 02.33
tel. +32 16 37 61 98
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20200619/e7e1bde8/attachment-0001.htm>
------------------------------
Message: 2
Date: Fri, 19 Jun 2020 15:08:21 +0200
From: Stephen Whitmarsh <stephen.whitmarsh at gmail.com<mailto:stephen.whitmarsh at gmail.com>>
To: FieldTrip discussion list <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>>
Subject: Re: [FieldTrip] Errors with downsampling and artifact
rejection
Message-ID:
<CAFrxm=w44QZ0C7xB4cpsqdy0D0ou5UcpHNM-q3bjyaqwwJxRwg at mail.gmail.com<mailto:w44QZ0C7xB4cpsqdy0D0ou5UcpHNM-q3bjyaqwwJxRwg at mail.gmail.com>>
Content-Type: text/plain; charset="utf-8"
Dear Gaëlle,
To understand the problem it would be helpful to have 1) description of the data structures going in ft_resampledata (just type in command line and copy-paste the output) and the artefact detection function you are using, and 2) the configuration (cfg) you are using for those functions.
Cheers,
Stephen
Op vr 19 jun. 2020 om 14:56 schreef Gaëlle Leys <gaelle.leys at kuleuven.be<mailto:gaelle.leys at kuleuven.be>>:
> Dear Fieldtrip community,
>
>
>
> I have recently started with Fieldtrip for my EEG data processing and
> I am encountering some problems which I can’t seem to resolve.
>
> I’m working with mff files from an EGI EEG system. I have no problem
> reading in and preprocessing the data. However, when trying to
> downsample and setup the automatic artifact removal, I’m getting some errors.
>
>
>
> 1) When trying to downsample with the default options, these are the
> errors that I get:
>
> Error using resample>getSamples (line 357)
>
> The number of elements of Tx must match the number of rows of X when X
> is a matrix
>
>
>
> Error in resample>nonUniformResample (line 123)
>
> [x, tx] = getSamples(varargin{1:2});
>
>
>
> Error in resample (line 116)
>
> [varargout{1:max(1,nargout)}] =
> nonUniformResample(method,varargin{:});
>
>
>
> Error in ft_resampledata (line 228)
>
> newdat = transpose(resample(transpose(olddat),fsres,fsorig));
>
>
>
> I have tried downsampling before filtering, after
> filtering, on continuous data, or already segmented data. None of
> these things seem to resolve the error.
>
>
>
> 2) When trying to set up the automatic artifact removal process and
> choosing yes for the interactive plot, I get a plotting error:
>
> Error using plot
>
> Vectors must be the same length.
>
>
>
> Error in ft_artifact_zvalue>redraw_cb (line 973)
>
> plot(opt.h1, xval, yval, 'linestyle', '-', 'color', 'b',
> 'displayname', 'data');
>
>
>
> Error in ft_artifact_zvalue (line 512)
>
> redraw_cb(h);
>
>
>
> I’ve noticed that the xval and yval are different numbers,
> which of course doesn’t allow plotting. It seems like the xval changes
> according to the epoch length, however the yval remains the same and
> equals the amount of samples in my continuous data.
>
>
>
> 3) When choosing no for the interactive plot, I also get an error:
>
> Error using zeros
>
> Size inputs must be integers.
>
>
>
> Error in ft_artifact_zvalue (line 568)
>
> dum = zeros(1,max(opt.trl(:,2)));
>
>
>
> I’ve been looking into the functions and where it goes wrong, but I
> can’t seem to pinpoint what exactly is causing these issues. Anyone
> here that can help or provide me some tips?
>
>
>
> Thanks in advance!
>
>
>
> Kind regards,
>
>
>
> Gaëlle Leys
>
>
>
> Research Associate
> Brain & Cognition
> Tiensestraat 102 box 3714
> 3000 Leuven
>
> Room PSI 02.33
> tel. +32 16 37 61 98
>
>
> _______________________________________________
> fieldtrip mailing list
> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
> https://doi.org/10.1371/journal.pcbi.1002202
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20200619/137e31b1/attachment-0001.htm>
------------------------------
Message: 3
Date: Fri, 19 Jun 2020 18:58:36 +0200
From: "SILVA PEREIRA, SILVANA" <silvana.silva at upf.edu<mailto:silvana.silva at upf.edu>>
To: fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>
Subject: [FieldTrip] MNI coordinates for the EEG easycap-M1 layout
Message-ID:
<CA+_MWm1NufDWa-fjR71OzQ5ab88ioyUT8OJ-QFYX9ABr7gNQrA at mail.gmail.com<mailto:CA%2B_MWm1NufDWa-fjR71OzQ5ab88ioyUT8OJ-QFYX9ABr7gNQrA at mail.gmail.com>>
Content-Type: text/plain; charset="utf-8"
Dear community,
I've been struggling to find the 3D positions (montages) for the
Acticap-64ch-standard2 on the web, which is a modified version of the easycap-M1, but I have not succeeded. In the Fieldtrip page http://www.fieldtriptoolbox.org/template/electrode/ you have the following:
You can find the template 3-D electrode sets included in FieldTrip here <https://github.com/fieldtrip/fieldtrip/tree/master/template/electrode>.
But in that link you only find a txt file with theta-phi coordinates (easycap-M1.txt). Is there any place where I could find these positions in MNI space?
Thank you and best regards,
Silvana
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20200619/c0adf7df/attachment-0001.htm>
------------------------------
Subject: Digest Footer
_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202
------------------------------
End of fieldtrip Digest, Vol 115, Issue 22
******************************************
_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202
_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20200623/62aa978f/attachment.htm>
More information about the fieldtrip
mailing list