I want to remove AC noise

MNE version: 1.0.3
OS: macOS Monterey

Hello.

I am trying to measure event-related potentials.
Preliminary experiments have shown that there is too much AC noise, so I am thinking of removing it.
What code should I write to remove it?

Thank you in advance for your help.

what is AC noise ? you mean line noise?

can you show the PSD of your data?

Alex

Thank you for your reply.

It is about the line noise. I wrote AC noise because I think it is caused by AC power supply.
I am wondering how to write the code to remove this in MNEPython.

Sorry for being a beginner.
What do you mean by PSD?

Sorry for the lack of explanation.
Thank you in advance.

PSD = Power Spectral Density. Let’s start by confirming that your data is contaminated by powerline noise, 50 Hz in Europe, 60 Hz in the US (and I don’t know elsewhere).

Could you load your data into a Raw object (see the Loading Data section of the first tutorial: Overview of MEG/EEG analysis with MNE-Python — MNE 1.1.1 documentation) and then use the plot_psd method to display the PSD?

Link: mne.io.Raw — MNE 1.1.1 documentation
Code snippet:

from mne.io import read_raw


raw = read_raw(fname, preload=True)  # where fname is the path to your compatible file
raw.plot_psd()
1 Like

Thank you for your reply.
Sorry for the delay in responding.

In my area the power supply noise is considered 50Hz.

I ran it on the raw data and the following figure was output.

As you can see, there is no powerline noise. You do not have a peak at 50 Hz or 60 Hz.
Also, the dataset seems to be bandpass filtered between 1 and 20 Hz. The peak at 20 Hz looks weird to me.

Could you do the same plot on the raw data before BP filter?

Thank you for your reply.

As you can see, the data was after filtering.
Here are the results plotted with the data before filtering.

I have no idea what can cause noise at 20 Hz. If someone know, I’m very curious.
Anyway, you can apply a notch for 20 Hz and the harmonics. This way, you will also be able to increase your BP upper limit to more than 20 Hz if you want:

import numpy as np


raw = [...]  # load data
raw.notch_filter(np.arange(20, 120, 20))

Thank you for your reply.

Filtering at every 20 Hz resulted in the figure.
I think I have lowered it more than necessary, but is it OK?

That’s what a filter does, it looks OK. I prefer to avoid using notch filters, but I don’t see another solution in your case.
Alternatively, you should figure out where this noise is coming from, remove the source, and record clean data.

I understand.
Thank you for your kind .

One thing to check is if the sampling frequency was somehow mis-specified, so that interference at 50 Hz was showing up as if it were 20 Hz. I don’t know how this would have happened though so it’s a wild guess.

Another possibility is that it’s a coming from equipment in an adjacent lab in the same building. I’ve seen this once, it was coming through on an audio recording in a sound-attenuated booth. It was a timing signal for some custom physics equipment, and it was exactly 1kHz. (at 20 Hz this is almost surely not a timing signal :slight_smile: but may still be caused by nearby equipment)

1 Like