<div dir="ltr"><div>I am still struggling with automatic detection of linear drif. I solved the 1st issue with ft_artifact_threshold by writing my own simple function to do what I needed to achieve.</div><div><br></div><div>As I mentioned, my starting point is data segmented into trials. I look into every trial and add it to an array if there are no values higher or lower than +/-75. I then select only those trials that were added to this array.</div><div>







<p class="gmail-p1"><span class="gmail-Apple-converted-space">    </span>cfg=[];</p><p class="gmail-p1"><span class="gmail-Apple-converted-space">    </span>cfg.trials=[];</p>
<p class="gmail-p1"><span class="gmail-Apple-converted-space">    </span><span class="gmail-s1">for</span> tr = 1:length(baselined.trial)</p>
<p class="gmail-p1"><span class="gmail-Apple-converted-space">        </span><span class="gmail-s1">if</span> length(find(baselined.trial{1, tr} > 75 | baselined.trial{1, tr} < -75)) == 0</p>
<p class="gmail-p1"><span class="gmail-Apple-converted-space">            </span>cfg.trials=[cfg.trials, tr];</p>
<p class="gmail-p1"><span class="gmail-Apple-converted-space">        </span><span class="gmail-s1">end</span></p>
<p class="gmail-p1"><span class="gmail-Apple-converted-space">    </span><span class="gmail-s1">end</span></p>
<p class="gmail-p1"><span class="gmail-Apple-converted-space">    </span>filtered = ft_selectdata(cfg, baselined);</p><p class="gmail-p1"><br>I hope this is useful to someone.</p><p class="gmail-p1"><br></p><p class="gmail-p1">Arnold</p><p class="gmail-p1"><br></p></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 22, 2017 at 3:45 PM, Arnold Kochari <span dir="ltr"><<a href="mailto:a.kochari@uva.nl" target="_blank">a.kochari@uva.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">
















<p class="MsoNormal">Dear FieldTrip
community,<br></p><p class="MsoNormal"><span></span></p>

<p class="MsoNormal"><span> </span></p>

<p class="MsoNormal" style="margin-bottom:12pt;line-height:13pt">I am new to FieldTrip and got stuck while trying to exactly replicate an
analysis reported in a paper. I would be very grateful for any tips.<br>
Specifically, I cannot manage to automatically reject trials with certain
min/max uV (question 1) and cannot find any way to automatically detect linear drift (question 2). <span></span></p>

<p class="MsoNormal"><b>1.</b> After segmenting and baseline correcting using <i>demean</i>, I am trying to use the following code for rejection of trials
with extreme values using <i>ft_artifact_threshold</i>, but I seem to have made a mistake somewhere:<br>
<br>
<span style="font-size:10pt;font-family:Courier;color:black">   
cfg = [];</span><span style="font-family:Courier"><span></span></span></p>

<p class="MsoNormal"><span style="font-size:10pt;font-family:Courier;color:black">    cfg.trl =</span><font color="#000000"><span style="font-size:10pt;font-family:Courier"> </span><span style="font-size:10pt;font-family:Courier">'baselined.sampleinfo'</span><span style="font-size:10pt;font-family:Courier">;</span></font><span style="font-family:Courier"><span></span></span></p>

<p class="MsoNormal"><span style="font-size:10pt;font-family:Courier;color:black">    cfg.continuous</span><font color="#000000"><span style="font-size:10pt;font-family:Courier"> = </span><span style="font-size:10pt;font-family:Courier">'no'</span><span style="font-size:10pt;font-family:Courier">;</span></font><span style="font-family:Courier"><span></span></span></p>

<p class="MsoNormal"><span style="font-size:10pt;font-family:Courier;color:black">    cfg.artfctdef.threshold.min = -75;</span><span style="font-family:Courier"><span></span></span></p>

<p class="MsoNormal"><span style="font-size:10pt;font-family:Courier;color:black">    cfg.artfctdef.threshold.max = 75;</span><span style="font-family:Courier"><span></span></span></p>

<p class="MsoNormal"><span style="font-size:10pt;font-family:Courier;color:black">    </span><span style="font-family:Courier"><span></span></span></p>

<p class="MsoNormal"><span style="font-size:10pt;font-family:Courier;color:black">    [cfg, artifact] =
ft_artifact_threshold(cfg, baselined);</span><span style="font-family:Courier"><span></span></span></p>

<p class="MsoNormal" style="margin-bottom:12pt;line-height:13pt"><span> <br></span>I am getting to following error: </p><p class="MsoNormal" style="margin-bottom:12pt;line-height:13pt">
Error using butter (line 79) <br>butter: first
band edge must be smaller than second</p><p class="MsoNormal" style="margin-bottom:12pt;line-height:13pt">Error in
ft_preproc_bandpassfilter (line 153) <br>[B, A] = butter(N, [min(Fbp)/Fn
max(Fbp)/Fn]); <br><br>Error in
preproc (line 327)<br>if strcmp(cfg.bpfilter, 'yes'), dat = ft_preproc_bandpassfilter(dat,
fsample, cfg.bpfreq, cfg.bpfiltord, cfg.bpfilttype,<br>cfg.bpfiltdir, cfg.bpinstabilityfix,
cfg.bpfiltdf, cfg.bpfiltwintype, cfg.bpfiltdev, cfg.plotfiltresp,
cfg.usefftfilt); end</p><p class="MsoNormal" style="margin-bottom:12pt;line-height:13pt">Error in
ft_artifact_threshold (line 164)<br>dat = preproc(dat, channel,
offset2time(cfg.trl(trlop,3), hdr.Fs, size(dat,2)), artfctdef);<br><br></p><p class="MsoNormal" style="margin-bottom:12pt;line-height:13pt"><b>2. </b>I am also trying to detect a linear drift of more than +/- 50 uV beginning before the onset of the stimulus (so before 0). With this one, I am not sure where to begin. I would be grateful for tips about what functions I can use to do this.</p><p class="MsoNormal" style="margin-bottom:12pt;line-height:13pt"><br></p><p class="MsoNormal" style="margin-bottom:12pt;line-height:13pt">Kind regards,<br>Arnold Kochari<br>PhD candidate, Institute for Logic, Language and Computation, University of Amsterdam</p>

</div>
</blockquote></div><br></div>