<div dir="ltr">So far I've just been using ft_databrowser in the same way you mention to look for artifacts that affect most or all channels. But I think I will need to also visually check each channel for bad trials. Since I'm working with iEEG, these will be mainly those picking up any epileptic discharges. Of course the channels around the seizure foci I will throw out entirely.<div><br></div><div>I'm a bit daunted by how much work it will be to do a channel x trial visual rejection since I have ~1700 trials and ~ 100 channels for our one subject so far. In fact just typing those numbers makes me think it may not be feasible. Do you find the automated rejection works satisfactorily for you?</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 8, 2017 at 3:35 PM, Teresa Madsen <span dir="ltr"><<a href="mailto:braingirl@gmail.com" target="_blank">braingirl@gmail.com</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">I actually do a mix of approaches:  a quick look using ft_databrowser with all channels for irregular artifacts like disconnection events, then a channel-by-channel search for large z-value artifacts and clipping artifacts, then I remove all those and do one last ft_databrowser review of all channels together.  I'll attach the function I was working on, but it's more complex than you originally asked for and not fully tested yet, so use at your own risk.<div><br></div><div>Do you use ft_databrowser or ft_rejectvisual for visual artifact rejection?</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>~Teresa</div><div><br></div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 8, 2017 at 12:04 PM, Tim Meehan <span dir="ltr"><<a href="mailto:timeehan@gmail.com" target="_blank">timeehan@gmail.com</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">Thanks for sharing! I'm just taking a look now. It looks like you're doing mostly automated rejection. Or are you also doing visual rejection along with the z-value thresholding?<div><br></div><div>Thanks again,</div><div>Tim</div></div><div class="m_387050010567836901HOEnZb"><div class="m_387050010567836901h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 3, 2017 at 5:31 PM, Teresa Madsen <span dir="ltr"><<a href="mailto:braingirl@gmail.com" target="_blank">braingirl@gmail.com</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">Here's a rough sketch of my approach, with one custom function attached.  If you or others find it useful, maybe we can think about ways to incorporate it into the FieldTrip code.  I've been working mostly with scripts, but you've inspired me to work on functionizing the rest of it so it's more shareable.<div><br></div><div>So, assuming raw multichannel data has been loaded into FieldTrip structure 'data' with unique trial identifiers in data.trialinfo...</div><div><font face="monospace, monospace"><br></font></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="font-family:monospace,monospace">for ch = 1:numel(data.label)</span></div><div><font face="monospace, monospace">  %% pull out one channel at a time</font></div><div><span style="font-family:monospace,monospace">  cfg = [];</span></div><div><div><font face="monospace, monospace">  cfg.channel = data.label{ch};</font></div></div><div><font face="monospace, monospace"><br></font></div><div><div><span style="font-family:monospace,monospace">  </span><span style="font-family:monospace,monospace">datch{ch} </span><span style="font-family:monospace,monospace">= ft_selectdata(cfg, data);</span></div></div><div><div><font face="monospace, monospace">    </font></div></div><div><font face="monospace, monospace">  %% identify large z-value artifacts</font><span style="font-family:monospace,monospace"> and/or whatever else you might want</span></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="font-family:monospace,monospace">  cfg = [];</span></div><div><span style="font-family:monospace,monospace">  </span><font face="monospace, monospace">cfg.artfctdef.zvalue.channel        = 'all';</font></div><div><font face="monospace, monospace">  cfg.artfctdef.zvalue.cutoff         = 15;</font></div><div><font face="monospace, monospace">  cfg.artfctdef.zvalue.trlpaddin<wbr>g     = 0;</font></div><div><font face="monospace, monospace">  cfg.artfctdef.zvalue.fltpaddin<wbr>g     = 0;</font></div><div><font face="monospace, monospace">  cfg.artfctdef.zvalue.artpaddin<wbr>g     = 0.1;</font></div><div><font face="monospace, monospace">  cfg.artfctdef.zvalue.rectify        = 'yes';</font></div><div><br></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="font-family:monospace,monospace">  </span><span style="font-family:monospace,monospace">[~, artifact.</span><span style="font-family:monospace,monospace">zvalue</span><span style="font-family:monospace,monospace">] = ft_artifact_zvalue([], </span><span style="font-family:monospace,monospace">datch{c<wbr>h}</span><span style="font-family:monospace,monospace">);</span></div><div><span style="font-family:monospace,monospace"><br></span></div><div><span style="font-family:monospace,monospace">  </span><span style="font-family:monospace,monospace">%% replace artifacts with NaNs</span></div><div><span style="font-family:monospace,monospace">  cfg = [];</span></div><div><div><font face="monospace, monospace">  cfg.artfctdef.zvalue.artifact = artifact.zvalue;</font></div></div><div><div style="font-family:monospace,monospace"><div>  cfg.artfctdef.reject          = 'nan';</div><div><br></div></div></div><div><div style="font-family:monospace,monospace"><div>  datch{ch} = ft_rejectartifact(cfg,datch{ch<wbr>});</div></div></div><div><span style="font-family:monospace,monospace">end</span></div><div><span style="font-family:monospace,monospace"><br></span></div><div><span style="font-family:monospace,monospace">%% re-merge channels</span></div><div><div><span style="font-family:monospace,monospace">data = ft_appenddata([],datch);</span></div></div><div><div style="font-family:monospace,monospace"><br></div></div><div><span style="font-family:monospace,monospace">%% </span><span style="font-family:monospace,monospace">mark </span><span style="font-family:monospace,monospace">uniform </span><span style="font-family:monospace,monospace">NaNs as artifacts when they occur across all channels</span></div><div><span style="font-family:monospace,monospace">% and replace non-uniform NaNs (on some but not all channels) with zeroes, saving times</span></div><div><span style="font-family:monospace,monospace">[artifact,data,times] = artifact_nan2zero_TEM(data) % custom function, see attached</span><br></div><div><br></div><div><span style="font-family:monospace,monospace">%% reject artifacts by breaking into sub-trials</span></div><div><div><font face="monospace, monospace">cfg = [];</font></div><div><span style="font-family:monospace,monospace">cfg.artfctdef.nan2zero.artifac<wbr>t </span><span style="font-family:monospace,monospace">= artifact;</span><br></div><div><font face="monospace, monospace">cfg.artfctdef.reject            = 'partial';</font></div><div><font face="monospace, monospace"><br></font></div><div><span style="font-family:monospace,monospace">data = ft_rejectartifact(cfg,data);</span><br></div></div><div><font face="monospace, monospace"><br></font></div><div><span style="font-family:monospace,monospace">%% identify real trials</span><br></div><div><div><span style="font-family:monospace,monospace">trlinfo = unique(data.trialinfo,'rows','<wbr>stable');</span><br></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">for tr = 1:size(trlinfo,1)</font></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><font face="monospace, monospace">  </font><span style="font-family:monospace,monospace">%% calculate trial spectrogram</span></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">  </font><span style="font-family:monospace,monospace">cfg = [];</span></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"></blockquote><span style="font-family:monospace,monospace">  cfg.trials = ismember(data.trialinfo, trlinfo(tr,:), 'rows');</span><br><span style="font-family:monospace,monospace">  cfg.keeptrials = 'no';             % refers to sub-trials</span></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="font-family:monospace,monospace">  cfg.method     = 'mtmconvol';<br></span></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="font-family:monospace,monospace">  cfg.output     = 'powandcsd';</span></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">  cfg.foi = 2.^(0:0.1:log2(300));    % 83 freqs, log2 spaced, 1-300 Hz</font></div><div><font face="monospace, monospace">  cfg.tapsmofrq  = cfg.foi/10;       % smooth by 10%</font></div><div><font face="monospace, monospace">  cfg.t_ftimwin  = 2./cfg.tapsmofrq; % for 3 tapers (K=3), T=2/W</font></div><div><font face="monospace, monospace">  cfg.toi        = '50%';</font></div><div><font face="monospace, monospace">  cfg.pad        = 'nextpow2';</font></div><div><span style="font-family:monospace,monospace">  </span></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><font face="monospace, monospace">  </font><span style="font-family:monospace,monospace">freq = ft_freqanalysis(cfg,data);</span><br></div><div><font face="monospace, monospace">  </font></div><div><span style="font-family:monospace,monospace">  %% replace powspctrm & crsspctrum values with NaNs</span></div><div><span style="font-family:monospace,monospace">  % </span><span style="font-family:monospace,monospace">where t_ftimwin (or wavlen for wavelets) overlaps with artifact</span></div><div><font face="monospace, monospace">  </font><span style="font-family:monospace,monospace">for ch = 1:numel(freq.label)</span><br></div><div><font face="monospace, monospace">    badt = [times{tr,ch}];</font></div><div><font face="monospace, monospace">    if ~isempty(badt) && any(...</font></div><div><font face="monospace, monospace">        badt > (min(freq.time) - max(freq.cfg.t_ftimwin)) & ...</font></div><div><font face="monospace, monospace">        badt < (max(freq.time) + max(freq.cfg.t_ftimwin)))</font></div><div><font face="monospace, monospace">      ci = find(any(strcmp(freq.label{ch}<wbr>, freq.labelcmb)));</font></div><div><font face="monospace, monospace">      for t = 1:numel(freq.time)</font></div><div><font face="monospace, monospace">        for f = 1:numel(freq.freq)</font></div><div><font face="monospace, monospace">          mint = freq.time(t) - freq.cfg.t_ftimwin(f);</font></div><div><font face="monospace, monospace">          maxt = freq.time(t) + freq.cfg.t_ftimwin(f);</font></div><div><font face="monospace, monospace">          if any(badt > mint & badt < maxt)</font></div><div><font face="monospace, monospace">            freq.powspctrm(ch,f,t) = NaN;</font></div><div><font face="monospace, monospace">            freq.crsspctrm(ci,f,t) = NaN;</font></div><div><font face="monospace, monospace">          end</font></div><div><font face="monospace, monospace">        end</font></div><div><font face="monospace, monospace">      end</font></div><div><font face="monospace, monospace">    end</font></div><div><font face="monospace, monospace">  end</font></div></div><div><font face="monospace, monospace"><br></font></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><font face="monospace, monospace">  %% save corrected output</font></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><font face="monospace, monospace">  </font><span style="font-family:monospace,monospace">save(</span><font face="monospace, monospace">['trial' num2str(tr)</font><font face="monospace, monospace"> 'mtmconvolTFA.mat'<wbr>]</font><span style="font-family:monospace,monospace">, 'freq', '-v7.3');</span></div><div><font face="monospace, monospace">end</font></div></div><div><br></div></blockquote><div><font face="monospace, monospace">    </font></div></div><div class="m_387050010567836901m_2526031096446437846HOEnZb"><div class="m_387050010567836901m_2526031096446437846h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 2, 2017 at 9:55 AM, Tim Meehan <span dir="ltr"><<a href="mailto:timeehan@gmail.com" target="_blank">timeehan@gmail.com</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">Hi Teresa,<div><br></div><div>Thanks for the reply. I'll take a look at your example if you don't mind sharing. Thanks!</div><span class="m_387050010567836901m_2526031096446437846m_498533721170297676HOEnZb"><font color="#888888"><div><br></div><div>Tim</div></font></span></div><div class="m_387050010567836901m_2526031096446437846m_498533721170297676HOEnZb"><div class="m_387050010567836901m_2526031096446437846m_498533721170297676h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 2, 2017 at 9:53 AM, Teresa Madsen <span dir="ltr"><<a href="mailto:braingirl@gmail.com" target="_blank">braingirl@gmail.com</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">No, not really.  The only way I've found to do that is to loop through my artifact rejection process on each trial individually, then merge them back together with NaNs filling in where there are artifacts, but then that breaks every form of analysis I want to do.  :-P<div><br></div><div>I wonder if it would work to fill in the artifacts with 0s instead of NaNs....I might play with that.  Let me know if you're interested in some example code.</div><div><br></div><div>~Teresa</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_387050010567836901m_2526031096446437846m_498533721170297676m_-8415465910375655184h5">On Wed, Mar 1, 2017 at 3:55 PM, Tim Meehan <span dir="ltr"><<a href="mailto:timeehan@gmail.com" target="_blank">timeehan@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_387050010567836901m_2526031096446437846m_498533721170297676m_-8415465910375655184h5"><div dir="ltr">Hello All,<div><br></div><div>When performing visual artifact rejection, I want to be able to mark artifacts that occur during some specific trials and only on some specific channels. In the tutorials I see only ways to mark bad channels (i.e. across all trials) or bad trials (i.e. across all channels). Does FieldTrip handle marking artifacts restricted to some channel/trial combination?</div><div><br></div><div>Thanks,</div><div>Tim</div></div>
<br></div></div>______________________________<wbr>_________________<br>
fieldtrip mailing list<br>
<a href="mailto:fieldtrip@donders.ru.nl" target="_blank">fieldtrip@donders.ru.nl</a><br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer" target="_blank">https://mailman.science.ru.nl/<wbr>mailman/listinfo/fieldtrip</a><span class="m_387050010567836901m_2526031096446437846m_498533721170297676m_-8415465910375655184HOEnZb"><font color="#888888"><br></font></span></blockquote></div><span class="m_387050010567836901m_2526031096446437846m_498533721170297676m_-8415465910375655184HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div class="m_387050010567836901m_2526031096446437846m_498533721170297676m_-8415465910375655184m_-655738992042887856gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><font color="#0000ff"><font size="4"><font face="garamond, serif">Teresa E. Madsen, PhD</font><br></font><font face="garamond, serif">Research Technical Specialist:  <i>in vivo </i>electrophysiology & data analysis</font></font></div><div dir="ltr"><font color="#0000ff"><font face="garamond, serif">Division of Behavioral Neuroscience and Psychiatric Disorders<br>Yerkes National Primate Research Center</font></font><div><font face="garamond, serif" color="#0000ff">Emory University<br></font><div><font face="garamond, serif" color="#0000ff">Rainnie Lab, NSB 5233<br>954 Gatewood Rd. NE<br>Atlanta, GA 30329</font></div><div><div><font face="garamond, serif" color="#0000ff"><a href="tel:(770)%20296-9119" value="+17702969119" target="_blank">(770) 296-9119</a></font><br></div></div></div><div><font face="garamond, serif" color="#0000ff"><a href="mailto:braingirl@gmail.com" target="_blank">braingirl@gmail.com</a></font></div><div><font face="garamond, serif" color="#0000ff"><div><a href="https://www.linkedin.com/in/temadsen" target="_blank">https://www.linkedin.com/in/te<wbr>madsen</a></div></font></div></div></div></div></div></div></div>
</font></span></div>
<br>______________________________<wbr>_________________<br>
fieldtrip mailing list<br>
<a href="mailto:fieldtrip@donders.ru.nl" target="_blank">fieldtrip@donders.ru.nl</a><br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer" target="_blank">https://mailman.science.ru.nl/<wbr>mailman/listinfo/fieldtrip</a><br></blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<br>
fieldtrip mailing list<br>
<a href="mailto:fieldtrip@donders.ru.nl" target="_blank">fieldtrip@donders.ru.nl</a><br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer" target="_blank">https://mailman.science.ru.nl/<wbr>mailman/listinfo/fieldtrip</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="m_387050010567836901m_2526031096446437846m_498533721170297676gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><font color="#0000ff"><font size="4"><font face="garamond, serif">Teresa E. Madsen, PhD</font><br></font><font face="garamond, serif">Research Technical Specialist:  <i>in vivo </i>electrophysiology & data analysis</font></font></div><div dir="ltr"><font color="#0000ff"><font face="garamond, serif">Division of Behavioral Neuroscience and Psychiatric Disorders<br>Yerkes National Primate Research Center</font></font><div><font face="garamond, serif" color="#0000ff">Emory University<br></font><div><font face="garamond, serif" color="#0000ff">Rainnie Lab, NSB 5233<br>954 Gatewood Rd. NE<br>Atlanta, GA 30329</font></div><div><div><font face="garamond, serif" color="#0000ff"><a href="tel:(770)%20296-9119" value="+17702969119" target="_blank">(770) 296-9119</a></font><br></div></div></div><div><font face="garamond, serif" color="#0000ff"><a href="mailto:braingirl@gmail.com" target="_blank">braingirl@gmail.com</a></font></div><div><font face="garamond, serif" color="#0000ff"><div><a href="https://www.linkedin.com/in/temadsen" target="_blank">https://www.linkedin.com/in/te<wbr>madsen</a></div></font></div></div></div></div></div></div></div>
</div>
</div></div><br>______________________________<wbr>_________________<br>
fieldtrip mailing list<br>
<a href="mailto:fieldtrip@donders.ru.nl" target="_blank">fieldtrip@donders.ru.nl</a><br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer" target="_blank">https://mailman.science.ru.nl/<wbr>mailman/listinfo/fieldtrip</a><br></blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<br>
fieldtrip mailing list<br>
<a href="mailto:fieldtrip@donders.ru.nl" target="_blank">fieldtrip@donders.ru.nl</a><br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer" target="_blank">https://mailman.science.ru.nl/<wbr>mailman/listinfo/fieldtrip</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="m_387050010567836901gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><font color="#0000ff"><font size="4"><font face="garamond, serif">Teresa E. Madsen, PhD</font><br></font><font face="garamond, serif">Research Technical Specialist:  <i>in vivo </i>electrophysiology & data analysis</font></font></div><div dir="ltr"><font color="#0000ff"><font face="garamond, serif">Division of Behavioral Neuroscience and Psychiatric Disorders<br>Yerkes National Primate Research Center</font></font><div><font face="garamond, serif" color="#0000ff">Emory University<br></font><div><font face="garamond, serif" color="#0000ff">Rainnie Lab, NSB 5233<br>954 Gatewood Rd. NE<br>Atlanta, GA 30329</font></div><div><div><font face="garamond, serif" color="#0000ff"><a href="tel:(770)%20296-9119" value="+17702969119" target="_blank">(770) 296-9119</a></font><br></div></div></div><div><font face="garamond, serif" color="#0000ff"><a href="mailto:braingirl@gmail.com" target="_blank">braingirl@gmail.com</a></font></div><div><font face="garamond, serif" color="#0000ff"><div><a href="https://www.linkedin.com/in/temadsen" target="_blank">https://www.linkedin.com/in/<wbr>temadsen</a></div></font></div></div></div></div></div></div></div>
</div>
</div></div><br>______________________________<wbr>_________________<br>
fieldtrip mailing list<br>
<a href="mailto:fieldtrip@donders.ru.nl">fieldtrip@donders.ru.nl</a><br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer" target="_blank">https://mailman.science.ru.nl/<wbr>mailman/listinfo/fieldtrip</a><br></blockquote></div><br></div>