[Mne_analysis] Low pass filtering questions

Eric Larson larson.eric.d at gmail.com
Tue Mar 26 16:57:32 EDT 2013
Search archives:

Don (et. al),

As suggested by Alex, here's some empirical data. Let's make some pure
tones in the passband (37.5 Hz) and stopband (42.5) in mne-python using the
testing dataset raw file as an example:

>>> import mne
>>> import numpy as np
>>> raw = mne.fiff.Raw('test.fif', preload=True)
>>> raw._data[0] = 1e-10 * np.sin(2 * np.pi * 37.5 *
np.arange(raw._data.shape[1]) / raw.info['sfreq'])
>>> raw._data[1] = 1e-10 * np.sin(2 * np.pi * 42.5 *
np.arange(raw._data.shape[1]) / raw.info['sfreq'])
>>> raw.save('test_sin_raw.fif')

at a shell, let's do the lowpass you're interested in (lowpasses by
default):

$ mne_process_raw --raw test_sin_raw.fif --save test_sin_lp_raw.fif
--projoff

Back in Python, let's see what happened to the RMS of our signals:

>>> raw = mne.fiff.Raw('test_sin_raw.fif', preload=True)
>>> raw_lp = mne.fiff.Raw('test_sin_lp_raw.fif', preload=True)
>>> np.sqrt(np.mean(raw_lp._data[0] ** 2))  # expect close to 7.07e-11
7.0629870812673256e-11
>>> np.sqrt(np.mean(raw_lp._data[1] ** 2))  # expect closer to zero
1.6152302769536156e-12
>>> 20 * np.log10(np.sqrt(np.mean(raw._data[0] ** 2)) /
np.sqrt(np.mean(raw_lp._data[0] ** 2)))
0.0095603499577439008
>>> 20 * np.log10(np.sqrt(np.mean(raw._data[1] ** 2)) /
np.sqrt(np.mean(raw_lp._data[1] ** 2)))
32.825155846953265

So, that would be ~0dB attenuation in the passbard (37.5 Hz) and 32 dB of
attenuation at the stop band (42.5 Hz). I also did 45 and 47.5 Hz offline,
and got 35 and 37 dB of attenuation, respectively.

Cheers,
Eric



On Tue, Mar 26, 2013 at 1:08 PM, Alexandre Gramfort <
gramfort at nmr.mgh.harvard.edu> wrote:

> hi Donald,
>
> if you want to experiment with this you can run the PSD estimation on
> raw data before
> and after filtering as in :
>
>
> http://martinos.org/mne/auto_examples/time_frequency/plot_compute_raw_data_spectrum.html#example-time-frequency-plot-compute-raw-data-spectrum-py
>
> you'll see how many dB you loose at 42.5Hz.
>
> Alex
>
>
>
> On Tue, Mar 26, 2013 at 8:16 PM, Krieger, Donald N. <kriegerd at upmc.edu>
> wrote:
> > Thank you for continuing to try to address this question.
> >
> > Please pardon my asking for clarification.
> >
> > My question boils down to this: If I use the standalone mne_process_raw
> and use the standard filter settings of 40 Hz with 5 Hz dropoff, is
> everything above 42.5 Hz cut to zero?
> >
> > Thanks,
> >
> > Don
> >
> > Don Krieger, Ph.D.
> > Department of Neurological Surgery
> > University of Pittsburgh
> > (412)648-9654 Office
> > (412)521-4431 Cell/Text
> >
> >
> > -----Original Message-----
> > From: mne_analysis-bounces at nmr.mgh.harvard.edu [mailto:
> mne_analysis-bounces at nmr.mgh.harvard.edu] On Behalf Of Hari Bharadwaj
> > Sent: Tuesday, March 26, 2013 2:31 PM
> > To: Martin Luessi
> > Cc: mne_analysis at nmr.mgh.harvard.edu
> > Subject: Re: [Mne_analysis] Low pass filtering questions
> > Importance: High
> >
> > Thanks! I should apologize for being too lazy to look at the C code.
> >
> > Regards,
> > Hari
> >
> >
> > On Tue, March 26, 2013 9:36 am, Martin Luessi wrote:
> >> Hari,
> >>
> >> Please excuse the long silence. In the C code, method (1) is used, i.e.,
> >> the filter is designed in the freq. domain with smooth transitions at
> >> the corner frequencies (using a cosine). In MNE-Python on the other hand
> >> method (2) is used. It can use both IIR or FIR filters, the FIR filters
> >> are designed using
> >>
> >>
> http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.firwin2.html
> >>
> >> the actual implementation uses an overlap-add FFT applied in forward and
> >> backward direction to get zero phase (like filtfilt, as you mentioned).
> >>
> >> I hope this helps,
> >>
> >> Martin
> >>
> >> On 03/14/13 14:08, Hari Bharadwaj wrote:
> >>> Hi Don, Alex and Matti,
> >>>      Not to introduce any more confusion but I have a clarification
> >>> question:
> >>> Which of the following is true about the C-code?
> >>> (1) The filter is realized in the frequency domain fully (i.e) the FFT
> >>> coefficients for blocks of 2048 time samples are tapered to have a
> >>> transition band of 5 Hz around the cutoff and then going back to time.
> >>> In
> >>> this case, the filter is a non-causal IIR filter with zero-group delay.
> >>>
> >>> (2) An FIR filter is designed first and then then implemented in the
> >>> frequency domain using the overlap-add method with FFT blocks of 2048
> >>> points each. In this case, the filter is FIR and non-causal with
> >>> zero-group delay but there are (small) sidebands extending upto the
> >>> Nyquist rate. This would be like MATLAB's fftfilt().
> >>>
> >>> Thanks,
> >>> Hari
> >>>
> >>>
> >>> On Thu, March 14, 2013 8:45 am, Matti Hamalainen wrote:
> >>>>
> >>>> On Mar 14, 2013, at 8:30 AM, Alexandre Gramfort wrote:
> >>>>
> >>>>> hi Don,
> >>>>>
> >>>>>> Please bear with a further question:
> >>>>>> If the low-pass is set at 40 Hz, then the cos^2 drop off is applied
> >>>>>> beginning at the 40 hz components and falling to zero at 45 ?  Or is
> >>>>>> it
> >>>>>> applied beginning at something like 38 hz so that the fourier
> >>>>>> coefficients are attenuated by a fact of 2 at 40 ?
> >>>>>
> >>>>> I am not 100% about the C code but I bet for 40 to 45 with 0 at 45 Hz
> >>>>>
> >>>>>> And pardon this stupid question: Does this produce a gain of 0.0 for
> >>>>>> all higher frequencies in the filtered signal above 45?  Or is there
> >>>>>> some kind of ringing which occurs?
> >>>>>
> >>>>> it does remove all frequencies about 45Hz up to some numerical errors
> >>>>> and if there is some ringing it will be in time. The less the stop
> >>>>> band (here 5) the more ringing in time domain.
> >>>>
> >>>> Hi Don,
> >>>>
> >>>> In the C code the default width of the lowpass transition is 5 Hz. For
> >>>> 40
> >>>> Hz lowpass this means that the falloff starts at 37.5 Hz and ends at
> >>>> 42.5
> >>>> Hz. You can adjust this value in the mne_browse_raw or with the
> >>>> --lowpassw
> >>>> option in mne_process_raw and mne_browse_raw.
> >>>>
> >>>> The manual tells this in sections 4.5.1 and 4.2.1.
> >>>>
> >>>> - Matti
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> ---------
> >>>>
> >>>> Matti Hamalainen, Ph.D.
> >>>> Athinoula A. Martinos Center for Biomedical Imaging
> >>>> Massachusetts General Hospital
> >>>>
> >>>> msh at nmr.mgh.harvard.edu
> >>>> mhamalainen at partners.org
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> _______________________________________________
> >>>> Mne_analysis mailing list
> >>>> Mne_analysis at nmr.mgh.harvard.edu
> >>>> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
> >>>
> >>>
> >>
> >>
> >> --
> >> Martin Luessi, Ph.D.
> >>
> >> Research Fellow
> >>
> >> Department of Radiology
> >> Athinoula A. Martinos Center for Biomedical Imaging
> >> Massachusetts General Hospital
> >> Harvard Medical School
> >> 149 13th Street
> >> Charlestown, MA 02129
> >>
> >> Fax: +1 617 726-7422
> >>
> >>
> >>
> >
> >
> > --
> > Hari Bharadwaj
> > PhD Candidate, Biomedical Engineering,
> > Boston University
> > 677 Beacon St.,
> > Boston, MA 02215
> >
> > Martinos Center for Biomedical Imaging,
> > Massachusetts General Hospital
> > 149 Thirteenth Street,
> > Charlestown, MA 02129
> >
> > hari at nmr.mgh.harvard.edu
> > Ph: 734-883-5954
> >
> >
> > _______________________________________________
> > Mne_analysis mailing list
> > Mne_analysis at nmr.mgh.harvard.edu
> > https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
> >
> >
> > The information in this e-mail is intended only for the person to whom
> it is
> > addressed. If you believe this e-mail was sent to you in error and the
> e-mail
> > contains patient information, please contact the Partners Compliance
> HelpLine at
> > http://www.partners.org/complianceline . If the e-mail was sent to you
> in error
> > but does not contain patient information, please contact the sender and
> properly
> > dispose of the e-mail.
> >
> >
> >
> > _______________________________________________
> > Mne_analysis mailing list
> > Mne_analysis at nmr.mgh.harvard.edu
> > https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
> _______________________________________________
> Mne_analysis mailing list
> Mne_analysis at nmr.mgh.harvard.edu
> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20130326/84a27cfd/attachment.html 


More information about the Mne_analysis mailing list