<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:Helvetica;
        panose-1:0 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Aptos;
        panose-1:2 11 0 4 2 2 2 2 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:12.0pt;
        font-family:"Aptos",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
code
        {mso-style-priority:99;
        font-family:"Courier New";}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML - vooraf opgemaakt Char";
        margin:0cm;
        font-size:10.0pt;
        font-family:"Courier New";}
span.apple-converted-space
        {mso-style-name:apple-converted-space;}
span.HTML-voorafopgemaaktChar
        {mso-style-name:"HTML - vooraf opgemaakt Char";
        mso-style-priority:99;
        mso-style-link:"HTML - vooraf opgemaakt";
        font-family:Consolas;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        mso-ligatures:none;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="NL" link="blue" vlink="purple" style="word-wrap:break-word;line-break:after-white-space">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">Dear Jan-Mathijs,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">Thank you for your response and the detailed explanation. I understand your point about the importance of preserving the temporal discontinuity in the data after artifact
 rejection. Given this, I will focus on working with the artifact-free segments as they are, without attempting to stitch them together for visualization purposes.
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">I still had a question to the warnings I encountered during artifact rejection using ft_rejectartifact: "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." Could you please help me understand the implications of these warnings? Do they indicate a potential issue that needs to be resolved,
 or are they more informational and do not affect the integrity of the preprocessing steps?
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">Thank you in advance!<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">Kind regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">Sophie<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div id="mail-editor-reference-message-container">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="color:black">Van:
</span></b><span style="color:black">fieldtrip <fieldtrip-bounces@science.ru.nl> namens Schoffelen, J.M. (Jan Mathijs) via fieldtrip <fieldtrip@science.ru.nl><br>
<b>Datum: </b>dinsdag, 25 juni 2024 om 07:38<br>
<b>Aan: </b>FieldTrip discussion list <fieldtrip@science.ru.nl><br>
<b>CC: </b>Schoffelen, J.M. (Jan Mathijs) <janmathijs.schoffelen@donders.ru.nl><br>
<b>Onderwerp: </b>Re: [FieldTrip] Issue with partial artifact rejection in sleep EEG data visualization<o:p></o:p></span></p>
</div>
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" align="left" width="100%" style="width:100.0%;display:table;border-collapse:seperate;float:none">
<tbody>
<tr>
<td style="background:#A6A6A6;padding:5.25pt 1.5pt 5.25pt 1.5pt"></td>
<td width="100%" style="width:100.0%;background:#EAEAEA;padding:5.25pt 3.75pt 5.25pt 11.25pt">
<div>
<p class="MsoNormal" style="mso-element:frame;mso-element-frame-hspace:2.25pt;mso-element-wrap:around;mso-element-anchor-vertical:paragraph;mso-element-anchor-horizontal:column;mso-height-rule:exactly">
<span style="font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#212121">You don't often get email from fieldtrip@science.ru.nl.
<a href="https://aka.ms/LearnAboutSenderIdentification">Learn why this is important</a><o:p></o:p></span></p>
</div>
</td>
<td width="75" style="width:56.25pt;background:#EAEAEA;padding:5.25pt 3.75pt 5.25pt 3.75pt">
</td>
</tr>
</tbody>
</table>
<div>
<p class="MsoNormal">Hi Sophie, <o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">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)”. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">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. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Best wishes,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Jan-Mathijs<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On 24 Jun 2024, at 17:45, Schubert, E.S. (Sophie) via fieldtrip <fieldtrip@science.ru.nl> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p><span lang="EN-US" style="font-size:10.5pt;font-family:Helvetica">Dear FieldTrip Support Team,</span><span style="font-size:10.5pt;font-family:Helvetica"><o:p></o:p></span></p>
<p style="font-variant-caps:normal;text-align:start;word-spacing:0px"><span lang="EN-US" style="font-size:10.5pt;font-family:Helvetica">Currently, I am working with sleep EEG data and facing an issue with visualizing artifact-rejected data after employing partial
 rejection methods.</span><span style="font-size:10.5pt;font-family:Helvetica"><o:p></o:p></span></p>
<p style="font-variant-caps:normal;text-align:start;word-spacing:0px"><span lang="EN-US" style="font-size:10.5pt;font-family:Helvetica">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.</span><span style="font-size:10.5pt;font-family:Helvetica"><o:p></o:p></span></p>
<p style="font-variant-caps:normal;text-align:start;word-spacing:0px"><span lang="EN-US" style="font-size:10.5pt;font-family:Helvetica">For artifact detection, I utilize automatic methods within FieldTrip to partially reject artifacts based on segments, specifically
 targeting EOG and EMG artifacts.The<span class="apple-converted-space"> </span></span><code><span lang="EN-US" style="font-size:10.0pt;font-family:"Aptos",sans-serif">eog_artifacts.EOG_eye</span></code><span class="apple-converted-space"><span lang="EN-US" style="font-size:10.5pt;font-family:Helvetica"> </span></span><span lang="EN-US" style="font-size:10.5pt;font-family:Helvetica">and<span class="apple-converted-space"> </span></span><code><span lang="EN-US" style="font-size:10.0pt;font-family:"Aptos",sans-serif">combined_muscle_artifacts</span></code><span class="apple-converted-space"><span lang="EN-US" style="font-size:10.0pt"> </span></span><span lang="EN-US" style="font-size:10.5pt;font-family:Helvetica">structures
 contain<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.</span><span style="font-size:10.5pt;font-family:Helvetica"><o:p></o:p></span></p>
<p style="font-variant-caps:normal;text-align:start;word-spacing:0px"><span lang="EN-US" style="font-size:10.5pt;font-family:Helvetica">I am able to visualize marked artifacts using the following code snippet:</span><span style="font-size:10.5pt;font-family:Helvetica"><o:p></o:p></span></p>
<pre style="font-variant-caps:normal;text-align:start;word-spacing:0px"><code><span lang="EN-US">%% Visualization of the signal with marked artifacts </span></code><o:p></o:p></pre>
<pre><code><span lang="EN-US">cfg = [];</span></code><o:p></o:p></pre>
<pre><code><span lang="EN-US">cfg.channel = 'all'; % All channels</span></code><o:p></o:p></pre>
<pre><code><span lang="EN-US">cfg.viewmode = 'vertical'; % Or 'butterfly', depending on preference</span></code><o:p></o:p></pre>
<pre><code><span lang="EN-US">cfg.artfctdef.eog.artifact = eog_artifacts_high.EOG_eye;</span></code><o:p></o:p></pre>
<pre><code><span lang="EN-US">cfg.artfctdef.muscle.artifact = combined_muscle_artifacts;</span></code><o:p></o:p></pre>
<pre><code><span lang="EN-US">ft_databrowser(cfg, data_segmented);</span></code><o:p></o:p></pre>
<p style="font-variant-caps:normal;text-align:start;word-spacing:0px"><span lang="EN-US" style="font-size:10.5pt;font-family:Helvetica">Here is a simplified version of the code snippet I use to reject artifact segments:</span><span style="font-size:10.5pt;font-family:Helvetica"><o:p></o:p></span></p>
<pre style="font-variant-caps:normal;text-align:start;word-spacing:0px"><code><span lang="EN-US">%% Reject artifacts partially within trials</span></code><o:p></o:p></pre>
<pre><code><span lang="EN-US">cfg = [];</span></code><o:p></o:p></pre>
<pre><code><span lang="EN-US">cfg.artfctdef.reject = 'partial'; % Partial rejection within trials</span></code><o:p></o:p></pre>
<pre><code><span lang="EN-US">cfg.artfctdef.eog.artifact = eog_artifacts.EOG_eye; % EOG artifacts</span></code><o:p></o:p></pre>
<pre><code><span lang="EN-US">cfg.artfctdef.muscle.artifact = combined_muscle_artifacts; % Combined muscle artifacts</span></code><o:p></o:p></pre>
<pre><code><span lang="EN-US"> </span></code><o:p></o:p></pre>
<pre><code><span lang="EN-US">data_clean_artifactfree = ft_rejectartifact(cfg, data_segmented);</span></code><o:p></o:p></pre>
<pre><code><span lang="EN-US"> </span></code><o:p></o:p></pre>
<pre><code><span lang="EN-US">cfg = [];</span></code><o:p></o:p></pre>
<pre><code><span lang="EN-US">cfg.channel = 'all'; % All channels</span></code><o:p></o:p></pre>
<pre><code><span lang="EN-US">cfg.viewmode = 'vertical'; % Visualization mode</span></code><o:p></o:p></pre>
<pre><code><span lang="EN-US">ft_databrowser(cfg, data_clean_artifactfree);</span></code><o:p></o:p></pre>
<p style="font-variant-caps:normal;text-align:start;word-spacing:0px"><span lang="EN-US" style="font-size:10.5pt;font-family:Helvetica">During artifact rejection<span class="apple-converted-space"> </span>using<span class="apple-converted-space"> </span></span><code><span lang="EN-US" style="font-size:10.0pt;font-family:"Aptos",sans-serif">ft_rejectartifact</span></code><span lang="EN-US" style="font-size:10.5pt;font-family:Helvetica">,
 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.</span><span style="font-size:10.5pt;font-family:Helvetica"><o:p></o:p></span></p>
<p style="font-variant-caps:normal;text-align:start;word-spacing:0px"><span lang="EN-US" style="font-size:10.5pt;font-family:Helvetica">Ultimately,<span class="apple-converted-space"> </span>my objective is to use<span class="apple-converted-space"> </span></span><code><span lang="EN-US" style="font-size:10.0pt;font-family:"Aptos",sans-serif">ft_redefinetrial</span></code><span class="apple-converted-space"><span lang="EN-US" style="font-size:10.5pt;font-family:Helvetica"> </span></span><span lang="EN-US" style="font-size:10.5pt;font-family:Helvetica">to
 concatenate<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.</span><span style="font-size:10.5pt;font-family:Helvetica"><o:p></o:p></span></p>
<p style="font-variant-caps:normal;text-align:start;word-spacing:0px"><span lang="EN-US" style="font-size:10.5pt;font-family:Helvetica">Thank you in advance for your assistance.</span><span style="font-size:10.5pt;font-family:Helvetica"><o:p></o:p></span></p>
<p style="font-variant-caps:normal;text-align:start;word-spacing:0px"><span style="font-size:10.5pt;font-family:Helvetica">Best regards,<o:p></o:p></span></p>
<p style="font-variant-caps:normal;text-align:start;word-spacing:0px"><span style="font-size:10.5pt;font-family:Helvetica">Sophie Schubert<o:p></o:p></span></p>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"> <o:p></o:p></span></p>
</div>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="0" width="100%" align="center">
</div>
<p style="font-variant-caps:normal;text-align:start;word-spacing:0px"><i><span style="font-size:7.5pt;font-family:"Arial",sans-serif">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.</span></i><span style="font-size:10.5pt;font-family:Helvetica"><o:p></o:p></span></p>
<p style="font-variant-caps:normal;text-align:start;word-spacing:0px"><i><span style="font-size:7.5pt;font-family:"Arial",sans-serif;color:green">Denk s.v.p aan het milieu voor u deze e-mail afdrukt.</span></i><span style="font-size:10.5pt;font-family:Helvetica"><o:p></o:p></span></p>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="0" width="100%" align="center">
</div>
<p style="font-variant-caps:normal;text-align:start;word-spacing:0px"><i><span style="font-size:7.5pt;font-family:"Arial",sans-serif">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.</span></i><span style="font-size:10.5pt;font-family:Helvetica"><o:p></o:p></span></p>
<p style="font-variant-caps:normal;text-align:start;word-spacing:0px"><i><span style="font-size:7.5pt;font-family:"Arial",sans-serif;color:green">Please consider the environment before printing this e-mail.</span></i><span style="font-size:10.5pt;font-family:Helvetica"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.5pt;font-family:Helvetica">_______________________________________________<br>
fieldtrip mailing list<br>
</span><a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip"><span style="font-size:10.5pt;font-family:Helvetica">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</span></a><span style="font-size:10.5pt;font-family:Helvetica"><br>
</span><a href="https://doi.org/10.1371/journal.pcbi.1002202"><span style="font-size:10.5pt;font-family:Helvetica">https://doi.org/10.1371/journal.pcbi.1002202</span></a><o:p></o:p></p>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>