def lfilter0(b, a, x, axis=0):
"""Filter data with an IIR or FIR filter with zero DC group delay.
:func:`scipy.signal.lfilter` provides a way to filter a signal `x` using a FIR/IIR
filter defined by `b` and `a`. The resulting output is delayed, as compared to the
input by the group delay. This function corrects for the group delay, resulting in
an output that is synchronized with the input signal. If the filter as an acausal
impulse response, some precursor signal from the output will be lost. To avoid this,
pad input signal `x` with sufficient zeros at the beginning to capture the precursor.
Since both, :func:`scipy.signal.lfilter` and this function return a signal with the
same length as the input, some signal tail is lost at the end. To avoid this, pad
input signal `x` with sufficient zeros at the end.
See documentation for :func:`scipy.signal.lfilter` for more details.
>>> import arlpy
>>> import numpy as np
>>> fs = 250000
>>> b = arlpy.uwa.absorption_filter(fs, distance=500)
>>> x = np.pad(arlpy.signal.sweep(20000, 40000, 0.5, fs), (127, 127), 'constant')
>>> y = arlpy.signal.lfilter0(b, 1, x)
"""
w, g = _sig.group_delay((b, a))
ndx = _np.argmin(_np.abs(w))
d = int(round(g[ndx]))
x = _np.pad(x, (0, d), 'constant')
y = _sig.lfilter(b, a, x, axis)[d:]
return y
评论列表
文章目录