<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof">
Dear Ivo, </div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof">
Thank you so much for your help!! </div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof">
As I just needed one of the two types of artifact rejection and your code applies both, I've also managed to create two separate loops, according to whether one wants to use either artifact rejection based on peak-to-peak or min/max thresholds. I've also added
 a few lines that store the number of rejected trials and which ones have been rejected into the new data5. I share the scrpit with you and the community, for the future and just in case you'll need it one day
<span id="��">�� </span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof">
<span><br>
</span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof">
<span>Thank you so much again for your script and patience!!</span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof">
<span><br>
</span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof">
all the best, </div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof">
<span>Ele</span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof">
<span>
<div class="rtcContent" style="padding:30px"><span class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal"><span><span style="color: rgb(0, 128, 19);">%% minimum and maximum threshold</span></span></span>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>chs_remaining = [1:19 21:28 31:65];   </span><span style="color: rgb(0, 128, 19);">% which channels to use for the cleaning, in our case this was 5th to 8th</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>rel_thrs_max = 50;</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>rel_thrs_min = -50;</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
</div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>excluded = [];  </span><span style="color: rgb(0, 128, 19);">% create a matrix where excluded trials are collected</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span style="color: rgb(14, 0, 255);">for </span><span>i = 1:size(clean_data.trial,2)  
</span><span style="color: rgb(0, 128, 19);">% we specify here that we are going through the trial indexes, i is defined as the number of trials</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>    dat = clean_data.trial{i}(chs_remaining,:);  </span><span style="color: rgb(0, 128, 19);">% we select the channels we want to clean from trial nr. i</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>    </span><span style="color: rgb(14, 0, 255);">if </span><span>(min(dat,[],</span><span style="color: rgb(167, 9, 245);">'all'</span><span>) <= rel_thrs_min) || (max(dat,[],</span><span style="color: rgb(167, 9, 245);">'all'</span><span>) >= rel_thrs_max)</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>        excluded = [excluded i];</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>    </span><span style="color: rgb(14, 0, 255);">end</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span style="color: rgb(14, 0, 255);">end</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
</div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>    cfg=[];</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>    cfg.trials = setdiff(1:size(clean_data.trial,2),excluded);</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>    data5=ft_redefinetrial(cfg,clean_data); </span><span style="color: rgb(0, 128, 19);">%with these three lines we can finally integrate our cleaning with the FieldTripian ft_redefinetrial :)</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>    data5.rejected=length(excluded);</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>    data5.rejectedidx=excluded;</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span style="color: rgb(0, 128, 19);">%% peak to peak     </span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>chs_remaining = [1:19 21:28 31:65];   </span><span style="color: rgb(0, 128, 19);">% which channels to use for the cleaning, in our case this was 5th to 8th</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>absolute_threshold = 100;</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
</div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>excluded = [];  </span><span style="color: rgb(0, 128, 19);">% create a matrix where excluded trials are collected</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span style="color: rgb(14, 0, 255);">for </span><span>i = 1:size(clean_data.trial, 2)  
</span><span style="color: rgb(0, 128, 19);">% we specify here that we are going through the trial indexes, i is defined as the number of trials</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>    dat = clean_data.trial{i}(chs_remaining, :);  </span><span style="color: rgb(0, 128, 19);">% we select the channels we want to clean from trial nr. i</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>    diff_val = max(dat, [], </span><span style="color: rgb(167, 9, 245);">'all'</span><span>) - min(dat, [],
</span><span style="color: rgb(167, 9, 245);">'all'</span><span>);</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>    </span><span style="color: rgb(14, 0, 255);">if </span><span>diff_val > absolute_threshold</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>        excluded = [excluded i];</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>    </span><span style="color: rgb(14, 0, 255);">end</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span style="color: rgb(14, 0, 255);">end</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
</div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>    cfg.trials = setdiff(1:size(clean_data.trial,2),excluded);</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>    data5=ft_redefinetrial(cfg,clean_data); </span><span style="color: rgb(0, 128, 19);">%with these three lines we can finally integrate our cleaning with the FieldTripian ft_redefinetrial :)</span></span></div>
<div class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal">
<span><span>    data5.rejected=length(excluded);</span></span></div>
<span class="lineNode" style="font-size:10pt;font-family:Menlo, Monaco, Consolas, "Courier New", monospace;font-weight:normal"><span><span>    data5.rejectedidx=excluded;</span></span></span></div>
</span></div>
<div class="elementToProof">
<div id="Signature">
<div>
<div></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
<span style="margin: 0px; font-size: 16px; font-family: Calibri, Arial, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; text-align: start; background-color: white;"><font size="2" face="Calibri,Arial,Helvetica,sans-serif" style="color: rgb(117, 123, 128);"><span style="margin:0px"><b><font size="2" style="color: rgb(117, 123, 128);"><span style="margin:0px; font-size:11pt"><span style="margin: 0px; font-size: 13.31px; font-family: Calibri, sans-serif; color: rgb(222, 106, 25);">Eleonora
 Parrotta,  Doctoral Researcher in Social Neuroscience </span></span></font></b></span></font></span>
<div style="margin: 0px; font-size: 16px; font-family: Calibri, Arial, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; text-align: start; background-color: white;">
<span style="color: rgb(222, 106, 25);"></span><font size="2" face="Calibri,Arial,Helvetica,sans-serif" style="color: rgb(117, 123, 128);"><span style="margin:0px"><font size="2" style="color: rgb(117, 123, 128);"><span style="margin:0px; font-size:11pt"><span style="margin: 0px; font-size: 13.31px; font-family: Calibri, sans-serif; color: purple;">
<div style="margin:0px"><span style="margin: 0px; color: rgb(117, 123, 128);"><span style="margin: 0px; font-size: 13.32px; font-family: Calibri, Arial, Helvetica, sans-serif, serif, EmojiFont; color: rgb(51, 51, 51); background-color: white;">School of Psychology</span><span> </span>|
 University of Aberdeen | Aberdeen |<span> </span><span style="margin: 0px; font-size: 13.32px; font-family: Arial, sans-serif, serif, EmojiFont; color: rgb(51, 51, 51); background-color: white;">AB24 3FX</span></span></div>
<span style="margin:0px"><span style="margin: 0px; color: rgb(117, 123, 128);"><span style="margin: 0px; font-size: 13.32px; font-family: Arial, sans-serif, serif, EmojiFont; color: rgb(51, 51, 51); background-color: white;"><span style="margin: 0px; font-family: Calibri, Arial, Helvetica, sans-serif, serif, EmojiFont; background-color: white;"><span style="margin:0px">e.parrotta.20@abdn.ac.uk</span></span></span></span></span></span></span></font></span></font></div>
<br>
</div>
</div>
</div>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>Da:</b> Ivaylo Iotchev <ivaylo.iotchev@gmail.com><br>
<b>Inviato:</b> venerdě 26 maggio 2023 08:35<br>
<b>A:</b> eleonora parrotta <eleonora_p@hotmail.it><br>
<b>Cc:</b> FieldTrip discussion list <fieldtrip@science.ru.nl><br>
<b>Oggetto:</b> Re: [FieldTrip] automatic artifact rejection based on voltage threshold</font>
<div> </div>
</div>
<div>
<div dir="ltr">Absolute threshold is the one that uses a single threshold value, which you can determine yourself, but indeed 100 or 150 is common.<br>
<br>
The peak to peak based thresholding is what we refer to as relative threshold, thus the script applies both<br>
<br>
Does it help?<br>
<br>
Best wishes,<br>
<br>
Ivo</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">Am Fr., 26. Mai 2023 um 10:26 Uhr schrieb eleonora parrotta <<a href="mailto:eleonora_p@hotmail.it">eleonora_p@hotmail.it</a>>:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div class="x_msg-742472986805754733">
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
Dear Dr. Ivaylo (Ivo) Iotchev</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
<br>
<div>Thank you so much for sharing this!! May I ask you to clarify a few details about the code, please?</div>
<div>My questions are:</div>
<div>(a) Is this code supposed to eliminate trials based on a (1) peak-to-peak artifact rejection (2) based on the threshold voltage ?</div>
<div>Based on that, the voltage threshold would be different. For example, for the option (1) I would choose a voltage threshold that does not exceeds 100 microvolt (i.e., the difference between the maximum and minimum values) while for option (2) I would determine
 the artifact based on whether the voltage exceeds of either +50 or -50 microvolts.
</div>
<div>(b) What is the difference between the absolute threshold and relative threshold specified in the code? I am referring to the variables called abs_thrs and rel_thrs, which you define before the onset of the loop. </div>
<div><br>
</div>
<div>Thank you again for your precious help,</div>
Eleonora<br>
</div>
<div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
<br>
</div>
<div id="x_m_-3941740188306240806Signature">
<div>
<div></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
<span style="margin:0px; font-size:16px; font-family:Calibri,Arial,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; text-align:start; background-color:white"><font size="2" face="Calibri,Arial,Helvetica,sans-serif" style="color:rgb(117,123,128)"><span style="margin:0px"><b><font size="2" style="color:rgb(117,123,128)"><span style="margin:0px; font-size:11pt"><span style="margin:0px; font-size:13.31px; font-family:Calibri,sans-serif; color:rgb(222,106,25)">Eleonora
 Parrotta,  Doctoral Researcher in Social Neuroscience </span></span></font></b></span></font></span>
<div style="margin:0px; font-size:16px; font-family:Calibri,Arial,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; text-align:start; background-color:white">
<span style="color:rgb(222,106,25)"></span><font size="2" face="Calibri,Arial,Helvetica,sans-serif" style="color:rgb(117,123,128)"><span style="margin:0px"><font size="2" style="color:rgb(117,123,128)"><span style="margin:0px; font-size:11pt"><span style="margin:0px; font-size:13.31px; font-family:Calibri,sans-serif; color:purple">
<div style="margin:0px"><span style="margin:0px; color:rgb(117,123,128)"><span style="margin:0px; font-size:13.32px; font-family:Calibri,Arial,Helvetica,sans-serif,serif,EmojiFont; color:rgb(51,51,51); background-color:white">School of Psychology</span><span> </span>|
 University of Aberdeen | Aberdeen |<span> </span><span style="margin:0px; font-size:13.32px; font-family:Arial,sans-serif,serif,EmojiFont; color:rgb(51,51,51); background-color:white">AB24 3FX</span></span></div>
<span style="margin:0px"><span style="margin:0px; color:rgb(117,123,128)"><span style="margin:0px; font-size:13.32px; font-family:Arial,sans-serif,serif,EmojiFont; color:rgb(51,51,51); background-color:white"><span style="margin:0px; font-family:Calibri,Arial,Helvetica,sans-serif,serif,EmojiFont; background-color:white"><span style="margin:0px"><a href="mailto:e.parrotta.20@abdn.ac.uk" target="_blank">e.parrotta.20@abdn.ac.uk</a></span></span></span></span></span></span></span></font></span></font></div>
<br>
</div>
</div>
</div>
</div>
<div id="x_m_-3941740188306240806appendonsend"></div>
<hr style="display:inline-block; width:98%">
<div id="x_m_-3941740188306240806divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>Da:</b> Ivaylo Iotchev <<a href="mailto:ivaylo.iotchev@gmail.com" target="_blank">ivaylo.iotchev@gmail.com</a>><br>
<b>Inviato:</b> giovedě 25 maggio 2023 16:30<br>
<b>A:</b> eleonora parrotta <<a href="mailto:eleonora_p@hotmail.it" target="_blank">eleonora_p@hotmail.it</a>><br>
<b>Cc:</b> FieldTrip discussion list <<a href="mailto:fieldtrip@science.ru.nl" target="_blank">fieldtrip@science.ru.nl</a>><br>
<b>Oggetto:</b> Re: [FieldTrip] automatic artifact rejection based on voltage threshold</font>
<div> </div>
</div>
<div>
<div dir="ltr">So this is the loop:<br>
<br>
 data4.label                      <font color="#9900ff">%at this point of the script the data we are about to clean is called data4, cleaning happened after other manipulations (e.g. filter)</font><br>
    chs_remaining=[5:8];   <font color="#9900ff">% which channels to use for the cleaning, in our case this was 5th to 8th</font><br>
    <br>
    excluded = [];                   <font color="#9900ff"> %create matrix where excluded trials are collected</font><br>
    for i = 1:size(data4.trial,2)   <font color="#9900ff">%we specify here that we are going through the trial indexes, i is defined as the number of trials</font><br>
        dat=data4.trial{i}(chs_remaining,:); <font color="#9900ff">%we select the channels we want to clean from trial nr. i</font><br>
        <br>
        if any(any((dat>abs_thrs))) || any(any((dat<-abs_thrs))) <font color="#9900ff">
% abs_thrs - absolute threshold, set at the begining of the script, this line applies thresholding</font><br>
            excluded=[excluded i]; <font color="#9900ff">%we add a trial to excluded if above condition is met</font><br>
        end<br>
        <br>
        if ~ismember(i,excluded) <font color="#9900ff">%the next lines select trials which survived the absolute threshold cleaning</font><br>
            maxn=size(dat,2)-100;<br>
            for n=1:maxn<br>
                if any(max(dat(:,n:(n+100)),[],2)+abs(min(dat(:,n:(n+100)),[],2)) > rel_thrs)
<font color="#9900ff">% rel_thrs - relative threshold, set at the begining of the script</font><br>
                    excluded=[excluded i];<br>
                end<br>
            end<br>
        end<br>
    end<br>
    <br>
    cfg=[];<br>
    cfg.trials = setdiff(1:size(data4.trial,2),excluded);<br>
    data5=ft_redefinetrial(cfg,data4); <font color="#9900ff">%with these three lines we can finally integrate our cleaning with the FieldTripian ft_redefinetrial :)</font><br>
<div><font color="#9900ff"><br>
</font></div>
<div><font color="#000000">I hope this helps. I can trace this work back to my colleagues Marianna Boros and Boglárka Morvai, but it is possible that these parts have an even older origin. Some additional comments were now added by me to support better understanding,
 to the extent to which I could do so :)<br>
<br>
Best wishes, and success!<br>
<br>
(Dr.) Ivaylo (Ivo) Iotchev</font></div>
</div>
<br>
<div>
<div dir="ltr">Am Do., 25. Mai 2023 um 16:11 Uhr schrieb eleonora parrotta <<a href="mailto:eleonora_p@hotmail.it" target="_blank">eleonora_p@hotmail.it</a>>:<br>
</div>
<blockquote style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div>
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
That would be awesome, Dr. Ivaylo!</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
I've been trying to implement it for weeks!</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
Thank you so much for any help</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
Eleonora </div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
<br>
</div>
<div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
<br>
</div>
<div id="x_m_-3941740188306240806x_m_3568747525712178187Signature">
<div>
<div></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
<span style="margin:0px; font-size:16px; font-family:Calibri,Arial,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; text-align:start; background-color:white"><font size="2" face="Calibri,Arial,Helvetica,sans-serif" style="color:rgb(117,123,128)"><span style="margin:0px"><b><font size="2" style="color:rgb(117,123,128)"><span style="margin:0px; font-size:11pt"><span style="margin:0px; font-size:13.31px; font-family:Calibri,sans-serif; color:rgb(222,106,25)">Eleonora
 Parrotta,  Doctoral Researcher in Social Neuroscience </span></span></font></b></span></font></span>
<div style="margin:0px; font-size:16px; font-family:Calibri,Arial,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; text-align:start; background-color:white">
<span style="color:rgb(222,106,25)"></span><font size="2" face="Calibri,Arial,Helvetica,sans-serif" style="color:rgb(117,123,128)"><span style="margin:0px"><font size="2" style="color:rgb(117,123,128)"><span style="margin:0px; font-size:11pt"><span style="margin:0px; font-size:13.31px; font-family:Calibri,sans-serif; color:purple">
<div style="margin:0px"><span style="margin:0px; color:rgb(117,123,128)"><span style="margin:0px; font-size:13.32px; font-family:Calibri,Arial,Helvetica,sans-serif,serif,EmojiFont; color:rgb(51,51,51); background-color:white">School of Psychology</span><span> </span>|
 University of Aberdeen | Aberdeen |<span> </span><span style="margin:0px; font-size:13.32px; font-family:Arial,sans-serif,serif,EmojiFont; color:rgb(51,51,51); background-color:white">AB24 3FX</span></span></div>
<span style="margin:0px"><span style="margin:0px; color:rgb(117,123,128)"><span style="margin:0px; font-size:13.32px; font-family:Arial,sans-serif,serif,EmojiFont; color:rgb(51,51,51); background-color:white"><span style="margin:0px; font-family:Calibri,Arial,Helvetica,sans-serif,serif,EmojiFont; background-color:white"><span style="margin:0px"><a href="mailto:e.parrotta.20@abdn.ac.uk" target="_blank">e.parrotta.20@abdn.ac.uk</a></span></span></span></span></span></span></span></font></span></font></div>
<br>
</div>
</div>
</div>
</div>
<div id="x_m_-3941740188306240806x_m_3568747525712178187appendonsend"></div>
<hr style="display:inline-block; width:98%">
<div id="x_m_-3941740188306240806x_m_3568747525712178187divRplyFwdMsg" dir="ltr">
<font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>Da:</b> Ivaylo Iotchev <<a href="mailto:ivaylo.iotchev@gmail.com" target="_blank">ivaylo.iotchev@gmail.com</a>><br>
<b>Inviato:</b> giovedě 25 maggio 2023 14:50<br>
<b>A:</b> FieldTrip discussion list <<a href="mailto:fieldtrip@science.ru.nl" target="_blank">fieldtrip@science.ru.nl</a>><br>
<b>Cc:</b> eleonora parrotta <<a href="mailto:eleonora_p@hotmail.it" target="_blank">eleonora_p@hotmail.it</a>><br>
<b>Oggetto:</b> Re: [FieldTrip] automatic artifact rejection based on voltage threshold</font>
<div> </div>
</div>
<div>
<div dir="ltr">Hey Eleonora,<br>
<br>
I might be able to send you some lines tomorrow which implement thresholding, these lines do not make direct use of FieldTrip I think, but they are MATLAB intern and thus can be coordinated within a script that uses Fieldtrip functions, too (basically that's
 what we are doing at the moment).<br>
<br>
Best wishes,<br>
<br>
(Dr.) Ivaylo (Ivo) Iotchev</div>
<br>
<div>
<div dir="ltr">Am Do., 25. Mai 2023 um 15:45 Uhr schrieb eleonora parrotta via fieldtrip <<a href="mailto:fieldtrip@science.ru.nl" target="_blank">fieldtrip@science.ru.nl</a>>:<br>
</div>
<blockquote style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div>
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
Dear Fieldtrippers,</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
I am trying to implement an automatic artifact rejection on epoched data. </div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
The aim of this process would be to compare the same dataset, analyzed both in fieldtrip and eeglab. To do so, I would need to efficiently implement the same EEGLAB parameters used for the artifact rejection in fieldtrip. </div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
I have two options</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
<div><span>
<div style="font-size:11pt; margin:0px">
<div>
<ol>
<li><span><span style="margin:0px">eliminate the trials based on a</span></span> peak-to-peak artifact rejection, which detects and remove trials in which the EEG signal exceeds of a threshold of 100 microvolt</li></ol>
<ol start="2">
<li><span>eliminate the trials based on simple threshold voltage, that is, eliminate trials in which the voltage exceeds of +- 50 microvolts.</span><br>
</li></ol>
</div>
</div>
</span></div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
Both options would be fine as both are implemented in eeglab, but I do not manage to implement neither of the two into fieldtrip.</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
 I've tried to use both ft_artifact_threshold and ft_rejectartifact, even by combining the two.</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
ft_rejectartifact is not able not detect artifacts in the data, the output is always :</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
%artifact rejection
<div>cfg = [];</div>
<div>cfg.artfctdef.channel = [1:28 31:65];</div>
<div>cfg.artfctdef.threshold.min = -50;</div>
<div>cfg.artfctdef.threshold.max = 50;</div>
<div>cfg.artfctdef.prestim = -0.1;</div>
<div>cfg.artfctdef.poststim = 0.6;</div>
<div>cfg.artfctdef.window = 'trial';</div>
data_clean = ft_rejectartifact(cfg, clean_data);<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
the call to "ft_preprocessing" took 111 seconds
<div>rejected   0 trials completely</div>
<div>rejected   0 trials partially</div>
<div>filled parts of   0 trials with NaNs</div>
<div>filled parts of   0 trials with zeros</div>
filled parts of   0 trials with a specified value <br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
<span style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">This is an example of what I get when using the functions together..</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
<span style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)"><br>
</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
<span style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">cfg = [];</span><br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
<div>cfg.continuous = 'no';</div>
<div>cfg.artfctdef.channel = {'all', '-ECG1', '-ECG2', '-IO'};</div>
<div>cfg.dataset =clean_data.trial(:,:);</div>
<div>% cfg.artfctdef.threshold.min = -50;</div>
<div>% cfg.artfctdef.threshold.max = 50;</div>
<div>% cfg.artfctdef.threshold.range=100;</div>
<div>cfg.artfctdef.prestim = -0.1;</div>
<div>cfg.artfctdef.poststim = 0.6;</div>
<div>cfg.trl=trl;</div>
<div>[~, artData] = ft_artifact_threshold(cfg, clean_data);</div>
<div><br>
</div>
<div>cfg = [];</div>
<div>cfg.artfctdef.xxx.artifact = artData;</div>
<div>cfg.artfctdef.reject = 'complete';</div>
<div>fnData = ft_rejectartifact(cfg, clean_data);</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
The output seems to not be able to read the trials information, as it does not mark the trials but only segments in which there are artifacts: </div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
searching for artifacts in 65 channels
<div>applying preprocessing options</div>
<div>searching in trial 643 from 643</div>
<div>detected 7172 artifacts</div>
the call to "ft_artifact_threshold" took 25 seconds</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
>>
<div>cfg = [];</div>
<div>cfg.artfctdef.xxx.artifact = artData;</div>
<div>cfg.artfctdef.reject = 'complete';</div>
<div>fnData = ft_rejectartifact(cfg, clean_data);</div>
<div>detected   1 xxx artifacts</div>
<div>Index in position 2 exceeds array bounds. Index must not exceed 1.</div>
<div><br>
</div>
<div>Error in ft_rejectartifact (line 305)</div>
    endsample = artifact{i}(:,2);<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
Please help me!!</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
Any support is appreciated <br>
Thank you very much </div>
<div>
<div id="x_m_-3941740188306240806x_m_3568747525712178187x_m_9165916737300767032Signature">
<div>
<div></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:11pt; color:rgb(0,0,0)">
<span style="margin:0px; font-size:16px; font-family:Calibri,Arial,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; text-align:start; background-color:white"><font size="2" face="Calibri,Arial,Helvetica,sans-serif" style="color:rgb(117,123,128)"><span style="margin:0px"><b><font size="2" style="color:rgb(117,123,128)"><span style="margin:0px; font-size:11pt"><span style="margin:0px; font-size:13.31px; font-family:Calibri,sans-serif; color:rgb(222,106,25)">Eleonora
 Parrotta,  Doctoral Researcher in Social Neuroscience </span></span></font></b></span></font></span>
<div style="margin:0px; font-size:16px; font-family:Calibri,Arial,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; text-align:start; background-color:white">
<span style="color:rgb(222,106,25)"></span><font size="2" face="Calibri,Arial,Helvetica,sans-serif" style="color:rgb(117,123,128)"><span style="margin:0px"><font size="2" style="color:rgb(117,123,128)"><span style="margin:0px; font-size:11pt"><span style="margin:0px; font-size:13.31px; font-family:Calibri,sans-serif; color:purple">
<div style="margin:0px"><span style="margin:0px; color:rgb(117,123,128)"><span style="margin:0px; font-size:13.32px; font-family:Calibri,Arial,Helvetica,sans-serif,serif,EmojiFont; color:rgb(51,51,51); background-color:white">School of Psychology</span><span> </span>|
 University of Aberdeen | Aberdeen |<span> </span><span style="margin:0px; font-size:13.32px; font-family:Arial,sans-serif,serif,EmojiFont; color:rgb(51,51,51); background-color:white">AB24 3FX</span></span></div>
<span style="margin:0px"><span style="margin:0px; color:rgb(117,123,128)"><span style="margin:0px; font-size:13.32px; font-family:Arial,sans-serif,serif,EmojiFont; color:rgb(51,51,51); background-color:white"><span style="margin:0px; font-family:Calibri,Arial,Helvetica,sans-serif,serif,EmojiFont; background-color:white"><span style="margin:0px"><a href="mailto:e.parrotta.20@abdn.ac.uk" target="_blank">e.parrotta.20@abdn.ac.uk</a></span></span></span></span></span></span></span></font></span></font></div>
<br>
</div>
</div>
</div>
</div>
</div>
_______________________________________________<br>
fieldtrip mailing list<br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer" target="_blank">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
<a href="https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!7ddtzKAneG1sI-ZoVtzMHtrOuzdvXjt2p9GYsS3guVXUYc0R2Yl-3GnXXFP9zx8SOt4-kwJAQJnF06eYhGJuX4Jox6g$" rel="noreferrer" target="_blank">https://doi.org/10.1371/journal.pcbi.1002202</a><br>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</body>
</html>