braindecode.preprocessing.NotchFilter#
- class braindecode.preprocessing.NotchFilter(freqs, picks=None, filter_length='auto', notch_widths=None, trans_bandwidth=1.0, n_jobs=None, method='fir', iir_params=None, mt_bandwidth=None, p_value=0.05, phase='zero', fir_window='hamming', fir_design='firwin', pad='reflect_limited', skip_by_annotation=('edge', 'bad_acq_skip'), verbose=None)[source]#
Braindecode preprocessor wrapper for
notch_filter().Notch filter a subset of channels.
- Parameters:
- freqsfloat | array of float | None
Specific frequencies to filter out from data, e.g.,
np.arange(60, 241, 60)in the US ornp.arange(50, 251, 50)in Europe.Nonecan only be used with the mode'spectrum_fit', where an F test is used to find sinusoidal components.- picksstr | array-like | slice | None
Channels to include. Slices and lists of integers will be interpreted as channel indices. In lists, channel type strings (e.g.,
['meg', 'eeg']) will pick channels of those types, channel name strings (e.g.,['MEG0111', 'MEG2623']will pick the given channels. Can also be the string values'all'to pick all channels, or'data'to pick data channels. None (default) will pick all data channels. Note that channels ininfo['bads']will be included if their names or indices are explicitly provided.- 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 forphase="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. Seemne.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 each stop band (centred at each freq in freqs) in Hz. If None,
freqs / 200is used.- trans_bandwidthfloat
Width of the transition band in Hz. Only used for
method='fir'andmethod='iir'.- n_jobsint | str
Number of jobs to run in parallel. Can be
'cuda'ifcupyis installed properly andmethod='fir'.- methodstr
'fir'will use overlap-add FIR filtering,'iir'will use IIR forward-backward filtering (viafiltfilt()).- iir_paramsdict | None
Dictionary of parameters to use for IIR filtering. If
iir_params=Noneandmethod="iir", 4th order Butterworth will be used. For more information, seemne.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'andfreqs=None. Note that this will be Bonferroni corrected for the number of frequencies, so large p-values may be justified.- phasestr
Phase of the filter. When
method='fir', symmetric linear-phase FIR filters are constructed with the following behaviors whenmethod="fir":"zero"(default)The delay of this filter is compensated for, making it non-causal.
"minimum"A minimum-phase filter will be constructed by decomposing the zero-phase filter into a minimum-phase and all-pass systems, and then retaining only the minimum-phase system (of the same length as the original zero-phase filter) via
scipy.signal.minimum_phase()."zero-double"This is a legacy option for compatibility with MNE <= 0.13. The filter is applied twice, once forward, and once backward (also making it non-causal).
"minimum-half"This is a legacy option for compatibility with MNE <= 1.6. A minimum-phase filter will be reconstructed from the zero-phase filter with half the length of the original filter.
When
method='iir',phase='zero'(default) or equivalently'zero-double'constructs and applies IIR filter twice, once forward, and once backward (making it non-causal) usingfiltfilt();phase='forward'will apply the filter once in the forward (causal) direction usinglfilter().Added in version 0.13.
Changed in version 1.7: The behavior for
phase="minimum"was fixed to use a filter of the requested length and improved suppression.- fir_windowstr
The window to use in FIR design, can be “hamming” (default), “hann” (default in 0.13), or “blackman”.
Added in version 0.15.
- fir_designstr
Can be “firwin” (default) to use
scipy.signal.firwin(), or “firwin2” to usescipy.signal.firwin2(). “firwin” uses a time-domain design technique that generally gives improved attenuation using fewer samples than “firwin2”.Added in version 0.15.
- padstr
The type of padding to use. Supports all
numpy.pad()modeoptions. 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 formethod='fir'. The default is'reflect_limited'.Added in version 0.15.
- skip_by_annotationstr | list of str
If a string (or list of str), any annotation segment that begins with the given string will not be included in filtering, and segments on either side of the given excluded annotated segment will be filtered separately (i.e., as independent signals). The default (
('edge', 'bad_acq_skip')will separately filter any segments that were concatenated bymne.concatenate_raws()ormne.io.Raw.append(), or separated during acquisition. To disable, provide an empty list. Only used ifinstis raw.- verbosebool | str | int | None
Control verbosity of the logging output. If
None, use the default verbosity level. See the logging documentation andmne.verbose()for details. Should only be passed as a keyword argument.
- Returns:
- rawinstance of Raw
The raw instance with filtered data.
See also
Notes
Applies a zero-phase notch filter to the channels selected by “picks”. By default the data of the Raw object is modified inplace.
The Raw object has to have the data loaded e.g. with
preload=Trueorself.load_data().Note
If n_jobs > 1, more memory is required as
len(picks) * n_timesadditional time points need to be temporarily stored in memory.For details, see
mne.filter.notch_filter().