neurodsp.filt.filter_signal_iir

neurodsp.filt.filter_signal_iir(sig, fs, pass_type, f_range, butterworth_order, print_transitions=False, plot_properties=False, return_filter=False)[source]

Apply an IIR filter to a signal.

Parameters
sigarray

Time series to be filtered.

fsfloat

Sampling rate, in Hz.

pass_type{‘bandpass’, ‘bandstop’, ‘lowpass’, ‘highpass’}

Which kind of filter to apply:

  • ‘bandpass’: apply a bandpass filter

  • ‘bandstop’: apply a bandstop (notch) filter

  • ‘lowpass’: apply a lowpass filter

  • ‘highpass’ : apply a highpass filter

f_rangetuple of (float, float) or float

Cutoff frequency(ies) used for filter, specified as f_lo & f_hi. For ‘bandpass’ & ‘bandstop’, must be a tuple. For ‘lowpass’ or ‘highpass’, can be a float that specifies pass frequency, or can be a tuple and is assumed to be (None, f_hi) for ‘lowpass’, and (f_lo, None) for ‘highpass’.

butterworth_orderint

Order of the butterworth filter, if using an IIR filter. See input ‘N’ in scipy.signal.butter.

print_transitionsbool, optional, default: False

If True, print out the transition and pass bandwidths.

plot_propertiesbool, optional, default: False

If True, plot the properties of the filter, including frequency response and/or kernel.

return_filterbool, optional, default: False

If True, return the second order series coefficients of the IIR filter.

Returns
sig_filt1d array

Filtered time series.

sos2d array

Second order series coefficients of the IIR filter. Has shape of (n_sections, 6). Only returned if return_filter is True.

Examples

Apply a bandstop IIR filter to a simulated signal:

>>> from neurodsp.sim import sim_combined
>>> sig = sim_combined(n_seconds=10, fs=500,
...                    components={'sim_powerlaw': {}, 'sim_oscillation' : {'freq': 10}})
>>> filt_sig = filter_signal_iir(sig, fs=500, pass_type='bandstop',
...                              f_range=(55, 65), butterworth_order=7)