[FieldTrip] Issue with NaN values using ft_artifact_zvalue

Konstantinos Tsilimparis konstantinos.tsilimparis at outlook.com
Thu Jul 4 14:34:04 CEST 2024


Dear Sophie,
You have correctly identified that the error arises from the filter padding process. From my experience, if there are gaps (i.e., no available data points) between your trials, this will lead to NaN values during filter padding. While I am not fully aware of your data preprocessing and trial selection methods that leads to the data_segment, it believe that your trials have gaps in between. For instance, inspecting data_segment.samplenfo might reveal that the trials do not consist of continuous, uncut segments.
One option is to set the filter padding to 0, but this won't take care of the filter-induced edge effects. Another option is to go back in your analysis and change the way you segment your data. When you split your data into trials do not leave any gaps between trials. For example, split your signal in 30 seconds trials without gaps in between. Or if you leave gaps between trials, make sure to keep 0.1 sec more in the beginning and the end of each trial for cfg.artfctdef.zvalue.fltpadding = 0.1 to work properly.

Best regards,
Konstantinos Tsilimparis

From: fieldtrip <fieldtrip-bounces at science.ru.nl> On Behalf Of Schubert, E.S. (Sophie) via fieldtrip
Sent: Wednesday, July 3, 2024 4:14 PM
To: fieldtrip at science.ru.nl
Cc: Schubert, E.S. (Sophie) <E.S.Schubert at umcutrecht.nl>
Subject: [FieldTrip] Issue with NaN values using ft_artifact_zvalue

Dear FieldTrip Support Team,

I am writing to seek assistance with an issue I am encountering while using the ft_artifact_zvalue function in FieldTrip for artifact rejection. Despite my data containing no NaN values initially, I receive an error during the bandpass filtering process indicating that the input is expected to be finite.

Here is a detailed description of the problem:
searching for artifacts in 2 channels
Warning: data contains NaNs, not all processing methods are robust to NaNs, so the NaNs
might spread
Warning: data contains NaN values
Error using filtfilt>efiltfilt
Error using filtfilt
Expected input to be finite.

Error in filtfilt (line 102)
        y = efiltfilt(b,a,x);

Error in filter_with_correction (line 73)
    filt = filtfilt(B, A, dat')';

Error in ft_preproc_bandpassfilter (line 300)
    filt = filter_with_correction(B,A,dat,dir,usefftfilt);

Error in preproc (line 405)
if strcmp(cfg.bpfilter, 'yes'),     dat = ft_preproc_bandpassfilter(dat, fsample, cfg.bpfreq, cfg.bpfiltord, cfg.bpfilttype, cfg.bpfiltdir, cfg.bpinstabilityfix, cfg.bpfiltdf, cfg.bpfiltwintype, cfg.bpfiltdev, cfg.plotfiltresp, cfg.usefftfilt); end

Error in ft_artifact_zvalue (line 315)
  thisdat = preproc(thisdat, cfg.artfctdef.zvalue.channel, offset2time(0, hdr.Fs, size(thisdat,2)), cfg.artfctdef.zvalue, fltpadding, fltpadding);

The code that I use:
frontalEye = {'EOG LOC-A2', 'EOG ROC-A2'}; % for artifact rejection
cfg = [];
cfg.artfctdef.zvalue.channel = frontalEye;
cfg.artfctdef.zvalue.cutoff = 2.5;
cfg.artfctdef.zvalue.trlpadding = 0;
cfg.artfctdef.zvalue.artpadding = 0.4;
cfg.artfctdef.zvalue.fltpadding = 0.1;
cfg.artfctdef.zvalue.bpfilter = 'yes';
cfg.artfctdef.zvalue.bpfreq = [0.5 2];
cfg.artfctdef.zvalue.bpfiltord = 4;
cfg.artfctdef.zvalue.bpfilttype = 'but';
cfg.artfctdef.zvalue.hilbert = 'yes';
cfg.artfctdef.zvalue.interactive = 'no';
[cfg, artifact_EOG_eye] = ft_artifact_zvalue(cfg, data_segmented);

Important notes:

  1.  I have checked and verified that the data does not contain any NaN values before the filtering process.
  2.  I have tried different configurations, including setting the padding to 0, which prevents the error

It appears that NaN values are being introduced during the filtering process, but I am unable to determine the cause. I understand that the filterpadding specifies how much extra data around each trial's segment is read from the file. This extra data (padding) is used to mitigate edge artifacts that can occur after applying filters to the data. However, given the encountered error, I am uncertain if I am utilizing this function correctly. Could you please provide guidance on how to resolve this issue?

Thank you for your support!

Kind regards,

Sophie Schubert

________________________________

De informatie opgenomen in dit bericht kan vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onterecht ontvangt, wordt u verzocht de inhoud niet te gebruiken en de afzender direct te informeren door het bericht te retourneren. Het Universitair Medisch Centrum Utrecht is een publiekrechtelijke rechtspersoon in de zin van de W.H.W. (Wet Hoger Onderwijs en Wetenschappelijk Onderzoek) en staat geregistreerd bij de Kamer van Koophandel voor Midden-Nederland onder nr. 30244197.

Denk s.v.p aan het milieu voor u deze e-mail afdrukt.

________________________________

This message may contain confidential information and is intended exclusively for the addressee. If you receive this message unintentionally, please do not use the contents but notify the sender immediately by return e-mail. University Medical Center Utrecht is a legal person by public law and is registered at the Chamber of Commerce for Midden-Nederland under no. 30244197.

Please consider the environment before printing this e-mail.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20240704/12523939/attachment.htm>


More information about the fieldtrip mailing list