Properties of the DFT
The DFT inherits the rules of the Fourier transform, with one twist: everything is circular. Indices wrap around modulo , shifts rotate the array, and convolution becomes circular convolution. Knowing these rules lets you predict FFT output before running it and avoid the classic wrap-around bugs.
The rules
With ( points, indices modulo ):
| Time | Frequency |
|---|---|
| circular shift | |
| modulation | |
| real | |
| circular convolution | |
| Parseval |
import numpy as np
rng = np.random.default_rng(2)
N = 8
x = rng.integers(-5, 6, N).astype(float)
h = rng.integers(-5, 6, N).astype(float)
X, H = np.fft.fft(x), np.fft.fft(h)
k = np.arange(N)
print("shift rule: ", np.allclose(np.fft.fft(np.roll(x, 3)), np.exp(-2j * np.pi * k * 3 / N) * X))
print("real symmetry: ", np.allclose(X[(N - k) % N], np.conj(X)))
circ = np.array([sum(x[m] * h[(n - m) % N] for m in range(N)) for n in range(N)])
print("circular conv: ", np.allclose(np.fft.ifft(X * H).real, circ))
print("Parseval: ", np.sum(x ** 2), "=", round(float(np.sum(np.abs(X) ** 2) / N), 10))shift rule: True
real symmetry: True
circular conv: True
Parseval: 72.0 = 72.0
Circular versus linear convolution
Multiplying DFTs computes circular convolution: the tail of the result wraps around to the start. To get the ordinary (linear) convolution of lengths and , zero-pad both to at least :
import numpy as np
x = np.array([1.0, 2.0, 3.0, 4.0])
h = np.array([1.0, 1.0, 1.0])
print("linear (np.convolve):", np.convolve(x, h).tolist())
circ4 = np.fft.ifft(np.fft.fft(x) * np.fft.fft(h, 4)).real
print("circular, N = 4: ", (np.round(circ4, 10) + 0.0).tolist(), "<- tail wrapped onto the start")
N = len(x) + len(h) - 1
lin = np.fft.ifft(np.fft.fft(x, N) * np.fft.fft(h, N)).real
print("zero-padded, N = 6: ", (np.round(lin, 10) + 0.0).tolist())linear (np.convolve): [1.0, 3.0, 6.0, 9.0, 7.0, 4.0]
circular, N = 4: [8.0, 7.0, 6.0, 9.0] <- tail wrapped onto the start
zero-padded, N = 6: [1.0, 3.0, 6.0, 9.0, 7.0, 4.0]
With the outputs 7 and 4 at positions 4 and 5 were added onto positions 0 and 1: and .
Time reversal and the DFT twice
Circular time reversal corresponds to . Applying the DFT twice gives , the discrete version of . Note the index: stays in place, and the rest of the array is reversed.
In software
np.rollis a circular shift; for the FFT's view of the signal, it is the natural shift.- Wrap-around artifacts appear whenever image processing or audio code multiplies FFTs without padding: echoes at the wrong end, blur leaking from the right edge to the left.
Exercises
Exercise 1: Shift and magnitude
Does a circular shift change ?
Answer
No.
Solution
It multiplies by , which has magnitude 1. Magnitude spectra cannot tell where in the frame an event happened.
Exercise 2: How much padding?
You convolve a 1000-sample signal with a 200-tap filter via FFT. What is the smallest FFT size that avoids wrap-around?
Answer
1199 (in practice the next fast size, such as 1200 or 1280, or the power of two 2048).
Solution
. FFTs are fastest for sizes with small prime factors; scipy.fft.next_fast_len(1199) returns 1200.
Exercise 3: DFT twice (code)
Apply np.fft.fft twice to and divide by . What do you get?
Answer
.
Solution
import numpy as np
x = np.array([1, 2, 3, 4, 5], dtype=float)
y = np.fft.fft(np.fft.fft(x)) / len(x)
print((np.round(y.real, 10) + 0.0).tolist())[1.0, 5.0, 4.0, 3.0, 2.0]
Index 0 stays; the rest is reversed: .
Test yourself
Multiplying two DFTs and inverting computes…
- linear convolution always
- circular convolution
- cross-correlation
- the sum
A circular shift by samples multiplies by…
Parseval for the unnormalized DFT reads…