[FieldTrip] Issue with partial artifact rejection in sleep EEG data visualization

Schoffelen, J.M. (Jan Mathijs) janmathijs.schoffelen at donders.ru.nl
Tue Jun 25 07:34:27 CEST 2024


Hi Sophie,

If I understand the context of your question well, I think that the answer to the question "how to seamlessly visualize the cleaned data after partial artifact rejection?” is: “this is not recommended (and although it may be possible by creatively applying some fieldtrip code in combination with some out-of-the-box matlab, I am not going to tell you how to do it. Het brengt je alleen maar op slechte ideeën)”.

The whole rationale of rejecting the segments of data with artifacts, is to kick them out of the data object altogether, so that they do not contaminate the downstream analysis steps anymore. In doing so, ft_rejectartifact preserves the data’s original time axis, as well as the metadata (trialinfo) pertaining to the individual epochs (e.g. concretely, if an artifact occurs in the middle of an epoch, the given epoch is split into two sub-epochs, each with their own (consistent with the original) time axis, and each with the original epoch’s metadata duplicated). This indeed has consequences for the visualization of the data, because the artifacts appear as gaps. This is explicitly by design. From the context in your message you seem to want to somehow ’stitch together’ the data samples occurring at each side of the gap. Although this may be technically feasible with some matlab voodoo, I would recommend against it. The temporal discontinuity should be preserved for your own sake. If - within a putatively stitched together epoch - neighbouring data samples are derived from different parts of the original data, unwanted side effects will occur in the downstream processing, for instance with filtering, spectral transformation etc.

Best wishes,
Jan-Mathijs





On 24 Jun 2024, at 17:45, Schubert, E.S. (Sophie) via fieldtrip <fieldtrip at science.ru.nl> wrote:


Dear FieldTrip Support Team,

Currently, I am working with sleep EEG data and facing an issue with visualizing artifact-rejected data after employing partial rejection methods.

I have developed a custom script to define trials, which reads PSG signals from an EDF file and event annotations from a CSV file. This script calculates trial segments (trl) by specifying start and end points relative to event times, ensuring that each trial fits within the dataset's limits. The trl matrix records the start and end samples of each trial, along with its offset and associated event value. This precise trial definition is crucial for subsequent data analysis steps, including artifact rejection and sleep stage classification.

For artifact detection, I utilize automatic methods within FieldTrip to partially reject artifacts based on segments, specifically targeting EOG and EMG artifacts.The eog_artifacts.EOG_eye and combined_muscle_artifacts structures contain pairs of sample indices indicating the start and end of detected artifact segments, highlighting where artifacts were identified during the detection process.

I am able to visualize marked artifacts using the following code snippet:

%% Visualization of the signal with marked artifacts

cfg = [];

cfg.channel = 'all'; % All channels

cfg.viewmode = 'vertical'; % Or 'butterfly', depending on preference

cfg.artfctdef.eog.artifact = eog_artifacts_high.EOG_eye;

cfg.artfctdef.muscle.artifact = combined_muscle_artifacts;

ft_databrowser(cfg, data_segmented);

Here is a simplified version of the code snippet I use to reject artifact segments:

%% Reject artifacts partially within trials

cfg = [];

cfg.artfctdef.reject = 'partial'; % Partial rejection within trials

cfg.artfctdef.eog.artifact = eog_artifacts.EOG_eye; % EOG artifacts

cfg.artfctdef.muscle.artifact = combined_muscle_artifacts; % Combined muscle artifacts



data_clean_artifactfree = ft_rejectartifact(cfg, data_segmented);



cfg = [];

cfg.channel = 'all'; % All channels

cfg.viewmode = 'vertical'; % Visualization mode

ft_databrowser(cfg, data_clean_artifactfree);

During artifact rejection using ft_rejectartifact, I encounter the following warning messages: "The input is raw data with 14 channels and 1 trial. Warning: Original data has trialinfo, using user-specified trialinfo instead. Warning: correcting numerical inaccuracy in the time axes". Despite these warnings, the artifact rejection process completes successfully. However, when attempting to visualize the cleaned data (second part of the code), I observe fragmented signals where rejected artifact segments are displayed as white spaces, indicating signal removal. This fragmentation makes it challenging to assess the artifact-free data as a continuous signal and to detect any discontinuities or abrupt transitions in the data.

Ultimately, my objective is to use ft_redefinetrial to concatenate segments and visualize the entire continuous signal (while preserving the event markers – so that the information about the sleep stages is still accessible). Could you please provide guidance on how to seamlessly visualize the cleaned data after partial artifact rejection? Specifically, I would appreciate insights into any additional parameters or configurations that might be necessary to achieve a continuous visualization of the artifact-free EEG signal, ensuring proper data handling and analysis.

Thank you in advance for your assistance.

Best 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.

_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmailman.science.ru.nl%2Fmailman%2Flistinfo%2Ffieldtrip&data=05%7C02%7Cfieldtrip%40science.ru.nl%7C084b3e88b2c74bf55ce208dc94d87ab4%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638548904687597859%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=lBwSOWQDMBnyMi%2BcGJZnaR8FNv04e2GMg2BcZvbi%2F80%3D&reserved=0>
https://doi.org/10.1371/journal.pcbi.1002202<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdoi.org%2F10.1371%2Fjournal.pcbi.1002202&data=05%7C02%7Cfieldtrip%40science.ru.nl%7C084b3e88b2c74bf55ce208dc94d87ab4%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638548904687597859%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=d8NTpBfGLPv6kQkrnxie7t6oUIFhL7AICR4CxEQpoxY%3D&reserved=0>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20240625/d1f92254/attachment.htm>


More information about the fieldtrip mailing list