Frequency Response
The frequency response is the impulse response seen in the frequency domain: for each frequency, a complex number whose magnitude is the gain and whose angle is the phase shift the system applies. Because LTI systems only scale and shift sinusoids, the frequency response describes the system completely, and it is how audio equipment, filters and control loops are specified.
Definition for discrete systems
For a discrete system with impulse response , the frequency response is a function of the normalized frequency (radians per sample, ):
Feeding produces . With sampling rate , , so corresponds to .
import numpy as np
h = np.array([0.25, 0.5, 0.25]) # a tiny smoothing filter
def H(w):
return np.sum(h * np.exp(-1j * w * np.arange(len(h))))
for w in (0, np.pi / 4, np.pi / 2, 3 * np.pi / 4, np.pi):
print(f"omega = {w / np.pi:.2f} pi: gain {abs(H(w)):.4f} phase {np.angle(H(w)) + 0.0:+.4f} rad")
n = np.arange(200)
x = np.cos(np.pi / 4 * n)
y = np.convolve(x, h)[:200]
print("measured output amplitude at pi/4:", round(np.max(np.abs(y[50:])), 4))omega = 0.00 pi: gain 1.0000 phase +0.0000 rad
omega = 0.25 pi: gain 0.8536 phase -0.7854 rad
omega = 0.50 pi: gain 0.5000 phase -1.5708 rad
omega = 0.75 pi: gain 0.1464 phase -2.3562 rad
omega = 1.00 pi: gain 0.0000 phase +0.0000 rad
measured output amplitude at pi/4: 0.8536
The gain falls from 1 at DC to 0 at : a low-pass filter. The phase is linear, meaning every frequency is delayed by the same 1 sample.
Gain in decibels and the Bode plot
Gains are usually shown in decibels, , against log frequency (a Bode plot). dB means half power; dB means the amplitude is divided by 10.
import numpy as np
fs = 48000
a = 0.9 # one-pole low-pass y[n] = a y[n-1] + (1-a) x[n]
for f in (10, 100, 300, 1000, 3000, 10000, 24000):
w = 2 * np.pi * f / fs
H = (1 - a) / (1 - a * np.exp(-1j * w))
print(f"{f:6d} Hz: {round(20 * np.log10(abs(H)), 2) + 0.0:7.2f} dB phase {round(np.degrees(np.angle(H)), 2) + 0.0:7.2f} deg") 10 Hz: 0.00 dB phase -0.67 deg
100 Hz: -0.07 dB phase -6.71 deg
300 Hz: -0.56 dB phase -19.34 deg
1000 Hz: -4.05 dB phase -47.49 deg
3000 Hz: -11.67 dB phase -63.93 deg
10000 Hz: -21.28 dB phase -48.58 deg
24000 Hz: -25.58 dB phase 0.00 deg
The gain drops through dB near 800 Hz and then falls about 6 dB per doubling of frequency, the signature of a first-order filter.
Cascades multiply
Two systems in series have impulse response and therefore frequency response : gains multiply (decibels add) and phases add. This is why filters are designed as cascades of simple sections.
In software
scipy.signal.freqz(b, a)evaluates of a digital filter;freqsdoes the same for analog ones.- Headphone and room correction measure and apply an equalizer approximating in the bands where that is safe.
Exercises
Exercise 1: Gain of a difference
What is the frequency response of , and which frequencies does it remove?
Answer
with ; it removes DC.
Solution
, zero at and 2 at . A differencer is a high-pass filter.
Exercise 2: Decibels
A system has gain dB at 10 kHz. By what factor does it reduce the amplitude?
Answer
By 100.
Solution
gives .
Exercise 3: Cascade (code)
Cascade the smoother with itself. What is the gain at ?
Answer
0.25, the square of the single filter's 0.5.
Solution
import numpy as np
h = np.array([0.25, 0.5, 0.25])
h2 = np.convolve(h, h)
w = np.pi / 2
H2 = np.sum(h2 * np.exp(-1j * w * np.arange(len(h2))))
print(h2.tolist(), round(abs(H2), 4))[0.0625, 0.25, 0.375, 0.25, 0.0625] 0.25
Test yourself
The magnitude of the frequency response at is…
- the delay
- the gain applied to a sinusoid at
- the impulse response at
- always 1
Two filters in series have frequency response…
In a digital system, normalized frequency corresponds to…
- 0 Hz