mne.filter.notch_filter#

mne.filter.notch_filter(x, Fs, freqs, filter_length='auto', notch_widths=None, trans_bandwidth=1, method='fir', iir_params=None, mt_bandwidth=None, p_value=0.05, picks=None, n_jobs=1, copy=True, phase='zero', fir_window='hamming', fir_design='firwin', pad='reflect_limited', verbose=None)[source]#

Notch filter for the signal x.

Applies a zero-phase notch filter to the signal x, operating on the last dimension.

Parameters
xarray

Signal to filter.

Fsfloat

Sampling rate in Hz.

freqsfloat | array of float | None

Frequencies to notch filter in Hz, e.g. np.arange(60, 241, 60). None can only be used with the mode ‘spectrum_fit’, where an F test is used to find sinusoidal components.

filter_lengthstr | int

Length of the FIR filter to use (if applicable):

  • ‘auto’ (default): The filter length is chosen based on the size of the transition regions (6.6 times the reciprocal of the shortest transition band for fir_window=’hamming’ and fir_design=”firwin2”, and half that for “firwin”).

  • str: A human-readable time in units of “s” or “ms” (e.g., “10s” or “5500ms”) will be converted to that number of samples if phase="zero", or the shortest power-of-two length at least that duration for phase="zero-double".

  • int: Specified length in samples. For fir_design=”firwin”, this should not be used.

When method=='spectrum_fit', this sets the effective window duration over which fits are computed. See mne.filter.create_filter() for options. Longer window lengths will give more stable frequency estimates, but require (potentially much) more processing and are not able to adapt as well to non-stationarities.

The default in 0.21 is None, but this will change to '10s' in 0.22.

notch_widthsfloat | array of float | None

Width of the stop band (centred at each freq in freqs) in Hz. If None, freqs / 200 is used.

trans_bandwidthfloat

Width of the transition band in Hz. Only used for method='fir'.

methodstr

‘fir’ will use overlap-add FIR filtering, ‘iir’ will use IIR forward-backward filtering (via filtfilt). ‘spectrum_fit’ will use multi-taper estimation of sinusoidal components. If freqs=None and method=’spectrum_fit’, significant sinusoidal components are detected using an F test, and noted by logging.

iir_paramsdict | None

Dictionary of parameters to use for IIR filtering. If iir_params is None and method=”iir”, 4th order Butterworth will be used. For more information, see mne.filter.construct_iir_filter().

mt_bandwidthfloat | None

The bandwidth of the multitaper windowing function in Hz. Only used in ‘spectrum_fit’ mode.

p_valuefloat

P-value to use in F-test thresholding to determine significant sinusoidal components to remove when method=’spectrum_fit’ and freqs=None. Note that this will be Bonferroni corrected for the number of frequencies, so large p-values may be justified.

pickslist | slice | None

Channels to include. Slices and lists of integers will be interpreted as channel indices. None (default) will pick all channels. Note that channels in info['bads'] will be included if their indices are explicitly provided. Only supported for 2D (n_channels, n_times) and 3D (n_epochs, n_channels, n_times) data.

n_jobsint | str

Number of jobs to run in parallel. Can be ‘cuda’ if cupy is installed properly and method=’fir’.

copybool

If True, a copy of x, filtered, is returned. Otherwise, it operates on x in place.

phasestr

Phase of the filter, only used if method='fir'. Symmetric linear-phase FIR filters are constructed, and if phase='zero' (default), the delay of this filter is compensated for, making it non-causal. If phase='zero-double', then this filter is applied twice, once forward, and once backward (also making it non-causal). If 'minimum', then a minimum-phase filter will be constricted and applied, which is causal but has weaker stop-band suppression.

New in version 0.13.

fir_windowstr

The window to use in FIR design, can be “hamming” (default), “hann” (default in 0.13), or “blackman”.

New in version 0.15.

fir_designstr

Can be “firwin” (default) to use scipy.signal.firwin(), or “firwin2” to use scipy.signal.firwin2(). “firwin” uses a time-domain design technique that generally gives improved attenuation using fewer samples than “firwin2”.

New in version 0.15.

padstr

The type of padding to use. Supports all numpy.pad() mode options. Can also be "reflect_limited", which pads with a reflected version of each vector mirrored on the first and last values of the vector, followed by zeros.

Only used for method='fir'. The default is 'reflect_limited'.

verbosebool | str | int | None

Control verbosity of the logging output. If None, use the default verbosity level. See the logging documentation and mne.verbose() for details. Should only be passed as a keyword argument.

Returns
xfarray

The x array filtered.

Notes

The frequency response is (approximately) given by:

  1-|----------         -----------
    |          \       /
|H| |           \     /
    |            \   /
    |             \ /
  0-|              -
    |         |    |    |         |
    0        Fp1 freq  Fp2       Nyq

For each freq in freqs, where Fp1 = freq - trans_bandwidth / 2 and Fs2 = freq + trans_bandwidth / 2.

References

Multi-taper removal is inspired by code from the Chronux toolbox, see www.chronux.org and the book “Observed Brain Dynamics” by Partha Mitra & Hemant Bokil, Oxford University Press, New York, 2008. Please cite this in publications if method ‘spectrum_fit’ is used.