<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 class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Do., 25. Mai 2023 um 15:45 Uhr schrieb eleonora parrotta via fieldtrip <<a href="mailto:fieldtrip@science.ru.nl">fieldtrip@science.ru.nl</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg9165916737300767032">




<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="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!8X0kphJff_7BqOs3VUJZHHgkGXvuM2fuw3Mc2xdJUx_owXx2Zb6tA-C8K7PjUdkw8qMnYbIgWKOvN5qCo8h0Nw_prsHVVw$" rel="noreferrer" target="_blank">https://doi.org/10.1371/journal.pcbi.1002202</a><br>
</div></blockquote></div>