# 50Hz artefact for time frequency analysis {Disarmed}

**URL:** <https://mne.discourse.group/t/50hz-artefact-for-time-frequency-analysis-disarmed/1328>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [October 6, 2017, 10:43am UTC](https://mne.discourse.group/t/50hz-artefact-for-time-frequency-analysis-disarmed/1328 "2017-10-06T10:43:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [October 6, 2017, 10:43am UTC](https://mne.discourse.group/t/50hz-artefact-for-time-frequency-analysis-disarmed/1328/1 "2017-10-06T10:43:11Z")

</div>

Hi all,

I am trying to deal with line noise that may have come from HPI or and outside line ( 60HZ) I saw this thread from Wed Oct 8 08:03:00 EDT 2014: cited below ([https://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/2014-October/002627.html](https://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/2014-October/002627.html)):

I have used both the notch filter and cHPI\_filter approach provided by MNE but as you can see in the figures attached it does result in some distortions. I would like to try the approach Donald Kreiger suggests below and deal with the noise by (1) performing a Fourier transform, (2) attenuating the coefficients of the two frequencies, and (3) reconstructing the modified signal with an inverse Fourier transform. I have attached the results

My question is as follows: 1)is there a good reason not to try this approach 2) Is there a way to implement it natively and easily within men python?

Many thanks in advance for your kind attention

//david

P.s.  
attachments of PSD plots of meg channels raw, filtered with notch filter and with cHPI filter function  
code to generate filters:  
for cHPI\_filter:  
raw\_cHPI=mne.chpi.filter\_chpi(raw,include\_line=True)  
for notch\_filter:  
notches = np.arange(60, 181, 60),  
raw\_notch=raw.notch\_filter(notches)

[Mne\_analysis] 50Hz artefact for time frequency analysis

Krieger, Donald N. kriegerd at upmc.edu? \<mailto:mne\_analysis%40nmr.mgh.harvard.edu?Subject=Re:%20%5BMne\_analysis%5D%2050Hz%20artefact%20for%20time%20frequency%20analysis&In-Reply-To=%3C7FC4F062F840C344B5028EE833EEEADD131E2928%[40MSXMBXNSPRD12.acct.upmchs.net](http://40MSXMBXNSPRD12.acct.upmchs.net)%3E\>  
Wed Oct 8 08:03:00 EDT 2014  
Previous message: [Mne\_analysis] 50Hz artefact for time frequency analysis \<[https://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/2014-October/002626.html](https://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/2014-October/002626.html)\>  
Next message: [Mne\_analysis] 50Hz artefact for time frequency analysis \<[https://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/2014-October/002628.html](https://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/2014-October/002628.html)\>  
Messages sorted by: [date] \<[https://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/2014-October/date.html#2627](https://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/2014-October/date.html#2627)\> [thread] \<[https://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/2014-October/thread.html#2627](https://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/2014-October/thread.html#2627)\> [subject] \<[https://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/2014-October/subject.html#2627](https://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/2014-October/subject.html#2627)\> [author] \<[https://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/2014-October/author.html#2627](https://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/2014-October/author.html#2627)\> Search archives:  
Hi Elisabeth,

As someone else pointed out, your 50 Hz is almost certainly from the mains power.  
That is almost surely the source of the 150 Hz also.  
Noise from this source have the properties that (1) the frequency is very stable and (2) the amplitude is almost always also very stable.  
Because of these properties, this type of noise it typically best removed by measuring its amplitude and phase over a fairly long period, say a second or more, and then subtracting it off. This approach is typically very precise at remove the line noise while leaving any 50 and 150 Hz activity which is not constant in the signal.  
One way it can be done is by (1) performing a Fourier transform, (2) attenuating the coefficients of the two frequencies, and (3) reconstructing the modified signal with an inverse Fourier transform.  
This is likely a better approach than convolution with a notch filter since it explicitly uses the "constant amplitude" property of this noise.  
If the tools are readily available in mne-python, it might be worthwhile to try before chasing the low frequency noise you mentioned.

One other thing to consider is whether it is actually necessary to remove the noise at all.  
If the method you plan to use to explore the gamma band activity has high spectral resolution, the line noise may just show up as sharp peaks which you can ignore.  
On the other hand, if your method has low spectral resolution, it definitely is worthwhile and likely it will make sense to use some high resolution spectral method to assess whether the spectrum is adequately smooth across the two line noise peaks.

Finally it might be worthwhile to check a few data samples from other runs to see if line noise is consistently showing up on those same channels. If so, it's likely that the noise pickup is due to loss of proper "balance" by the amplifiers or to degradation in the connections which run to those amplifiers.

Regards,

Don

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [October 6, 2017, 12:57pm UTC](https://mne.discourse.group/t/50hz-artefact-for-time-frequency-analysis-disarmed/1328/2 "2017-10-06T12:57:38Z")

</div>

Hi David,

Did you happen to record a powerline signal with a separate electrode?

In that case you can very cleanly regress the powerline noise out of the other electrodes in the time domain without it affecting the signal in any other way. That'd be better then applying filters or attenuating fourier coefficients.

Best,

Kris

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [October 6, 2017, 1:30pm UTC](https://mne.discourse.group/t/50hz-artefact-for-time-frequency-analysis-disarmed/1328/3 "2017-10-06T13:30:28Z")

</div>

> My question is as follows: 1)is there a good reason not to try this approach

The reason for not to try this approach is that what your are  
proposing is equivalent to applying a brick wall filter. This will  
cause a lot of ringing.

See this link for more details:

> <https://dsp.stackexchange.com/questions/6220/why-is-it-a-bad-idea-to-filter-by-zeroing-out-fft-bins>

Alejandro

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [October 6, 2017, 2:51pm UTC](https://mne.discourse.group/t/50hz-artefact-for-time-frequency-analysis-disarmed/1328/4 "2017-10-06T14:51:58Z")

</div>

HI Alejandro,

Thank you for responding, and please forgive my signal processing ignorance in my following reply.

I read the comment below realize that this would be true for zeroing out this frequency but could I not replace the existing 60HZ coefficient with lets say the average power values of the59hz and 61Hz and reconstitute the wave without a heaving ringing?

Also say the data is decomposed using 1Hz frequency bins , but in the end I will only need to conduct time-frequncy analysis and 2Hz resolution, can i not spectral decompose the data at 1Hz and reconstitute it just using a 2Hz bin resolution?

thanks david  
David I. Leitman PhD

Visiting Scientist,  
PSYR2 - Psychiatric disorders: from Resistance to Response  
Centre de Recherche en Neurosciences de Lyon (CRNL) INSERM-CNRS

E. david.leitman at [ext.inserm.fr](http://ext.inserm.fr)  
Web. [davidileitman.com](http://davidileitman.com)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [October 6, 2017, 2:53pm UTC](https://mne.discourse.group/t/50hz-artefact-for-time-frequency-analysis-disarmed/1328/5 "2017-10-06T14:53:48Z")

</div>

Hi Kris, I do not think so but I will check. I fear however, that this noise may becoming from the Elekta HPI coils 🙂

David I. Leitman PhD

Visiting Scientist,  
PSYR2 - Psychiatric disorders: from Resistance to Response  
Centre de Recherche en Neurosciences de Lyon (CRNL) INSERM-CNRS

E. david.leitman at [ext.inserm.fr](http://ext.inserm.fr)  
Web. [davidileitman.com](http://davidileitman.com)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [October 6, 2017, 5:00pm UTC](https://mne.discourse.group/t/50hz-artefact-for-time-frequency-analysis-disarmed/1328/6 "2017-10-06T17:00:21Z")

</div>

> I read the comment below realize that this would be true for zeroing out  
> this frequency but could I not replace the existing 60HZ coefficient with  
> lets say the average power values of the59hz and 61Hz and reconstitute the  
> wave without a heaving ringing?

Any nonzero coeficient at the 60Hz will translate in a 60Hz component  
in the time domain. So I thing that will not work.

> Also say the data is decomposed using 1Hz frequency bins , but in the end I  
> will only need to conduct time-frequncy analysis and 2Hz resolution, can i  
> not spectral decompose the data at 1Hz and reconstitute it just using a 2Hz  
> bin resolution?

I don't quite understand what you're saying. But I don't think that  
changing the frequency resolution will help you to reduce the 60Hz  
component.

However, I think you may get less distortion if you try with a smaller  
order filter. You can control that with the `filter_length` parameter.  
You can also try to see what happens with `method='spectrum_fit'` .

Alejandro
