---
title: Frequency response, distortion and ideal filters
heading: Gain, phase, delay, and the filter you can't build
eyebrow: C9 · Lesson 15 · Frequency response, distortion and ideal filters
xp: 40
---

::: hook
An audio amplifier should change only the size of a signal; a cable should only delay it. Anything else is **distortion**: frequencies amplified unequally, or delayed by different amounts so a sharp edge smears. The frequency response tells exactly which, through its magnitude and its phase. And it explains a surprising fact about the filter every designer would like to have, one that passes everything below a cutoff perfectly and nothing above it: its impulse response starts before the impulse arrives. The ideal filter can't be built, only approached.
:::

::: play
- The curve is the impulse response of an ideal low-pass filter with cutoff $f_c$: $h(t) = 2f_c\,\mathrm{sinc}(2f_ct)$, a central peak with ripples on both sides.
- Raise $f_c$: the peak gets taller and narrower. A wider passband gives a sharper response in time.
- Look left of t = 0: the ripples are there too. The filter responds before the impulse arrives, so no real circuit can do this. Real filters delay a truncated version of it, or settle for a gentler cutoff.
:::
:::

```sim plot
view: graph
x: t = -4..4 ms
y: h = -0.6..2.2
slider: fc = 0.2..1 = 0.5 step 0.01
plot: 2*fc*sinc(2*fc*t) | samples: 1200 | label: h(t), kHz
marker: x = 0 | label: the impulse
readout: peak, per ms = 2*fc | digits: 3
readout: first zero, ms = 1/(2*fc) | digits: 3
```

::: predict
## The ideal low-pass filter passes every frequency below 1 kHz with gain 1 and zero phase, and nothing above. What is wrong with building one?

- [ ] Nothing: a high-order filter achieves it exactly
- [x] Its impulse response is nonzero before t = 0, so it would have to respond before its input arrives
- [ ] It would be unstable
- [ ] It would need infinite power

::: reveal
Its impulse response, $\sin(\omega_c t)/(\pi t)$, stretches to t = −∞, so it isn't causal. A real filter can delay a long stretch of it and cut off the rest (which is how FIR filters approximate it), but a perfectly sharp edge with zero delay is out of reach.
:::
:::

::: nameit
## Magnitude and phase

$H(j\omega) = \lvert H(j\omega)\rvert e^{j\phi(\omega)}$. The magnitude is the gain at each frequency (often in dB, $20\log_{10}\lvert H\rvert$), the phase is the shift.

## Distortionless transmission

A system that only scales and delays, $y(t) = Kx(t - t_0)$, has

$$H(j\omega) = Ke^{-j\omega t_0}$$

a **flat magnitude** and a **linear phase**, $\phi = -\omega t_0$. Unequal gains cause **magnitude distortion**; a phase that isn't a straight line through the origin causes **phase distortion**: frequencies arrive at different times and edges smear.

## Delay

$$\tau_g(\omega) = -\frac{d\phi}{d\omega} \quad (\text{group delay}), \qquad \tau_p(\omega) = -\frac{\phi(\omega)}{\omega} \quad (\text{phase delay})$$

The group delay is how late the envelope of a narrowband signal near ω arrives. For an RC low-pass, $\phi = -\arctan\omega\tau$ and $\tau_g = \tau/(1 + \omega^2\tau^2)$: τ at low frequencies, half that at the corner. A symmetric FIR filter of N taps has exactly linear phase, delaying everything by (N − 1)/2 samples.

## Ideal filters

The ideal low-pass, $H = 1$ for $\lvert\omega\rvert < \omega_c$ and 0 above, has

$$h(t) = \frac{\sin\omega_c t}{\pi t} = 2f_c\,\mathrm{sinc}(2f_ct)$$

with $\mathrm{sinc}(x) = \sin(\pi x)/(\pi x)$: height $2f_c$, zeros every $1/(2f_c)$, and nonzero for t < 0. Ideal high-pass, band-pass and band-stop filters are built from it, and none is causal.
:::

::: example
## An RC low-pass has τ = 1 ms. What is its group delay at low frequencies and at its corner?

::: solution
1. **Group delay of the RC low-pass.**
   $$\tau_g = \frac{\tau}{1 + \omega^2\tau^2}$$
2. **Near DC.** It's τ = 1 ms.
3. **At the corner.** There ωτ = 1, so it's τ/2 = 0.5 ms.
4. **What that means.** Frequencies near the corner arrive earlier than low ones, which is a small amount of phase distortion.

**Answer:** 1 ms at low frequencies and 0.5 ms at the corner.
:::
:::

::: example
## An 11-tap FIR filter has symmetric coefficients. What is its phase at ω = π/4?

::: solution
1. **Linear phase.** Symmetry makes the phase $-5\omega$ (the center tap is 5 samples in), wherever the gain is positive.
2. **At π/4.**
   $$\begin{aligned} -5\omega &= -5\pi/4 \\ &= -225° \end{aligned}$$
3. **No distortion.** Every frequency is delayed by exactly 5 samples: no phase distortion.

**Answer:** the phase is −5π/4, or −225°, a delay of exactly 5 samples.
:::
:::

::: example
## The ideal low-pass with cutoff $\omega_c = \pi/4$ has $h[n] = \sin(\omega_c n)/(\pi n)$. Find h[0], h[2] and h[4], and say why it can't be built.

::: solution
1. **h[0].** The limit at n = 0:
   $$\begin{aligned} h[0] &= \omega_c/\pi \\ &= 0.25 \end{aligned}$$
2. **h[2] and h[4].**
   $$\begin{aligned} h[2] &= \sin(\pi/2)/(2\pi) \\ &= 0.159 \\ h[4] &= \sin(\pi)/(4\pi) \\ &= 0 \end{aligned}$$
3. **Why it can't be built.** The response extends forever in both directions, with samples before n = 0, so it's non-causal and infinitely long.
4. **In practice.** Practical filters truncate and delay it, which costs a gradual transition band and ripple.

**Answer:** h[0] = 0.25, h[2] = 0.159 and h[4] = 0. It can't be built because it's non-causal and infinitely long.
:::
:::

::: check
given: t0 = 0.1 | 0.5 | 2; f = 100 | 250 | 1000
answer: -360*f*t0/1000
unit: °
tolerance: 0.5%

## A pure delay of {t0} ms. What phase shift does it give a {f} Hz sinusoid, in degrees?

::: right
Right. $-\omega t_0 = -360 f t_0$ degrees: {answer}°.
:::

::: misses
- [-2*pi*f*t0/1000] That's in radians; give it in degrees.
- [360*f*t0/1000] A delay makes the phase negative.
- [any] Not yet. $-360ft_0$.
:::
:::

::: check
given: tau = 1 | 2 | 5; f = 100 | 300
answer: tau/(1 + (2*pi*f*tau/1000)^2)
unit: ms
tolerance: 0.5%

## What is the group delay of an RC low-pass with τ = {tau} ms at {f} Hz?

::: right
Right. $\tau/(1 + (\omega\tau)^2)$ = {answer} ms.
:::

::: misses
- [tau] That's the low-frequency limit; at {f} Hz ωτ isn't small.
- [any] Not yet. $\tau_g = \tau/(1 + \omega^2\tau^2)$.
:::
:::

::: check
kind: parts
given: fc = 0.5 | 2 | 10

## An ideal low-pass filter cuts off at {fc} kHz.

::: part
answer: 2*fc
tolerance: 0.5%

### What is the height of its impulse response's peak, per millisecond?

::: misses
- [fc] The peak is $\omega_c/\pi = 2f_c$.
- [any] Not yet. $h(0) = 2f_c$.
:::
:::

::: part
answer: 1/(2*fc)
unit: ms
tolerance: 0.5%

### Where is its first zero after t = 0?

::: misses
- [1/fc] sinc(2f_c t) is first zero where $2f_ct = 1$.
- [any] Not yet. $t = 1/(2f_c)$.
:::
:::
:::

::: check
given: N = 11 | 21 | 64
answer: (N - 1)/2
tolerance: 0

## A symmetric FIR filter has {N} taps. How many samples does it delay every frequency?

::: right
Right. The center of symmetry: (N − 1)/2 = {answer}.
:::

::: misses
- [N/2] Count from the first tap at 0 to the center.
- [N] The delay is to the middle of the response, not its end.
- [any] Not yet. (N − 1)/2.
:::
:::

::: check
kind: parts
given: t0 = 1 | 3; p = 30 | 90; f = 100 | 500

## A system's phase is $\phi = -2\pi f\,t_0 - \phi_0$ with $t_0$ = {t0} ms and a constant $\phi_0$ = {p}°.

::: part
answer: t0
unit: ms
tolerance: 0.5%

### What is its group delay?

::: misses
- [any] The slope of the phase; the constant doesn't change it.
:::
:::

::: part
answer: t0 + p/360/f*1000
unit: ms
tolerance: 0.5%

### What is its phase delay at {f} Hz?

::: misses
- [t0] Phase delay includes the constant: $-\phi/\omega$.
- [any] Not yet. $t_0 + \phi_0/(2\pi f)$.
:::
:::
:::

::: check
given: R = 1 | 10; C = 10 | 47
answer: 1e3/(2*pi*R*C)
unit: Hz
tolerance: 0.5%

## An RC low-pass uses R = {R} kΩ and C = {C} nF. What is its 3 dB bandwidth?

::: right
Right. $1/(2\pi RC)$ = {answer} Hz.
:::

::: misses
- [1e3/(R*C)] That's 1/RC, in radians per second. Divide by 2π for hertz.
- [any] Not yet. $f_c = 1/(2\pi RC)$.
:::
:::

::: check
kind: choice

## A filter passes 1 kHz with gain 1 and 3 kHz with gain 1, but delays 3 kHz by 0.2 ms more than 1 kHz. What happens to a square wave at 1 kHz?

- [ ] Nothing: the gains are equal
- [x] Its shape changes, because its harmonics no longer line up in time
- [ ] It's delayed by 0.2 ms as a whole
- [ ] Its frequency shifts

::: misses
- [1] Equal gains avoid magnitude distortion, but unequal delays are phase distortion.
- [3] Only the harmonics at 3 kHz are delayed that much, so the parts move relative to each other.
- [4] LTI systems never change frequencies.
:::
:::

::: check
kind: parts
given: N = 11 | 31 | 101; fs = 1 | 8 | 48

## A linear-phase FIR filter has {N} symmetric taps and runs at {fs} kHz.

::: part
answer: (N - 1)/2
tolerance: 0

### What is its delay in samples?

::: misses
- [N/2] The center tap is (N − 1)/2 samples in.
- [any] $(N - 1)/2$.
:::
:::

::: part
answer: (N - 1)/2/fs
unit: ms
tolerance: 0.5%

### And in milliseconds?

::: misses
- [any] Samples ÷ rate.
:::
:::
:::

::: check
kind: parts
given: t = 0.1 | 1 | 10; x = 0.5 | 1 | 3

## An RC low-pass has τ = {t} ms.

::: part
answer: t/(1 + x^2)
unit: ms
tolerance: 0.5%

### What is its group delay where ωτ = {x}?

::: misses
- [t] Only near DC is it τ.
- [any] $\tau/(1 + \omega^2\tau^2)$.
:::
:::

::: part
answer: x/(2*pi*t)
unit: kHz
tolerance: 0.5%

### At what frequency is that?

::: misses
- [any] $\omega = x/\tau$, then divide by 2π.
:::
:::
:::

::: explain
## Why does a perfectly flat magnitude still not guarantee an undistorted output?

::: model
A signal's shape depends on how its frequency components line up in time, not just on their sizes. A flat magnitude keeps every component the right size, but if the phase isn't a straight line through the origin, different frequencies are delayed by different amounts. The components of a sharp edge or a pulse then arrive out of step and the waveform smears or rings, even though a spectrum analyzer would show the same amplitudes. Only linear phase delays every frequency equally, so the whole signal just moves later.
:::
:::

::: practice

::: check
given: t0 = 0.2 | 1; f = 500 | 2000
answer: -360*f*t0/1000
unit: °
tolerance: 0.5%

## Phase of a {t0} ms delay at {f} Hz, in degrees?

::: misses
- [any] $-360ft_0$.
:::
:::

::: check
given: N = 5 | 7 | 11 | 15 | 21 | 31 | 63 | 101
answer: (N - 1)/2
tolerance: 0

## Delay of a symmetric {N}-tap FIR filter, in samples?

::: misses
- [any] (N − 1)/2.
:::
:::

::: check
given: fc = 0.5 | 1 | 2 | 4 | 5 | 10 | 20
answer: 1/(2*fc)
unit: ms
tolerance: 0.5%

## First zero of an ideal {fc} kHz low-pass's impulse response?

::: misses
- [any] $1/(2f_c)$.
:::
:::
:::
