<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
Hi Sophie,
<div><br>
</div>
<div>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)”. </div>
<div><br>
</div>
<div>The whole rationale of <i>rejecting</i> 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. </div>
<div><br>
</div>
<div>Best wishes,</div>
<div>Jan-Mathijs</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>
<div>
<blockquote type="cite">
<div>On 24 Jun 2024, at 17:45, Schubert, E.S. (Sophie) via fieldtrip <fieldtrip@science.ru.nl> wrote:</div>
<br class="Apple-interchange-newline">
<div>
<div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">
<p><span lang="EN-US" style="">Dear FieldTrip Support Team,<o:p></o:p></span></p>
<p style="caret-color: rgb(0, 0, 0); font-variant-caps: normal; text-align: start; -webkit-text-stroke-width: 0px; word-spacing: 0px;">
<span lang="EN-US" style="">Currently, I am working with sleep EEG data and facing an issue with visualizing artifact-rejected data after employing partial rejection methods.<o:p></o:p></span></p>
<p style="caret-color: rgb(0, 0, 0); font-variant-caps: normal; text-align: start; -webkit-text-stroke-width: 0px; word-spacing: 0px;">
<span lang="EN-US" style="">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.<o:p></o:p></span></p>
<p style="caret-color: rgb(0, 0, 0); font-variant-caps: normal; text-align: start; -webkit-text-stroke-width: 0px; word-spacing: 0px;">
<span lang="EN-US" style="">For artifact detection, I utilize automatic methods within FieldTrip to partially reject artifacts based on segments, specifically targeting EOG and EMG artifacts.</span><span lang="EN-US" style="">The</span><span class="apple-converted-space"><span lang="EN-US" style=""> </span></span><code style="font-family: "Courier New";"><span lang="EN-US" style="font-family: Aptos, sans-serif;">eog_artifacts.EOG_eye</span></code><span class="apple-converted-space"><span lang="EN-US" style=""> </span></span><span lang="EN-US" style="">and</span><span class="apple-converted-space"><span lang="EN-US" style=""> </span></span><code style="font-family: "Courier New";"><span lang="EN-US" style="font-family: Aptos, sans-serif;">combined_muscle_artifacts<span class="Apple-converted-space"> </span></span></code><span lang="EN-US" style="">structures
 contain</span><span lang="EN-US" style=""><span class="Apple-converted-space"> </span>pairs of sample indices indicating the start and end of detected artifact segments, highlighting where artifacts were identified during the detection process.<o:p></o:p></span></p>
<p style="caret-color: rgb(0, 0, 0); font-variant-caps: normal; text-align: start; -webkit-text-stroke-width: 0px; word-spacing: 0px;">
<span lang="EN-US" style="">I am able to visualize marked artifacts using the following code snippet:<o:p></o:p></span></p>
<pre style="margin: 0cm; font-size: 10pt; font-family: "Courier New"; caret-color: rgb(0, 0, 0); font-variant-caps: normal; text-align: start; -webkit-text-stroke-width: 0px; word-spacing: 0px;"><code style="font-family: "Courier New";"><span lang="EN-US" style="">%% Visualization of the signal with marked artifacts <o:p></o:p></span></code></pre>
<pre style="margin: 0cm; font-size: 10pt; font-family: "Courier New";"><code style="font-family: "Courier New";"><span lang="EN-US" style="">cfg = [];<o:p></o:p></span></code></pre>
<pre style="margin: 0cm; font-size: 10pt; font-family: "Courier New";"><code style="font-family: "Courier New";"><span lang="EN-US" style="">cfg.channel = 'all'; % All channels<o:p></o:p></span></code></pre>
<pre style="margin: 0cm; font-size: 10pt; font-family: "Courier New";"><code style="font-family: "Courier New";"><span lang="EN-US" style="">cfg.viewmode = 'vertical'; % Or 'butterfly', depending on preference<o:p></o:p></span></code></pre>
<pre style="margin: 0cm; font-size: 10pt; font-family: "Courier New";"><code style="font-family: "Courier New";"><span lang="EN-US" style="">cfg.artfctdef.eog.artifact = eog_artifacts_high.EOG_eye;<o:p></o:p></span></code></pre>
<pre style="margin: 0cm; font-size: 10pt; font-family: "Courier New";"><code style="font-family: "Courier New";"><span lang="EN-US" style="">cfg.artfctdef.muscle.artifact = combined_muscle_artifacts;<o:p></o:p></span></code></pre>
<pre style="margin: 0cm; font-size: 10pt; font-family: "Courier New";"><code style="font-family: "Courier New";"><span lang="EN-US" style="">ft_databrowser(cfg, data_segmented);<o:p></o:p></span></code></pre>
<p style="caret-color: rgb(0, 0, 0); font-variant-caps: normal; text-align: start; -webkit-text-stroke-width: 0px; word-spacing: 0px;">
<span lang="EN-US" style="">Here is a simplified version of the code snippet I use to reject artifact segments:<o:p></o:p></span></p>
<pre style="margin: 0cm; font-size: 10pt; font-family: "Courier New"; caret-color: rgb(0, 0, 0); font-variant-caps: normal; text-align: start; -webkit-text-stroke-width: 0px; word-spacing: 0px;"><code style="font-family: "Courier New";"><span lang="EN-US" style="">%% Reject artifacts partially within trials<o:p></o:p></span></code></pre>
<pre style="margin: 0cm; font-size: 10pt; font-family: "Courier New";"><code style="font-family: "Courier New";"><span lang="EN-US" style="">cfg = [];<o:p></o:p></span></code></pre>
<pre style="margin: 0cm; font-size: 10pt; font-family: "Courier New";"><code style="font-family: "Courier New";"><span lang="EN-US" style="">cfg.artfctdef.reject = 'partial'; % Partial rejection within trials<o:p></o:p></span></code></pre>
<pre style="margin: 0cm; font-size: 10pt; font-family: "Courier New";"><code style="font-family: "Courier New";"><span lang="EN-US" style="">cfg.artfctdef.eog.artifact = eog_artifacts.EOG_eye; % EOG artifacts<o:p></o:p></span></code></pre>
<pre style="margin: 0cm; font-size: 10pt; font-family: "Courier New";"><code style="font-family: "Courier New";"><span lang="EN-US" style="">cfg.artfctdef.muscle.artifact = combined_muscle_artifacts; % Combined muscle artifacts<o:p></o:p></span></code></pre>
<pre style="margin: 0cm; font-size: 10pt; font-family: "Courier New";"><code style="font-family: "Courier New";"><span lang="EN-US" style=""><o:p> </o:p></span></code></pre>
<pre style="margin: 0cm; font-size: 10pt; font-family: "Courier New";"><code style="font-family: "Courier New";"><span lang="EN-US" style="">data_clean_artifactfree = ft_rejectartifact(cfg, data_segmented);<o:p></o:p></span></code></pre>
<pre style="margin: 0cm; font-size: 10pt; font-family: "Courier New";"><code style="font-family: "Courier New";"><span lang="EN-US" style=""><o:p> </o:p></span></code></pre>
<pre style="margin: 0cm; font-size: 10pt; font-family: "Courier New";"><code style="font-family: "Courier New";"><span lang="EN-US" style="">cfg = [];<o:p></o:p></span></code></pre>
<pre style="margin: 0cm; font-size: 10pt; font-family: "Courier New";"><code style="font-family: "Courier New";"><span lang="EN-US" style="">cfg.channel = 'all'; % All channels<o:p></o:p></span></code></pre>
<pre style="margin: 0cm; font-size: 10pt; font-family: "Courier New";"><code style="font-family: "Courier New";"><span lang="EN-US" style="">cfg.viewmode = 'vertical'; % Visualization mode<o:p></o:p></span></code></pre>
<pre style="margin: 0cm; font-size: 10pt; font-family: "Courier New";"><code style="font-family: "Courier New";"><span lang="EN-US" style="">ft_databrowser(cfg, data_clean_artifactfree);<o:p></o:p></span></code></pre>
<p style="caret-color: rgb(0, 0, 0); font-variant-caps: normal; text-align: start; -webkit-text-stroke-width: 0px; word-spacing: 0px;">
<span lang="EN-US" style="">During artifact rejection<span class="Apple-converted-space"> </span></span><span lang="EN-US" style="">using</span><span class="apple-converted-space"><span lang="EN-US" style=""> </span></span><code style="font-family: "Courier New";"><span lang="EN-US" style="font-family: Aptos, sans-serif;">ft_rejectartifact</span></code><span lang="EN-US" style="">,
 I encounter the following warning messages: "The input is raw data with 14 channels and 1 trial. Warning</span><span lang="EN-US" style="">: 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.<o:p></o:p></span></p>
<p style="caret-color: rgb(0, 0, 0); font-variant-caps: normal; text-align: start; -webkit-text-stroke-width: 0px; word-spacing: 0px;">
<span lang="EN-US" style="">Ultimately,<span class="Apple-converted-space"> </span></span><span lang="EN-US" style="">my objective is to use</span><span class="apple-converted-space"><span lang="EN-US" style=""> </span></span><code style="font-family: "Courier New";"><span lang="EN-US" style="font-family: Aptos, sans-serif;">ft_redefinetrial</span></code><span class="apple-converted-space"><span lang="EN-US" style=""> </span></span><span lang="EN-US" style="">to
 concatenate</span><span lang="EN-US" style=""><span class="Apple-converted-space"> </span>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.<o:p></o:p></span></p>
<p style="caret-color: rgb(0, 0, 0); font-variant-caps: normal; text-align: start; -webkit-text-stroke-width: 0px; word-spacing: 0px;">
<span lang="EN-US" style="">Thank you in advance for your assistance.<o:p></o:p></span></p>
<p style="caret-color: rgb(0, 0, 0); font-variant-caps: normal; text-align: start; -webkit-text-stroke-width: 0px; word-spacing: 0px;">
<span style="">Best regards,<o:p></o:p></span></p>
<p style="caret-color: rgb(0, 0, 0); font-variant-caps: normal; text-align: start; -webkit-text-stroke-width: 0px; word-spacing: 0px;">
<span style="">Sophie Schubert<o:p></o:p></span></p>
<div style="margin: 0cm; font-size: 11pt; font-family: Aptos, sans-serif;"><o:p> </o:p></div>
</div>
<hr style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">
<p style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">
<font size="-2" face="arial"><i>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.</i></font></p>
<p style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">
<font size="-2" face="arial" color="green"><i>Denk s.v.p aan het milieu voor u deze e-mail afdrukt.</i></font></p>
<hr style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">
<p style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">
<font size="-2" face="arial"><i>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.</i></font></p>
<p style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">
<font size="-2" face="arial" color="green"><i>Please consider the environment before printing this e-mail.</i></font></p>
<span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;">_______________________________________________</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">
<span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;">fieldtrip
 mailing list</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">
<a href="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" originalsrc="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" shash="qrlDAkLNznN9JEMfHLNTtmtKLzA0/IvIQNY7B2iK1Z2U7pPZ5KWkYaEyoWjPRQS4c9h54a2QdN58/3NIM7T9ZGWUvAGIURiyYmZQZFZ09/IQY+ySko5DhzztlFW4iTcmZkXtXPRMzql8h/SHF+BFMFxM2kCDR+8tTrGhHTLEjE4=" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">
<a href="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" originalsrc="https://doi.org/10.1371/journal.pcbi.1002202" shash="hnZCy+c60K8zz+QDxAKYniHLLsqijXIJbZyEWaf25pwJG+aOCtpQujHCx+5RYZf3en7OM3qAofQeUtv4a4aBWubFkm4gPDhkO3+RKRDtZo1MceXYxsulVyZT9/rhGVzeQ5G6bXkA4hUcATIhfdB7weIB2WOzudn0rmZpxq4PgUw=" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">https://doi.org/10.1371/journal.pcbi.1002202</a></div>
</blockquote>
</div>
<br>
</div>
</body>
</html>