torchaudio.functional.lfilter¶
- torchaudio.functional.lfilter(waveform: Tensor, a_coeffs: Tensor, b_coeffs: Tensor, clamp: bool = True, batching: bool = True) Tensor [source]¶
Perform an IIR filter by evaluating difference equation, using differentiable implementation developed independently by Yu et al. [Yu and Fazekas, 2023] and Forgione et al. [Forgione and Piga, 2021].
Note
To avoid numerical problems, small filter order is preferred. Using double precision could also minimize numerical precision errors.
- Parameters:
waveform (Tensor) – audio waveform of dimension of (…, time). Must be normalized to -1 to 1.
a_coeffs (Tensor) – denominator coefficients of difference equation of dimension of either 1D with shape (num_order + 1) or 2D with shape (num_filters, num_order + 1). Lower delays coefficients are first, e.g.
[a0, a1, a2, ...]
. Must be same size as b_coeffs (pad with 0’s as necessary).b_coeffs (Tensor) – numerator coefficients of difference equation of dimension of either 1D with shape (num_order + 1) or 2D with shape (num_filters, num_order + 1). Lower delays coefficients are first, e.g.
[b0, b1, b2, ...]
. Must be same size as a_coeffs (pad with 0’s as necessary).clamp (bool, optional) – If
True
, clamp the output signal to be in the range [-1, 1] (Default:True
)batching (bool, optional) – Effective only when coefficients are 2D. If
True
, then waveform should be at least 2D, and the size of second axis from last should equals tonum_filters
. The output can be expressed asoutput[..., i, :] = lfilter(waveform[..., i, :], a_coeffs[i], b_coeffs[i], clamp=clamp, batching=False)
. (Default:True
)
- Returns:
Waveform with dimension of either (…, num_filters, time) if
a_coeffs
andb_coeffs
are 2D Tensors, or (…, time) otherwise.- Return type:
Tensor