filtering.filter_data#
- autoclean.functions.preprocessing.filtering.filter_data(data, l_freq=None, h_freq=None, notch_freqs=None, notch_widths=0.5, method='fir', phase='zero', fir_window='hamming', verbose=None)[source]#
Filter EEG data using highpass, lowpass, and/or notch filtering.
This function applies digital filtering to continuous (Raw) or epoched EEG data. It supports highpass filtering to remove slow drifts, lowpass filtering to remove high-frequency noise, and notch filtering to remove line noise at specific frequencies (e.g., 50/60 Hz power line interference).
The function automatically detects the input data type and preserves it, returning the same type (Raw or Epochs) with identical structure but filtered time series data.
- Parameters:
- data
mne.io.BaseRaw
ormne.Epochs
The EEG data to filter. Can be any MNE Raw object (e.g., RawFIF, RawEEGLAB, etc.) or Epochs object.
- l_freq
float
orNone
,default
None
Low cutoff frequency for highpass filtering in Hz. If None, no highpass filtering is applied. Typical values: 0.1-1.0 Hz for removing slow drifts.
- h_freq
float
orNone
,default
None
High cutoff frequency for lowpass filtering in Hz. If None, no lowpass filtering is applied. Typical values: 30-100 Hz for removing high-frequency noise.
- notch_freqs
list
offloat
orNone
,default
None
Frequencies to notch filter in Hz. If None, no notch filtering is applied. Common values: [50] or [60] for power line noise, [50, 100, 150] for harmonics.
- notch_widths
float
orlist
offloat
,default
0.5 Width of the notch filter in Hz. If float, same width applied to all frequencies in notch_freqs. If list, must match length of notch_freqs. Wider notches remove more surrounding frequencies.
- method
str
,default
‘fir’ Filtering method. ‘fir’ uses finite impulse response (linear phase), ‘iir’ uses infinite impulse response (faster but can introduce artifacts).
- phase
str
,default
‘zero’ Phase of the filter. ‘zero’ for zero-phase (no delay), ‘zero-double’ for zero-phase with double filtering, ‘minimum’ for minimum phase.
- fir_window
str
,default
‘hamming’ Window function for FIR filter design. Options: ‘hamming’, ‘hann’, ‘blackman’. Affects filter characteristics and artifacts.
- verbosebool or
None
,default
None
Control verbosity of output. If None, uses MNE default.
- data
- Returns:
- filtered_data
mne.io.BaseRaw
ormne.Epochs
The filtered data object, same type as input. Contains identical structure and metadata but with filtered time series data.
- filtered_data
See also
mne.io.Raw.filter
MNE’s raw data filtering method
mne.Epochs.filter
MNE’s epochs filtering method
mne.io.Raw.notch_filter
MNE’s notch filtering for raw data
mne.Epochs.notch_filter
MNE’s notch filtering for epochs
Examples
>>> filtered_raw = filter_data(raw, l_freq=1.0, h_freq=40.0) >>> filtered_raw = filter_data(raw, notch_freqs=[60]) >>> bandpass_data = filter_data(raw, l_freq=8.0, h_freq=12.0)