From Analog to Digital Filters

Lecture 2 · Filter tasks in audio, impulse invariance, the bilinear transformation, prewarping

Dr.-Ing. Maximilian Schäfer · Prof. Dr.-Ing. Sebastian J. Schlecht

Where we are

One question, asked of every method

Block Representation Generator
Filters and effects LTI and time-varying systems hand-designed
Classical synthesis samples, partials, modes, physical state hand-designed
DDSP the same structured models parameters learned
Reverberation a recursive dynamical system hand-designed, fittable
Diffusion a learned representation learned

 

The four questions

  1. How is the sound represented?
  2. What are the controllable parameters?
  3. What structure is built in?
  4. What is fixed by design, and what is learned?

Filters and effects, part 1 of 5. Today: why audio filters are designed from analog prototypes, and how to carry them over to discrete time.

Listen: one riff, four treatments

dry: the guitar DI of the course
bass boost, +12 dB low shelf, corner 250 Hz
tone knob down, low-pass at 600 Hz
through a diode clipper

 

Listen first

Two of the three treatments are linear filters: a mixing desk does them with one knob each. Which one is not, and what would you need to know to build it?

Overview

Overview Filter tasks in communications and audio engineering

Communications Audio Engineering
Task
suppression of unwanted signal components (selective filter) amplification or reduction of certain frequency bands
Prototypes
rectangular lowpass, highpass,
bandpass, bandstop
adaptive filters
high and lowpasses of degree 1 and 2,
high and low frequency shelving filters,
peak filters
Typical requirements
passband deviation \(<\) 1dB
stopband attenuation \(>\) 60dB
boost or cut from 0dB to 20dB
gain and cutoff frequency highly variable
during operation

Overview Tolerance schemes and equalizers

Communications:

Tolerance schemes of lowpass, highpass, bandpass and bandstop filters with passband and stopband limits.

Tolerance schemes after H. W. Schüßler, Digitale Signalverarbeitung 2, Springer-Verlag, 2010 (redrawn).

tolerance schemes for selective filters:

lp, hp lowpass, highpass
bp, bs bandpass, bandstop
\(\Omega_\mathrm{D}\), \(\Omega_\mathrm{S}\) passband and stopband cutoff frequencies
\(\delta_\mathrm{D}\), \(\delta_\mathrm{S}\) tolerances

Audio Engineering:

Magnitude responses of a parametric equalizer chain: low shelf, three peak filters at 200 Hz, 600 Hz and 2 kHz, and a high shelf, for gains from -15 to +15 dB.

shelving and peak filters
(german: Kuhschwanz-Entzerrer, Glocken-Filter)
cutoff and center frequencies
variable during operation

Overview Filters with adjustable coefficients

Block diagram: input, filter, output; manual input sets the calculation of coefficients, which sets the filter.

Photo of a mixing console with rows of knobs and faders.

Mixing console · Rodrigo César, public domain, Wikimedia Commons

Overview Simple calculation of the coefficients

Problem: simple calculation of the coefficients required

  • simple manual input of gain, cutoff frequencies, etc.
    e.g. through faders at a mixing console,

  • simple and fast calculation of the filter coefficients

  • the stability of the filter has to be guaranteed for all possible input values

possible solutions:

  1. non-recursive filters

    advantage: always stable, disadvantage: many coefficients to calculate

  2. recursive filters in direct form \[H(z) = c\cdot \frac{z^2 + \beta_1 z+ \beta_0}{z^2 + \alpha_1 z+ \alpha_0}\] advantage: few coefficients,
    disadvantage: no straightforward calculation of the filter coefficients

  3. recursive filters by transformation from analog reference filters

    advantage: few coefficients,
    one-to-one assignment between variable parameters and filter coefficients,
    guaranteed stability possible

Overview Analog reference filter

Investigate a candidate transfer function for a low frequency shelving filter \[\begin{aligned} H(s) &= \frac{s + V_0\, \omega_\mathrm{c}}{s + \omega_\mathrm{c}} & V_0 &>1 & \omega_\mathrm{c} & > 0 \end{aligned}\]

Basic behaviour of the frequency response \(H(j\omega)\): \[\begin{aligned} H(0) &= V_0 \quad \text{DC gain}, \\ \lim\limits_{\omega\rightarrow\infty}H(j\omega) &=1 \quad \text{high frequency gain} \end{aligned}\] For more details, see the Bode diagram.

Overview Bode diagram of the low frequency shelving filter

Bode diagram for \(\omega>0\) \[\begin{aligned} \log|H(j\omega)| &= \log \left| \frac{j\omega + V_0\, \omega_\mathrm{c}}{j\omega + \omega_\mathrm{c}} \right| = \log \left| j\omega + V_0\, \omega_\mathrm{c}\right| - \log \left| j\omega + \omega_\mathrm{c}\right| \\ \log|H(j\omega)| &\approx \begin{cases} \log V_0 & \omega < \omega_\mathrm{c} < V_0\, \omega_\mathrm{c} \\ \log V_0 + \log \omega_\mathrm{c} - \log \omega & \omega_\mathrm{c} < \omega < V_0\, \omega_\mathrm{c} \\ \log 1 = 0 & \omega_\mathrm{c} < V_0\, \omega_\mathrm{c} < \omega \end{cases} \end{aligned}\]

Bode sketch of the low frequency shelving filter: gain V0 up to omega_c, falling to 1 at V0 omega_c.

Note that the axes are spaced logarithmically.

Overview Shelving filter = low pass + constant

Decompose the shelving filter into a low pass filter and a constant: \[\begin{aligned} H(s) & = \frac{s + V_0\, \omega_\mathrm{c}}{s + \omega_\mathrm{c}} = \frac{s + \omega_\mathrm{c}}{s + \omega_\mathrm{c}} + \frac{(V_0-1) \omega_\mathrm{c}}{s + \omega_\mathrm{c}} = 1 + H_0 \frac{\omega_\mathrm{c}}{s + \omega_\mathrm{c}} & H_0 &= V_0-1 \end{aligned}\] \[\begin{aligned} H(s) &= 1 + H_0 H_\mathrm{LP}(s) & H_\mathrm{LP}(s) &= \frac{\omega_\mathrm{c}}{s + \omega_\mathrm{c}} \end{aligned}\] Basic behaviour of the lowpass frequency response \(H_\mathrm{LP}(j\omega)\): \[\begin{aligned} H_\mathrm{LP}(0) &= 1 \quad \text{DC gain} \\ \lim\limits_{\omega\rightarrow\infty}H_\mathrm{LP}(j\omega) &=0 \quad \text{high frequency gain} \end{aligned}\]

\(H_\mathrm{LP}(s)\) first order lowpass filter with unit passband gain and cutoff frequency \(\omega_\mathrm{c}\)

Note

\(H_\mathrm{LP}(s)\) is used as a running example in the following.

Overview Analog-to-Discrete Transformations

transform the

  • transfer function of a continuous-time system into the

  • transfer function of a corresponding discrete-time system

with similar properties. \[H_\mathrm{c}(s) \quad \longrightarrow \quad H_\mathrm{d}(z)\]

Different approaches with different properties:

  • impulse-invariant transformation,

  • bilinear transformation,

  • …and others.

Overview Impulse-invariant transformation

\[\begin{aligned} &\textbf{Impulse-Invariant Transformation}& H_\mathrm{d}(z) = \text{𝒵} \left\{ T \left.\left[ \text{ℒ}^{-1}\left\{ H_\mathrm{c}(s) \right\} \right]\right|_{t=kT} \right\} \end{aligned}\]

Impulse-invariant transformation as a chain: H_c(s), inverse Laplace transform to h_c(t), sampling with period T, T h_c(kT) = h_d(k), z-transform to H_d(z).

Example

\[\begin{aligned} H_\mathrm{c}(s) &= \sum\limits_{\mu=1}^n A_\mu \dfrac{1}{s-s_\mu} &&\longrightarrow& H_\mathrm{d}(z) &= T\sum\limits_{\mu=1}^n A_\mu \dfrac{z}{z-z_\mu} & z_\mu &=e^{s_\mu T} \end{aligned}\]

The same chain for one partial fraction: 1/(s - s_mu), e^(s_mu t), sampling, T z_mu^k, T z/(z - z_mu).

Disadvantage

  • Sampling of the impulse response causes aliasing in the frequency domain

  • For low-pass systems only!

Impulse invariance: where the aliasing comes from

Left: the analog first-order lowpass response at 5 kHz and its copies shifted by multiples of the sampling frequency; the parts of the neighbouring copies inside the band minus fs/2 to fs/2 are shaded red, the dashed sum is the impulse-invariant response. Right: in the band 0 to fs/2 the impulse-invariant response deviates from the analog one, most towards fs/2; the bilinear response falls to zero at fs/2.

  • Sampling the impulse response, \(h_\mathrm{d}[k] = T\,h_\mathrm{c}(kT)\), repeats the frequency response every \(f_\mathrm{s}\): \[H_\mathrm{d}(e^{j\omega T}) = \sum_{k} H_\mathrm{c}\big(j(\omega - k\,\omega_\mathrm{s})\big)\]
  • A first-order low-pass is not band-limited: the tails of the neighbouring copies (red) fall into the band and add to the response
  • For \(f_\mathrm{c}\) = 5 kHz, \(f_\mathrm{s}\) = 44.1 kHz: +0.4 dB at DC, −2.9 dB at 15 kHz, −5.2 dB at \(f_\mathrm{s}/2\)

 

Take away

  • impulse invariance keeps the impulse response, not the frequency response
  • aliasing unless \(H_\mathrm{c}\) is (nearly) zero above \(f_\mathrm{s}/2\): fine for steep low-passes, useless for high-pass, shelving and peak filters
  • the bilinear transformation (next) has no aliasing; it warps the frequency axis instead

Bilinear Transformation

Bilinear Transformation From the s-plane to the z-plane

Mapping from to
\(s\)-plane \(z\)-plane
imaginary axis \(j\omega\) unit circle \(e^{j\Omega}\)
frequency axis
continuous signals
frequency axis
discrete signals
frequency responses
of analog filters
frequency responses
of digital filters
structures of analog filters structures of digital filters
\(s = \displaystyle \frac{2}{T} \frac{z - 1}{z+1}\) \(z = \displaystyle \frac{1 + sT/2}{1-sT/2}\)

Bilinear Transformation Given a continuous system, wanted a discrete one

Given: continuous system \(H_\mathrm{c}(s)\)

Block diagram: V_c(s) into H_c(s), output Y_c(s).

Wanted: discrete system \(H_\mathrm{d} (z)\)

Block diagram: V_d(z) into H_d(z), output Y_d(z).

Representation of a continuous system by a realizing structure, e.g.

\[H_\mathrm{c} (s) = \displaystyle \frac{b_1 s + b_0}{s + c_0} = \displaystyle\frac{Y_\mathrm{c}(s)}{V_\mathrm{c}(s)}\]

Realizing structure of the first-order system: integrator 1/s with feedforward gains b0, b1 and feedback -c0.

Integrator:
\(\quad X(s) = \displaystyle \frac{1}{s}\; W(s)\), \(\quad x(t) = \displaystyle \int \limits^{t}_{0} w (\tau)\, d \tau\)

Block diagram of the integrator: W(s) into 1/s, output X(s).

Bilinear Transformation A discrete approximation of the integrator

Derive a discrete system \(G(z)\) such that \(\quad\dfrac{1}{s} \approx G (z)\).

Two different derivations:

1 Numerical integration of \(x(t)=\displaystyle \int \limits^{t}_{0} w (\tau) d\tau\) at \(t\!=\!kT\)
with the trapezoidal rule

Trapezoidal rule: the area under w(t) between kT and (k+1)T approximated by a trapezoid.

\(\Rightarrow\) \[\begin{array}{rcl}\displaystyle \rlap{x\big((k + 1) T \big) = }\\[1ex]\displaystyle &\displaystyle = &\displaystyle \displaystyle \int \limits^{(k+1)T}_{0} w (\tau)\, d \tau = \underbrace{ \displaystyle \int \limits^{kT}_{0} w (\tau)\, d \tau}_{\displaystyle x(kT)} + \displaystyle \int \limits^{(k + 1) T}_{kT} w (\tau)\, d \tau \\\displaystyle &\displaystyle = &\displaystyle \displaystyle x(kT) + \frac{T}{2} \big[ w\big( ( k + 1) T \big) + w(kT)\big]\end{array}\]

\(z\)-transformation

\[\displaystyle zX(z) = X(z) + \frac{T}{2} \bigg[zW(z) + W (z)\bigg]\]

\(\displaystyle \frac{X (z)}{W(z)} =\) \(\bbox[#eef2f8,6px,border:1.5px solid #215293]{\displaystyle \frac{T}{2} \displaystyle \frac{z + 1}{z-1} = G(z)}\)

Bilinear Transformation 2 Representation of a sequence of samples as a series of impulses

\[\begin{array}{lll}\displaystyle v_\mathrm{c} (t) &\displaystyle = &\displaystyle \displaystyle \sum \limits^{\infty}_{k = 0} v_\mathrm{d} [k]\, \delta (t - kT)\\\displaystyle V_\mathrm{c} (s) &\displaystyle = &\displaystyle \text{ℒ} \left\{ v_\mathrm{c} (t) \right\} = \displaystyle \sum \limits^{\infty}_{k = 0} v_\mathrm{d} [k] e^{-skT}\\\displaystyle V_\mathrm{d} (z) &\displaystyle = &\displaystyle \text{𝒵} \left\{ v_\mathrm{d} [k] \right\} = \displaystyle \sum \limits^{\infty}_{k = 0} v_\mathrm{d} [k] z^{-k} \end{array}\]

\[\Rightarrow\]

\(z = e^{sT}\)
\(s = \displaystyle \frac{1}{T} \ln z\)

cannot be realized by a difference equation

instead approximation by series expansion:

\[s = \dfrac{1}{T} \ln z = \dfrac{2}{T} \left[ \dfrac{z-1}{z + 1} + \dfrac{1}{3} \left( \dfrac{z-1}{z + 1} \right)^3 + \cdots \right] \approx \dfrac{2}{T} \dfrac{z-1}{z + 1}\] \[\bbox[#eef2f8,6px,border:1.5px solid #215293]{ \dfrac{1}{s} \approx \dfrac{T}{2} \dfrac{z + 1}{z - 1} = G (z) }\]

Bilinear Transformation From \(H_\mathrm{c}(s)\) to \(H_\mathrm{d}(z)\)

from the transfer function \(H_\mathrm{c}(s)\) (continuous) to \(H_\mathrm{d}(z)\) (discrete):

\[H_\mathrm{d} (z) = H_\mathrm{c} \left( \dfrac{1}{G(z)} \right) = H_\mathrm{c} \left( \dfrac{2}{T} \dfrac{z-1}{z + 1} \right)\]

Example

\(\begin{array}{lll}\displaystyle H_\mathrm{c} (s) &\displaystyle = &\displaystyle \displaystyle \frac{\omega_\mathrm{c}}{s + \omega_\mathrm{c}} = \displaystyle \frac{-s_\infty}{s - s_\infty}, \quad s_\infty = - \omega_\mathrm{c} \qquad |H_\mathrm{c} (0)| = 1, \quad |H_\mathrm{c} (\infty)| \rightarrow 0 \\[3ex]\displaystyle H_\mathrm{d} (z) &\displaystyle = &\displaystyle \displaystyle \frac{\omega_\mathrm{c}}{\displaystyle\frac{1}{G(z)} + \omega_\mathrm{c}}= \displaystyle \frac{\omega_\mathrm{c}}{ \displaystyle\frac{2}{T} \frac{z-1}{z + 1}+ \omega_\mathrm{c}}= \displaystyle \frac{\omega_\mathrm{c} T/2\; (z + 1)} {(z-1) + \omega_\mathrm{c} T/2\; (z + 1)} = \\[5ex]\displaystyle &\displaystyle = &\displaystyle \displaystyle \frac{\omega_\mathrm{c}T/2\; (z + 1)} {(1+ \omega_\mathrm{c}T/2 )z - (1 - \omega_\mathrm{c} T/2)} = \displaystyle \frac{\omega_\mathrm{c}T/2}{1 + \omega_\mathrm{c} T/2} \cdot \displaystyle \frac{z + 1}{z - z_\infty} = \\[3ex]\displaystyle &\displaystyle =&\displaystyle \displaystyle\frac{1 - z_\infty }{2} \cdot \displaystyle \frac{z + 1}{z - z_\infty} \qquad \mbox{ with } z_\infty = \displaystyle \frac{1 - \omega_\mathrm{c}T/2 }{1 + \omega_\mathrm{c}T/2 } = \displaystyle \frac{1 + s_\infty T/2 }{1 - s_\infty T/2 } \end{array}\)
\[H_\mathrm{d}(1) = H_\mathrm{c}(0) = 1,\qquad H_\mathrm{d}(-1) =H_\mathrm{c}(\infty) = 0\]

Bilinear Transformation 1. Stability: properties of the mapping

Properties of the mapping \(z = \displaystyle \frac{1 + s T/2}{1 - s T/2}\) with \(s = \sigma + j \omega\):

\[z = \rho e^{j \Omega} = \displaystyle \frac{1 + (\sigma + j \omega)T/2}{1 - (\sigma + j \omega) T/2}\]

\[|z| = \rho = \sqrt{ \displaystyle \frac{(1 + \sigma T/2)^2 + (\omega T/2)^2}{(1 - \sigma T/2)^2 + (\omega T/2)^2}}\]

\[\begin{array}{lllllll}\displaystyle \sigma &\displaystyle > &\displaystyle 0 \quad &\displaystyle \rightarrow &\displaystyle \quad \rho &\displaystyle > &\displaystyle 1\\\displaystyle \sigma &\displaystyle = &\displaystyle 0 \quad &\displaystyle \rightarrow &\displaystyle \quad \rho &\displaystyle = &\displaystyle 1\\\displaystyle \sigma &\displaystyle < &\displaystyle 0 \quad &\displaystyle \rightarrow &\displaystyle \quad \rho &\displaystyle < &\displaystyle 1 \end{array}\]

s-plane and z-plane: the left half-plane maps to the inside of the unit circle, the right half-plane to the outside.

Bilinear Transformation Conclusions

1. Stability
Poles in the left \(s\)-half-plane are mapped to
the interior of the unit circle of the \(z\)-plane.

continuous system stable \(\rightarrow\) discrete system stable

s-plane and z-plane: the left half-plane maps to the inside of the unit circle, the right half-plane to the outside.

Stability: where the \(s\)-plane goes

Lines of constant damping in the s-plane map to circles through z = -1 in the z-plane; the imaginary axis becomes the unit circle.

Vertical lines (constant damping) become circles through \(z = -1\); the imaginary axis becomes the unit circle. ✕: a pole at \(sT/2 = -0.4\) lands at \(z = 0.43\).

Bilinear Transformation 2. Frequency warping

2. Frequency Warping \[\begin{array}{rcl}\displaystyle &\displaystyle &\displaystyle s = \displaystyle \frac{2}{T} \displaystyle \frac{z - 1}{z + 1} \qquad \mbox{ for } s = j \omega, z = e^{j \Omega} \\\displaystyle &\displaystyle &\displaystyle j \omega = \displaystyle \frac{\displaystyle 2}{\displaystyle T} \displaystyle \frac{ e^{j \Omega} - 1}{e^{j \Omega} + 1} = \displaystyle \frac{2}{T} \displaystyle \frac{e^{j \Omega/2} - e^{-j \Omega/2}}{e^{j \Omega/2} + e^{-j \Omega/2}} = \displaystyle \frac{2}{T} \displaystyle \frac{2 j \sin \Omega/2}{2 \cos \Omega/2} \\\displaystyle &\displaystyle &\displaystyle \omega = \displaystyle \frac{2}{T} \tan \displaystyle \frac{\Omega}{2} \qquad \Omega = 2\, {\rm arctan}\, \omega T/2 \end{array}\]

geometric illustration:

\[\begin{array}{lllllll}\displaystyle \omega &\displaystyle = &\displaystyle 0 &\displaystyle \rightarrow &\displaystyle \Omega &\displaystyle = &\displaystyle 0\\[1ex]\displaystyle \omega &\displaystyle = &\displaystyle \displaystyle \frac{2}{T} &\displaystyle \rightarrow &\displaystyle \Omega &\displaystyle = &\displaystyle \displaystyle\frac{\pi}{2}\\[2ex]\displaystyle \omega &\displaystyle = &\displaystyle \pm \infty &\displaystyle \rightarrow &\displaystyle \Omega &\displaystyle = &\displaystyle \pm \pi\\[1ex]\displaystyle |\omega| &\displaystyle \ll &\displaystyle \displaystyle \frac{1}{T} &\displaystyle \rightarrow &\displaystyle \Omega &\displaystyle \approx &\displaystyle \omega T\\\displaystyle \end{array}\]

Geometric illustration of frequency warping: a point at angle Omega on the unit circle and the tangent value omega T/2.

Bilinear Transformation Local equalization of the warping by prewarping

continuous system \(\quad\omega = 2 \pi f\)
discrete system

\[\Omega = \omega'T = 2 \pi T f' = 2 \,{\rm arctan}\, \omega T/2\]

\[\begin{array}{lll}\displaystyle f' &\displaystyle = &\displaystyle \displaystyle \frac{1}{\pi}\, f_\mathrm{s} \cdot {\rm arctan} \left( \pi \displaystyle \frac{f}{f_\mathrm{s}} \right)\\\displaystyle &\displaystyle &\displaystyle \\\displaystyle f &\displaystyle = &\displaystyle \displaystyle \frac{1}{\pi}\, f_\mathrm{s} \cdot {\rm tan} \left( \pi \displaystyle \frac{f'}{f_\mathrm{s}} \right) \end{array}\]

Warping curve f'/f_s = arctan(pi f/f_s)/pi with the prewarped frequency f_0 marked.

for \(f \ll f_\mathrm{s}\): \(f'\approx f\) approximately linear

Local equalization of frequency warping by prewarping

  1. Specify the desired cutoff frequency of the discrete system \(\rightarrow f_0'\)

  2. Mapping onto the frequency axis of the continuous systems (prewarping) \(\rightarrow \bar{f}_0\)

  3. Design of a continuous system with the cutoff frequency \(\bar{f}_0 \rightarrow \bar{H}_\mathrm{c} (s)\)

  4. Obtain the discrete system by bilinear transformation \(\rightarrow H_\mathrm{d} (z) = \bar{H}_\mathrm{c} \left( \displaystyle \frac{2}{T}\displaystyle \frac{z-1}{z + 1} \right)\)

Frequency warping: an example

Warping curve of the bilinear transformation at 44.1 kHz: the analog 10 kHz lands at 8.69 kHz, prewarping designs the prototype at 12.12 kHz.

Magnitude responses of the analog prototype, the prewarped prototype and the digital lowpass with and without prewarping at 10 kHz.

 

1. Wanted: digital cutoff \(f'_\mathrm{c}\) = 10 kHz at \(f_\mathrm{s}\) = 44.1 kHz

Directly applied: analog design at 10 kHz lands at \(f'\) = 8.69 kHz (orange, both plots): the warping pulls it down

2. Prewarping: \(\bar f_\mathrm{c} = \frac{f_\mathrm{s}}{\pi}\tan\frac{\pi f'_\mathrm{c}}{f_\mathrm{s}}\) = 12.12 kHz (arrow in the top plot)

3. Analog design of the prototype at \(\bar f_\mathrm{c}\) (dotted, bottom plot)

4. Bilinear transformation: the digital low-pass (blue) passes −3 dB exactly at 10 kHz

Bilinear Transformation Example: lowpass with prewarping

Example: Lowpass

\(\displaystyle H_\mathrm{c}(s)=\frac{\omega_\mathrm{c}}{s+\omega_\mathrm{c}}\:,\qquad H_\mathrm{d}(z)=\frac{1-z_\infty}{2}\cdot\frac{z+1}{z-z_\infty}\), prewarping for \(\omega_\mathrm{c}\):

\[\omega_\mathrm{c}=2\pi f_\mathrm{c}=2\pi\,\dfrac{1}{\pi}\,f_\mathrm{s}\tan\left(\pi\,\dfrac{f'_\mathrm{c}}{f_\mathrm{s}} \right)\qquad\Rightarrow\qquad \dfrac{\omega_\mathrm{c}T}{2}= \tan\left(\pi\dfrac{f'_\mathrm{c}}{f_\mathrm{s}}\right)=c\]

Design procedure

Desired cutoff frequency of the discrete system \(f'_\mathrm{c}\) \[\begin{aligned} c &= \tan\left(\pi\,\frac{f'_\mathrm{c}}{f_\mathrm{s}}\right) \\ z_\infty &= \frac{1-c}{1+c} \\ H_\mathrm{d}(z) &= \frac{1-z_\infty}{2}\cdot\frac{z+1}{z-z_\infty} \end{aligned}\]

Design procedure in code: a digital low shelf

c    = np.tan(np.pi * fc / fs)      # prewarped ωc·T/2
zinf = (1 - c) / (1 + c)
b    = (1 - zinf) / 2 * np.array([1, 1])   # lowpass H_LP
a    = np.array([1, -zinf])
H0   = 10 ** (G / 20) - 1
b    = a + H0 * b                   # shelf: 1 + H0·H_LP
y    = scipy.signal.lfilter(b, a, x)

The coefficients follow from the knob in closed form: one \(\tan\) per update.

 

Digital low shelf, two knobs

Gain \(G\) in dB and cutoff \(f'_\mathrm{c}\) in Hz: \[V_0 = 10^{G/20}, \qquad H_0 = V_0 - 1\] \[H_\mathrm{d}(z) = 1 + H_0\,\frac{1 - z_\infty}{2}\cdot\frac{z+1}{z - z_\infty}\]

Bilinear Transformation Warping and prewarping of a first-order lowpass

Four-quadrant plot of warping and prewarping: prototype and warped prototype, digital filters with and without prewarping, and the arctan mapping.

Bilinear Transformation Example: lowpass at two sampling rates

Four panels of first-order lowpass magnitude responses at sampling rates of 48 and 96 kHz with cutoffs of 1 and 10 kHz: continuous, discrete with and without prewarping.

Learn German with signals and systems:

Frequenz frequency
Frequenzgang frequency response
Grenzfrequenz cutoff frequency
Abtastfrequenz sampling frequency
Tiefpass lowpass
Betrag magnitude
kontinuierlich continuous
Vorverzerrung prewarping

Failure case: a filter sweep that cannot reach the top

Left: the warping curve of the bilinear transformation at 16 kHz sampling rate maps the analog 7 kHz to 4.8 kHz. Right: resonance frequency over time of the sweep; prewarped it reaches 7 kHz, not prewarped it stalls at 4.8 kHz.

Sound examples: a sawtooth through a resonant low-pass (second order, \(Q\) = 6) at \(f_\mathrm{s}\) = 16 kHz. The cutoff is swept 200 Hz → 7 kHz → 200 Hz; every 2 ms the coefficients are recomputed from the analog prototype with the bilinear transformation. The plots above show where the resonance ends up.

prewarped
not prewarped

 

Take away

Without prewarping the analog 7 kHz lands at \(f' = \frac{f_\mathrm{s}}{\pi}\arctan\frac{\pi\cdot 7\,\mathrm{kHz}}{f_\mathrm{s}}\) = 4.8 kHz: the sweep stalls and stays dull at the top. Prewarping, \(f_\mathrm{c} = \frac{f_\mathrm{s}}{\pi}\tan\frac{\pi f'_\mathrm{c}}{f_\mathrm{s}}\), costs one \(\tan\) per update and puts the resonance where the knob says. Time-varying filters (lecture 4) prewarp at every coefficient update.

Wrap-up

Check yourself

Prewarp a lowpass

A first-order lowpass should have its cutoff at \(f'_\mathrm{c} = 10\) kHz, at \(f_\mathrm{s} = 48\) kHz. At which cutoff \(f_\mathrm{c}\) do you design the analog prototype? Where would the digital cutoff land without prewarping?

Try it: notebook (warp, prewarp and compare impulse invariance with the bilinear transformation), runs in the browser.

Take away

Design analog, then transform

Audio filters need coefficients that are simple to compute from gain and cutoff, and stable for every knob setting: design a continuous prototype, then transform it.

 

Impulse invariance

Samples the impulse response: the frequency response aliases. Usable for lowpass systems only.

 

Bilinear transformation

\(s = \frac{2}{T}\frac{z-1}{z+1}\) (trapezoidal rule): stable stays stable, the \(j\omega\) axis becomes the unit circle, the frequency axis is warped. Prewarping makes one frequency exact.

Next lecture: one more mapping, now from the unit circle onto itself. Allpass transformations move a cutoff with a single coefficient.

Further reading

  • U. Zölzer (ed.), DAFX: Digital Audio Effects, 2nd ed., Wiley, 2011
  • U. Zölzer, Digitale Audiosignalverarbeitung, 3. Auflage, B.G. Teubner, Stuttgart, 2005
  • H. W. Schüßler, Digitale Signalverarbeitung 2, Springer, 2010
  • B. Girod, R. Rabenstein, A. Stenger, Signals and Systems, Wiley, 2001
  • R. Rabenstein, M. Schäfer, Multidimensional Signals and Systems: Theory and Foundations, Springer, 2023

Slides 1:1 from the LMS/FAU lecture notes (R. Rabenstein, M. Schäfer); figures redrawn in TikZ (slides/filters_tikz/), plots re-plotted from the original Matlab scripts, added examples by the slides/make_filters_*.py scripts in the course repository.