functional.lowpass_filter(gain: float = 0.0, fs: int = 48000, device=None) tuple

Lowpass filter coefficients. It uses the RBJ cookbook formulas to map the cutoff frequency and gain to the filter coefficients to the to the \(\mathbf{b}\) and \(\mathbf{a}\) biquad coefficients. The transfer function of the filter is given by

\[H(z) = \frac{b_0 + b_1 z^{-1} + b_2 z^{-2}}{a_0 + a_1 z^{-1} + a_2 z^{-2}}\]

for

\[b_0 = \frac{1 - \cos(\omega_c)}{2},\;\; b_1 = 1 - \cos(\omega_c),\;\; b_2 = \frac{1 - \cos(\omega_c)}{2}\]
\[a_0 = 1 + \alpha,\;\; a_1 = -2 \cos(\omega_c),\;\; a_2 = 1 - \alpha\]

where \(\omega_c = 2\pi f_c / f_s\), \(\alpha = \sin(\omega_c)/2 \cdot \sqrt{2}\) and \(\cos(\omega_c)\) is the cosine of the cutoff frequency. The gain is applied to the filter coefficients as \(b = 10^{g_{\textrm{dB}}/20} b\).

Args:
  • fc (float): The cutoff frequency of the filter in Hz. Default: 500 Hz.

  • gain (float): The gain of the filter in dB. Default: 0 dB.

  • fs (int): The sampling frequency of the signal in Hz. Default: 48000 Hz.

  • device (torch.device, optional): The device of constructed tensors. Default: None.

Returns:
  • b (ndarray): The numerator coefficients of the filter transfer function.

  • a (ndarray): The denominator coefficients of the filter transfer function.

functional.highpass_filter(gain: float = 0.0, fs: int = 48000, device=None) tuple

Highpass filter coefficients. It uses the RBJ cookbook formulas to map the cutoff frequency and gain to the filter coefficients to the to the \(\mathbf{b}\) and \(\mathbf{a}\) biquad coefficients.

\[H(z) = \frac{b_0 + b_1 z^{-1} + b_2 z^{-2}}{a_0 + a_1 z^{-1} + a_2 z^{-2}}\]

for

\[b_0 = \frac{1 + \cos(\omega_c)}{2},\;\; b_1 = - 1 - \cos(\omega_c),\;\; b_2 = \frac{1 + \cos(\omega_c)}{2}\]
\[a_0 = 1 + \alpha,\;\; a_1 = -2 \cos(\omega_c),\;\; a_2 = 1 - \alpha\]

where \(\omega_c = 2\pi f_c / f_s\), \(\alpha = \sin(\omega_c)/2 \cdot \sqrt{2}\) and \(\cos(\omega_c)\) is the cosine of the cutoff frequency. The gain is applied to the filter coefficients as \(b = 10^{g_{\textrm{dB}}/20} b\).

Args:
  • fc (float, optional): The cutoff frequency of the filter in Hz. Default: 10000 Hz.

  • gain (float, optional): The gain of the filter in dB. Default: 0 dB.

  • fs (int, optional): The sampling frequency of the signal in Hz. Default: 48000 Hz.

  • device (torch.device, optional): The device of constructed tensors. Default: None.

Returns:
  • b (ndarray): The numerator coefficients of the filter transfer function.

  • a (ndarray): The denominator coefficients of the filter transfer function.

functional.bandpass_filter(fc2: Tensor, gain: float = 0.0, fs: int = 48000, device=None) tuple

Bandpass filter coefficients. It uses the RBJ cookbook formulas to map the cutoff frequencies and gain to the filter coefficients to the to the \(\mathbf{b}\) and \(\mathbf{a}\) biquad coefficients.

\[H(z) = \frac{b_0 + b_1 z^{-1} + b_2 z^{-2}}{a_0 + a_1 z^{-1} + a_2 z^{-2}}\]

for

\[b_0 = \alpha,\;\; b_1 = 0,\;\; b_2 = - \alpha\]
\[a_0 = 1 + \alpha,\;\; a_1 = -2 \cos(\omega_c),\;\; a_2 = 1 - \alpha\]

where

\[\omega_c = \frac{2\pi f_{c1} + 2\pi f_{c2}}{2 f_s}`,\]
\[\text{ BW } = \log_2\left(\frac{f_{c2}}{f_{c1}}\right), \]
\[\alpha = \sin(\omega_c) \sinh\left(\frac{\log(2)}{2} \text{ BW } \frac{\omega_c}{\sin(\omega_c)}\right)\]

The gain is applied to the filter coefficients as \(b = 10^{g_{\textrm{dB}}/20} b\).

Args:
  • fc1 (float): The left cutoff frequency of the filter in Hz.

  • fc2 (float): The right cutoff frequency of the filter in Hz.

  • gain (float, optional): The gain of the filter in dB. Default: 0 dB.

  • fs (int, optional): The sampling frequency of the signal in Hz. Default: 48000 Hz.

  • device (torch.device, optional): The device of constructed tensors. Default: None.

Returns:
  • b (ndarray): The numerator coefficients of the filter transfer function.

  • a (ndarray): The denominator coefficients of the filter transfer function.