How to filter harmonics?

Hi all,

Is there a way in MNE to do the opposite of notch-filtering so as to filter
out everything but the line noise and its harmonics?

I'm typically trying to filter the signals so as to only keep the 60, 120,
180, 240 Hz frequency bands.

Thanks!

JR
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20160323/fc6bb2fa/attachment.html

Hi JR,

what about:
bandpass: 55: 245, plus notch filters for the other gaps

d

Thanks!

For the record I did:

noise_freq = 60. # US line noise
width = 2. # notch widh in Hz

# harmonics until nquist
n_harm = raw.info['sfreq'] // (2. * noise_freq) + 1

# band pass first to last harmonics
harmonics = noise_freq * np.arange(1, n_harm)
raw.filter(noise_freq - width, harmonics[-1] + width)

# band stop filter in between harmonics (it's not really a notch, since the
freq width is very large)
raw.notch_filter(freqs=harmonics[:-1]+noise_freq//2,
notch_widths=noise_freq - 2*width)

JR

Hi all,
     I've also been trying to figure out filtering, and getting a bit stuck
on what to do with the result of such. If I follow along above and then do
something like:

filtered_data = raw.notch_filter(freqs=harmonics[:-1]+noise_freq//2,
notch_widths=noise_freq - 2*width)

I can't treat the result like a raw RawFIF, and if I ask python

type(filtered_data)
NoneType

So how does one use (say, plot) such a result?

Thanks!
Megan

MEG Technician
The Mind Research Network
1101 Yale Blvd. NE
Albuquerque, New Mexico 87106
505-272-3304

raw.filter() operates inplace (and doesn't return anything, which is why
you get None as a result), so your raw object is now filtered.

You can use raw_2 = raw.copy(), raw_2.filter(...) if you don't want to
modify your original raw instance.

Eric

Okay. I see: the above replaces raw with the filtered data.

Thanks!
Megan

MEG Technician
The Mind Research Network
1101 Yale Blvd. NE
Albuquerque, New Mexico 87106
505-272-3304

Hi Megan,

Just to follow up on this, we just added the copy param to raw.filter(),
which is now available on the dev branch. The behavior now is when
`copy=False` (default), it returns `self`. When `copy=False` it will allow
for you to assign to the same name as you did, also you can choose not
assign it and the raw file will be modified in-place.

https://github.com/mne-tools/mne-python/pull/3077

HTH,

teon

Hi Teon,
Cool, thanks for the update!
Megan

MEG Technician
The Mind Research Network
1101 Yale Blvd. NE
Albuquerque, New Mexico 87106
505-272-3304