---
title: Fast convolution and filter banks
heading: Filtering by multiplying spectra, why the FFT computes circular convolution and how zero padding makes it linear, overlap-add processing in blocks, when the FFT beats a direct FIR filter, the latency it costs, and splitting a signal into many channels with a DFT filter bank
eyebrow: D5 · Lesson 7 · Fast convolution and filter banks
xp: 40
---

::: hook
Convolving a signal with a 10,000-tap impulse response, the reverberation of a concert hall, say, takes 10,000 multiplications for every output sample: almost half a billion a second for CD audio. But convolution in time is multiplication in frequency, and the FFT gets to frequency cheaply. Transform a block, multiply by the filter's spectrum, transform back, and the cost per sample grows only with the logarithm of the filter's length. Long filters, room simulators and the channelizers that split a wideband radio into hundreds of channels all work this way.
:::

::: play
- Real multiplications per output sample for an N-tap FIR filter, computed directly (N) and by FFT overlap-add with a transform of the next power of two at least 2N (counting 4 real multiplications per complex one).
- For short filters, direct wins; past about 64 taps the FFT method wins, and by thousands of taps it's tens of times cheaper.
- The cost is latency: the FFT method has to collect a whole block before producing any output.
:::

```sim plot
view: graph
x: N = 4..100000 log
y: C = 1..100000 log
slider: p = 3..16 step 1 = 10
plot: N | samples: 300 | color: ch3 | label: direct, multiplications per output
plot: 4*(2^ceil(log(2*N)/log(2))*ceil(log(2*N)/log(2)) + 2^ceil(log(2*N)/log(2)))/(2^ceil(log(2*N)/log(2)) - N + 1) | samples: 300 | label: FFT overlap-add
marker: x = 2^p | label: N = 2^p taps
readout: direct = 2^p | digits: 5
readout: FFT = 4*(2^(p + 1)*(p + 1) + 2^(p + 1))/(2^(p + 1) - 2^p + 1) | digits: 4
```

::: predict
## A 1024-tap filter runs by overlap-add with 2048-point FFTs. About how many complex multiplications does each output sample cost?

- [ ] 1024
- [ ] 2048
- [x] About 24
- [ ] About 2

::: reveal
Each block takes a 2048-point FFT and inverse FFT (1024 × 11 multiplications each) plus 2048 spectral products: 2048 × 11 + 2048 = 24,576. It yields 2048 − 1024 + 1 = 1025 new outputs, so 24.0 complex multiplications, about 96 real ones, per sample against 1024 directly: ten times cheaper.
:::
:::

::: nameit
## Convolution by FFT

Convolution in time is multiplication in frequency, but the DFT's version is **circular**: the end of the output wraps around onto the start. Convolving a B-sample block with an N-tap filter makes $B + N - 1$ outputs, so the transform length must be

$$L \ge B + N - 1$$

with the block and the filter zero-padded to L. Then the circular result equals the linear one.

## Overlap-add

Cut the input into blocks of B samples, convolve each by FFT, and add each result's $N - 1$ sample tail onto the start of the next. (**Overlap-save** instead overlaps the input blocks and discards the wrapped samples.) Per block the work is two L-point FFTs plus L products, about $L\log_2L + L$ complex multiplications, for B outputs.

## Latency

Nothing comes out until a block has been collected: at least B samples of delay, which matters for live audio. Real-time convolvers split the filter into short and long partitions to keep the delay small.

## Filter banks

A bank of M bandpass filters spaced $f_s/M$ apart can share one prototype low-pass and one M-point FFT: the input passes through the prototype's M **polyphase** branches, and the FFT turns their outputs into M channels at once. Radio channelizers, audio codecs (MP3, AAC) and the OFDM receivers of D4 are built on this.
:::

::: example
## What transform length handles 3000-sample blocks with a 1000-tap filter, and what's the first block's latency at 48 kHz with B = 1025?

::: solution
1. **Transform length.**
   $$\begin{aligned} L &\ge 3000 + 1000 - 1 \\ &= 3999 \end{aligned}$$
   so a 4096-point FFT.
2. **Block size.** With 2048-point FFTs and a 1024-tap filter, B = 1025 samples.
3. **Latency.**
   $$\frac{1025}{48\,000\ \text{Hz}} = 21.4\ \text{ms}$$
   before the first output.

**Answer:** a 4096-point FFT, and with B = 1025 the first output comes 21.4 ms after the start.
:::
:::

::: example
## A 48 kHz signal is split into 64 channels by a DFT filter bank. How far apart are they?

::: solution
1. **Channel spacing.**
   $$\frac{48\,000\ \text{Hz}}{64} = 750\ \text{Hz}$$
2. **Rate after the bank.** Each channel can be decimated by up to 64 (lesson 9), so the total sample rate stays 48 kHz.

**Answer:** the channels are 750 Hz apart.
:::
:::

::: example
## How much does FFT convolution save over direct convolution for a 1000-tap filter with 4096-point transforms?

::: solution
1. **Outputs per block.**
   $$4096 - 1000 + 1 = 3097$$
2. **Cost per block.** Two FFTs and a spectrum product take about
   $$\begin{aligned} &2 \times 2048 \times 12 + 4096 \\ &= 53\,248\ \text{complex multiplies} \end{aligned}$$
3. **Cost per output.**
   $$\frac{53\,248}{3097} = 17.2$$
   complex multiplies, or about 69 real multiplies.
4. **Compare.** Direct convolution takes 1000 multiplies per output, about 15 times as many.

**Answer:** FFT convolution does about 15 times less work: about 69 real multiplies per output against 1000.
:::
:::

::: check
given: B = 512 | 1000 | 3000; N = 64 | 513 | 1000
answer: B + N - 1
tolerance: 0.4

## Blocks of {B} samples are convolved with a {N}-tap filter by FFT. What's the shortest transform that avoids wraparound?

::: right
Right. $B + N - 1$ = {answer} points.
:::

::: misses
- [B + N] One less: the full linear convolution is B + N − 1 long.
- [B] The output is longer than the block: add the filter's tail.
- [any] Not yet. The length of the linear convolution.
:::
:::

::: check
given: p = 8 | 10 | 12 | 14
answer: (2^(p + 1)*(p + 1) + 2^(p + 1))/(2^p + 1)
tolerance: 0.5%

## A $2^{\given{p}}$-tap filter runs by overlap-add with FFTs twice that long. About how many complex multiplications does each output cost?

::: right
Right. $(L\log_2L + L)/(L - N + 1)$ = {answer}.
:::

::: misses
- [2^p] That's the direct method.
- [any] Not yet. Two FFTs and the products per block, over the new outputs per block.
:::
:::

::: check
given: B = 256 | 1025 | 4096; s = 44.1 | 48 | 96
answer: B/s
unit: ms
tolerance: 0.5%

## An overlap-add convolver collects {B}-sample blocks at {s} kHz. What's its minimum latency?

::: right
Right. $B/f_s$ = {answer} ms.
:::

::: misses
- [any] Not yet. One block of samples.
:::
:::

::: check
given: s = 48 | 1000 | 30720; M = 16 | 64 | 1024
answer: s/M
unit: kHz
tolerance: 0.5%

## A DFT filter bank splits a {s} kHz signal into {M} channels. How far apart are the channels?

::: right
Right. $f_s/M$ = {answer} kHz.
:::

::: misses
- [any] Not yet. The sampling rate shared among the channels.
:::
:::

::: check
kind: parts
given: M = 100 | 500 | 1000; N = 2048 | 8192

## An overlap-add filter has {M} taps and uses {N}-point FFTs.

::: part
answer: N - M + 1
unit: samples
tolerance: 0

### How many new outputs does each block give?

::: misses
- [any] $N - M + 1$.
:::
:::

::: part
answer: M/((2*N/2*log(N)/log(2) + N)*4/(N - M + 1))
tolerance: 1%

### How many times less work than direct convolution is it, counting 4 real multiplies per complex one?

::: misses
- [any] Direct: M per output; FFT: (2 FFTs + product) × 4 ÷ outputs.
:::
:::
:::

::: check
kind: parts
given: B = 256 | 1024; fs = 16 | 48

## Overlap-add processes {B}-sample blocks at {fs} kHz.

::: part
answer: B/fs
unit: ms
tolerance: 0.5%

### What latency does collecting a block add?

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

::: part
answer: fs*1000/B
unit: blocks/s
tolerance: 0.5%

### How many blocks a second?

::: misses
- [any] Rate ÷ block.
:::
:::
:::

::: explain
## Why does the FFT method of convolution need zero padding?

::: model
Multiplying two DFTs and transforming back gives circular convolution, as if both signals repeated forever with the DFT's length as their period. The true, linear convolution of a block with a filter is longer than either: it lasts the block's length plus the filter's length minus one. If the transform is shorter than that, the part of the output that runs past the end wraps around and adds onto the beginning, corrupting it. Padding both the block and the filter with zeros to at least the full output length gives the wrapped tail room to land on zeros, so the circular result equals the linear one.
:::
:::

::: practice

::: check
given: B = 10 | 100000; N = 2 | 10000
answer: B + N - 1
tolerance: 0.4

## Shortest FFT for {B}-sample blocks and {N} taps?

::: misses
- [any] $B + N - 1$.
:::
:::

::: check
given: B = 16 | 65536; s = 8 | 192
answer: B/s
unit: ms
tolerance: 0.5%

## Latency of {B}-sample blocks at {s} kHz?

::: misses
- [any] $B/f_s$.
:::
:::
:::
