mne.filter.
construct_iir_filter
(iir_params, f_pass=None, f_stop=None, sfreq=None, btype=None, return_copy=True)[source]¶Use IIR parameters to get filtering coefficients.
This function works like a wrapper for iirdesign and iirfilter in scipy.signal to make filter coefficients for IIR filtering. It also estimates the number of padding samples based on the filter ringing. It creates a new iir_params dict (or updates the one passed to the function) with the filter coefficients (‘b’ and ‘a’) and an estimate of the padding necessary (‘padlen’) so IIR filtering can be performed.
Note
As of 0.14, second-order sections will be used in filter
design by default (replacing output='ba'
by
output='sos'
) to help ensure filter stability and
reduce numerical error. Second-order sections filtering
requires SciPy >= 16.0.
Parameters: | iir_params : dict
f_pass : float or list of float
f_stop : float or list of float
sfreq : float | None
btype : str
return_copy : bool
|
---|---|
Returns: | iir_params : dict
|
See also
Notes
This function triages calls to scipy.signal.iirfilter()
and
scipy.signal.iirdesign()
based on the input arguments (see
linked functions for more details).
Examples
iir_params can have several forms. Consider constructing a low-pass filter at 40 Hz with 1000 Hz sampling rate.
In the most basic (2-parameter) form of iir_params, the order of the filter ‘N’ and the type of filtering ‘ftype’ are specified. To get coefficients for a 4th-order Butterworth filter, this would be:
>>> iir_params = dict(order=4, ftype='butter', output='sos')
>>> iir_params = construct_iir_filter(iir_params, 40, None, 1000, 'low', return_copy=False)
>>> print((2 * len(iir_params['sos']), iir_params['padlen']))
(4, 82)
Filters can also be constructed using filter design methods. To get a 40 Hz Chebyshev type 1 lowpass with specific gain characteristics in the pass and stop bands (assuming the desired stop band is at 45 Hz), this would be a filter with much longer ringing:
>>> iir_params = dict(ftype='cheby1', gpass=3, gstop=20, output='sos')
>>> iir_params = construct_iir_filter(iir_params, 40, 50, 1000, 'low')
>>> print((2 * len(iir_params['sos']), iir_params['padlen']))
(6, 439)
Padding and/or filter coefficients can also be manually specified. For a 10-sample moving window with no padding during filtering, for example, one can just do:
>>> iir_params = dict(b=np.ones((10)), a=[1, 0], padlen=0)
>>> iir_params = construct_iir_filter(iir_params, return_copy=False)
>>> print((iir_params['b'], iir_params['a'], iir_params['padlen']))
(array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]), [1, 0], 0)
For more information, see the tutorials Background information on filtering and Filtering and resampling data.