Convolve 1, 2, 3, 4 with 1, 1, 1 directly, and through a DFT of points. Watch the tail wrap onto the start as shrinks.
The tail wraps round
x = 1, 2, 3, 4 and h = 1, 1, 1. The linear output y has 4 + 3 − 1 = 6 samples.
N = 8: room for all 6 samples, plus 2 zeros. Circular and linear agree: 1, 3, 6, 9, 7, 4.
Describe this picture
Two panels for and , whose linear output has samples. The linear panel draws as stems with dot heads. The circular panel draws the output of the DFT product in points as stems with square heads. A dashed vertical line labelled “N” marks where the room ends, between and . When shrinks, each sample of at travels along an arc back to and adds on. Afterwards a faint dot stays where it came from, joined to its new place by a dotted arc, and the part of the stem it added is a hatched block, named “wrapped” in the key. The readouts are the DFT length and the number of samples wrapped.
The clip plays once and holds on its end frame. It steps through , 6, 5 and 4, with a caption at each value and none while changes; the readouts go from 8 and “none”, 6 and “none”, 5 and “1”, to 4 and “2”. Once the clip has finished, dragging the dashed line, or the arrow keys, sets from 4 to 10.
Two convolutions, one product
In Discrete convolution (5.2) you slid a flipped copy of along and added up the overlaps. From here on I call that linear convolution, written . If has samples and has , the output has samples.
The DFT offers a shortcut. Pad and with zeros to the same length , take the DFT of each, multiply the two spectra bin by bin, and invert. What comes back is called . It is not always .
The reason is in Sampling the spectrum (13.1). By the convolution rule of Properties of the DTFT (12.3), the DTFT of is . The products are samples of that spectrum. And samples of a spectrum describe the signal repeated every samples, with overlapping copies added. So is repeated every samples, one period kept.
If is at least the length of , the copies do not touch and you see followed by zeros. If is shorter, the copies overlap and the tail of lands on top of its start. This operation has a name from Properties of the DFT (13.3): , the -point circular convolution.
The tail wraps round
Think of a circular parking garage with bays. Cars arrive in order, and the first park in bays 0 to . A car that arrives after the last bay is taken goes round to the start and parks in a bay that is already occupied. In the convolution, parking in an occupied bay means adding to it.
The picture at the top of the page convolves with , so is 1, 3, 6, 9, 7, 4. Its clip stops at four DFT lengths:
- : room for all 6 samples, plus 2 zeros. Circular and linear agree: 1, 3, 6, 9, 7, 4.
- : just enough room. Still equal.
- : the last sample, 4, has no room and wraps onto : . Output 5, 3, 6, 9, 7.
- : the last two wrap: and . Output 8, 7, 6, 9. The DFT product gave a circular convolution; pad to and nothing wraps.
When the clip ends, drag the dashed line, or use the arrow keys, to set the DFT length from 4 to 10. Notice that the smallest value, 4, is where both sequences just fit. Move up one step at a time and watch the wrapped samples travel back out past the dashed line, until “samples wrapped” reads “none”.
One more thing to notice. Each circular output adds up to 30, the same total as the linear one. Wrapping moves samples; it never loses any.
The wrap rule, in symbols, is
Here runs over all whole numbers; at most a few terms are not zero. At , collects and , which is . If , only contributes inside , and followed by zeros.
The recipe
The quickest way to see the shortcut working is to follow one pass at , the first stop of the clip. Each strip below shows the sizes of a sequence of eight numbers. The first three are bins to and the last is samples to .
The sizes multiply bin by bin, and the angles add; the figure shows only the sizes. Bin 0 is the easiest check. is the sum of , is the sum of , and is the sum of .
Written out for two of the bins, and . That is the whole algorithm. In words:
- Pad and with zeros to length .
- Take the DFT of each.
- Multiply the two spectra, bin by bin.
- Take the inverse DFT of the product.
Choosing N
Padding to leaves room for all of , so nothing wraps and circular equals linear. Here that is , which is why already agrees. Below that, the wrapped samples add onto the start; this is time aliasing, the mirror of the frequency aliasing in Sampling and aliasing (10.1).
Below the DFT would not even hold the whole of or , so that question never arises. For a longer example, take 1000 samples through a filter of 101 taps. You need , and the next power of two is 2048, the usual choice for the FFT.
Why bother? Direct convolution needs about multiplications, which is here. The recipe needs three DFTs of length , and the FFT of The FFT (14.1) makes each of those fast. This is fast convolution. For signals too long to transform in one piece, Fast convolution (14.3) does it in blocks.
The maths behind it · circulant matrices
Linear convolution is the tall Toeplitz matrix of 5.2 §6. Circular convolution folds its bottom rows onto its top and gives a square circulant matrix, where each row is a rotation of the one above. The DFT as a matrix (13.5) diagonalises it.
The maths behind it · sums of random variables
The distribution of a sum of two independent whole-number quantities is the convolution of their distributions. Compute it with a DFT that is too short and large totals wrap onto small ones, a classic bug when dice or count distributions are combined by FFT.
Worked example
Take and , as in the instrument. The linear output is , and it sums to 30.
Now compute the circular output with by wrapping. Only lies at or beyond , so it adds onto :
The inverse DFT of with both padded to 5 gives the same numbers. The total is , as it must be.
Where you’ll meet this
Filters applied through an FFT, such as an audio reverb or an image blur, use this recipe and must choose with the rule above. A circular result also appears on purpose: a periodic signal passed through a filter gives a circular convolution, with no padding at all.
Reference card
| Quantity | Formula | Notes |
|---|---|---|
| Linear convolution | , length | 5.2 |
| DFT product | both padded to | |
| Wrap rule | , | 13.1 applied to |
| No wrap | then (and zeros) | |
| Total kept | wrapping moves samples | |
| Fast convolution | pad, DFT, multiply, inverse | FFT: 14.1, 14.3 |