S725 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

S7 · Lesson 25 · Fast convolution

Filtering long signals in blocks with the FFT, the overlap-add and overlap-save methods, their cost per output sample, the best block size, and latency

A long FIR filter, a room's 2-second reverberation at 48 kHz has 96,000 taps, costs that many multiplications for every output sample if it's computed directly. The FFT turns convolution into multiplication, but a signal that never ends can't be transformed in one piece. Block convolution solves that: cut the input into blocks, filter each with FFTs of a fixed size, and stitch the results together either by adding the overlapping tails or by discarding the corrupted starts. The block size is a trade between arithmetic and delay, and this lesson finds the best one.

  • Real multiplications per output sample for FFT block convolution with an N-point FFT and a P-tap filter, from the model 4(Nlog2⁡N+N)N−P+1 (two FFTs and one product per block of N − P + 1 outputs), against log2⁡N.
  • The dashed line is direct convolution, P multiplications per output.
  • Small blocks waste effort on overlap; huge blocks pay for long FFTs. For a 256-tap filter the minimum, about 55 per output, is near N = 2048, almost five times cheaper than direct. Below about 40 taps the direct method wins.

Predict

Overlap-save uses 1024-point FFTs with a 129-tap filter. How many output samples does each block produce?

Name it

Overlap-add

  1. Cut the input into non-overlapping blocks of L samples.
  2. Zero-pad each block and the P-tap filter to N ≥ L + P − 1 and multiply their FFTs; the inverse FFT gives each block's full linear convolution, L + P − 1 samples long.
  3. Add the overlapping P − 1 tail samples of each block's output to the start of the next.

Overlap-save

  1. Take input blocks of N samples overlapping by P − 1.
  2. Circularly convolve each with the filter by N-point FFTs.
  3. Discard the first P − 1 outputs of each block (wrapped) and keep the other N − P + 1.

No additions between blocks, which some implementations prefer.

Cost and block size

Per block: a forward and an inverse N-point FFT, about N2log2⁡N complex multiplications each, plus N complex products with the stored filter spectrum, for N − P + 1 outputs. At four real multiplications per complex one:

cost per output≈4(Nlog2⁡N+N)N−P+1

against P for direct convolution. The best N is a few times P. Each block must be collected before it can be processed, so the method adds latency of at least one block, L samples; very long filters with low latency use partitioned convolution, splitting the filter into segments of different sizes.

Worked example

A 256-tap filter runs by overlap-save. Compare the cost of 1024- and 2048-point FFTs with direct convolution.

Show the solution
  1. N = 1024. C=4(1024×10+1024)769=58.6per output
  2. N = 2048. C=4(2048×11+2048)1793=54.8per output
  3. N = 4096. The cost rises again, to 55.5.
  4. Compare direct. Direct convolution costs 256 per output, so the FFT method is about 4.7 times cheaper at its best.

Answer 58.6 multiplies per output with 1024-point FFTs and 54.8 with 2048-point FFTs, against 256 for direct convolution.

Worked example

At 48 kHz with N = 1024 and P = 256, how much latency does block processing add?

Show the solution
  1. Block size. Each block produces 769 outputs from 769 new inputs.
  2. Time to fill. t=76948000s=16.0ms The block can only be processed once it's complete.
  3. For live audio. That may be too much, which is why real-time convolution reverbs process the first part of the impulse response directly or with small blocks.

Answer about 16.0 ms of latency.

Worked example

A 4096-tap reverberation filter runs at 48 kHz by overlap-save with 8192-point FFTs. Compare its cost with direct convolution, and find its latency.

Show the solution
  1. Outputs per block. 8192−4096+1=4097
  2. Cost per output. C=4(8192×13+8192)4097=112 real multiplications each, against 4096 for direct convolution: 37 times cheaper.
  3. Latency. A block must fill before processing, so the output lags by 4097 samples, 85 ms, audible as an echo in live use.
  4. The fix. Partitioned convolution splits the filter into short early pieces and long late ones to cut that.

Answer 112 multiplications per output against 4096 direct (37 times cheaper), with 85 ms of latency.

Check

Overlap-save uses 1024-point FFTs with a 33-tap filter. How many outputs does each block keep?

Check

By the cost model, how many real multiplications per output does block convolution need with N = 2048 and P = 50?

Check

Block convolution with N = 1024 and P = 129 runs at 48 kHz. What's the minimum latency from collecting one block?

Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.

Check

A 100000-sample signal is filtered by overlap-add with N = 1024 and P = 513. How many blocks are needed?

Check

For a 4096-tap filter with N = 16384 (four times the next power of two), how many times cheaper is block convolution than direct convolution, by the cost model?

Check

Overlap-add uses input blocks of 500 samples and a 101-tap filter. How long is each block's output, and so the smallest FFT that avoids wrap-around?

Check

A 1024-tap filter runs by overlap-save at 16 kHz with FFTs 4 times its length.

(a)

How many real multiplications per output does it need?

(b)

How much latency does collecting a block add?

Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.

Check

Overlap-save uses N-point FFTs with a P-tap filter (P < N).

Step 1

How many outputs does each block keep?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Explain why

Why does overlap-save throw away part of every block?

Practice

Keep practicing

10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.