neurodsp.filt.utils.compute_frequency_response

neurodsp.filt.utils.compute_frequency_response(filter_coefs, a_vals, fs)[source]

Compute the frequency response of a filter.

Parameters
filter_coefs1d or 2d array

If 1d, interpreted as the B-value filter coefficients. If 2d, interpreted as the second-order (sos) filter coefficients.

a_vals1d array or None

The A-value filter coefficients for a filter. If second-order filter coefficients are provided in filter_coefs, must be None.

fsfloat

Sampling rate, in Hz.

Returns
f_db1d array

Frequency vector corresponding to attenuation decibels, in Hz.

db1d array

Degree of attenuation for each frequency specified in f_db, in dB.

Examples

Compute the frequency response for an FIR filter:

>>> from neurodsp.filt.fir import design_fir_filter
>>> filter_coefs = design_fir_filter(fs=500, pass_type='bandpass', f_range=(8, 12))
>>> f_db, db = compute_frequency_response(filter_coefs, 1, fs=500)

Compute the frequency response for an IIR filter, which uses SOS coefficients:

>>> from neurodsp.filt.iir import design_iir_filter
>>> sos_coefs = design_iir_filter(fs=500, pass_type='bandpass',
...                               f_range=(8, 12), butterworth_order=3)
>>> f_db, db = compute_frequency_response(sos_coefs, None, fs=500)