Shortcuts

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 separately by Yu et al. [Yu and Fazekas, 2023] and Forgione et al. [Forgione and Piga, 2021]. The gradients of a_coeffs are computed based on a faster algorithm from [Yu et al., 2024].

This feature supports the following devices: CPU, CUDA This API supports the following properties: Autograd, TorchScript

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 to num_filters. The output can be expressed as output[..., 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 and b_coeffs are 2D Tensors, or (…, time) otherwise.

Return type:

Tensor

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources