<div dir="ltr">Dear Jan-Mathijs,<div><br></div><div>Thanks a lot for your reply and your tips.</div><div>Actually I've already segmented the data in 30 seconds epochs, and the reason why I did it is that these are sleep data: so I should keep this length because of the night scoring.</div><div>I tried to enlarge the notch too, but it still doesn't work; the spectra before and after the filtering are exactly the same.</div><div><br></div><div>Best,</div><div>Alessandro</div></div><br><div class="gmail_quote"><div dir="ltr">Il giorno gio 28 giu 2018 alle ore 19:35 Schoffelen, J.M. (Jan Mathijs) <<a href="mailto:jan.schoffelen@donders.ru.nl">jan.schoffelen@donders.ru.nl</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">
Dear Alessandro,
<div><br>
</div>
<div>Given the code you provided it looks as if you have one single very long trial that you subject to dft-filtering. If the power line fluctuations actually do vary a bit in amplitude, which is likely (particularly given long sections of data), the
pure 50 (or 60) Hz sinusoid will get some ‘bandwidth’, so the removal won’t be perfect. I’d recommend to call ft_redefinetrial first, and then do a second call to ft_preprocessing with the dftfilter switched on. Yet, I’d expect that with 30 s segments it still
won’t work that well. In this case you could widen the notch a bit by specifying cfg.dftfreq = 50+(-n:n)./30;, with n put to a small number, e.g. <=3. However, unless you have good reasons to have the data chopped in half-minute segments, I’d also consider
to reduce this length, because you probably do not need to have a 1/30 Hz frequency resolution in your spectral decomposition.</div>
<div><br>
</div>
<div>Best wishes,</div>
<div>Jan-Mathijs</div>
<div><br>
</div>
<div>
<div>
<div style="word-wrap:break-word">
<div style="word-wrap:break-word">
<div style="word-wrap:break-word">
J.M.Schoffelen, MD PhD<br>
Associate PI, VIDI-fellow - PI, language in interaction<br>
Telephone: +31-24-3614793</div>
<div style="word-wrap:break-word">
Physical location: room 00.028</div>
<div style="word-wrap:break-word">
Donders Centre for Cognitive Neuroimaging, Nijmegen, The Netherlands<br>
<br>
<br>
</div>
</div>
</div>
</div>
</div>
<div><br>
</div>
<div><br>
<div>
<blockquote type="cite">
<div>On 28 Jun 2018, at 16:22, Alessandro Orticoni <<a href="mailto:alessandro.orticoni@gmail.com" target="_blank">alessandro.orticoni@gmail.com</a>> wrote:</div>
<br class="m_-3441952372654782124Apple-interchange-newline">
<div>
<div dir="ltr">Dear experts,
<div><br>
</div>
<div>I'm basically a beginner in coding with Fieldtrip, and I'm having a problem with line noise filtering.</div>
<div>I would like to remove it from the heart rate signal, and I tried just typing 'yes' at the option cfg.dftfilter.</div>
<div>But is doesn't seem to work, since the power spectrum contains the 50Hz and her harmonics even after the filtering.</div>
<div><br>
</div>
<div>You can find the code in the following lines:</div>
<div><br>
</div>
<div>
<div><font face="monospace, monospace" size="1" color="#0b5394">%% ===FREQUENCY Pre Filtering VERIFICATION===</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">fs=data.fsample;</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394"><br>
</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">cfg = [];</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">cfg.output = 'pow';</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">cfg.channel = 'ECG 2';</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">cfg.method = 'mtmfft';</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">cfg.taper = 'hanning';</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">cfg.pad = 'nextpow2';</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">cfg.foilim = [0.3 fs/2]; % teorema di Nyquist</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">freq_epoched_Cz = ft_freqanalysis(cfg, data_epoched_Cz);</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394"><br>
</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">%% ===Plot Spectra===</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">figure;</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">plot(freq_epoched_Cz.freq,mag2db(freq_epoched_Cz.powspctrm));</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394"><br>
</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">%% ===Filtering===</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">cfg = [];</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">cfg.channel = {'ECG 2'};</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">cfg.dftfilter = 'yes';</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">ECG_Filtered = ft_preprocessing(cfg,data_Cz);</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394"><br>
</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">cfg = [];</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">cfg.length = 30; % in seconds;</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">cfg.overlap = 0;</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">data_epoched_ECG_Filtered = ft_redefinetrial(cfg, ECG_Filtered);</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394"><br>
</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">cfg = [];</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">cfg.output = 'pow';</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">cfg.method = 'mtmfft';</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">cfg.taper = 'hanning';</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">cfg.pad = 'nextpow2';</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">cfg.foilim = [0.3 fs/2]; % teorema di Nyquist</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">freq_epoched_Cz_Filtered = ft_freqanalysis(cfg, data_epoched_ECG_Filtered);</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394"><br>
</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">%% ===Plot Spectra===</font></div>
<div><font face="monospace, monospace" size="1" color="#0b5394">plot(freq_epoched_Cz_Filtered.freq,mag2db(freq_epoched_Cz_Filtered.powspctrm));</font></div>
</div>
<div><br>
</div>
<div>Thanks a lot.</div>
<div><br>
</div>
<div>Kind regards,</div>
<div>Alessandro Orticoni</div>
</div>
_______________________________________________<br>
fieldtrip mailing list<br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" target="_blank">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
<a href="https://doi.org/10.1371/journal.pcbi.1002202" target="_blank">https://doi.org/10.1371/journal.pcbi.1002202</a></div>
</blockquote>
</div>
<br>
</div>
<br>
<br>
<div>
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">
<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://doi.org/10.1371/journal.pcbi.1002202" rel="noreferrer" target="_blank">https://doi.org/10.1371/journal.pcbi.1002202</a></blockquote></div>