9.6 FFT implementation
Source: Ideas from Computational Physics (Landau, Páez, Bordeianu), §9.6–9.7. Rewritten in original wording — no textbook Fortran/Python listing dumps. Continues 9.5b. Next: 9.6b.
Power-of-two length
Classic radix-2 FFTs want samples. If your record length is not a power of two, extend it to the next (repeat a prefix, or zero-pad — both change the implied period). Because a DFT always treats the window as periodic, concatenating early samples just starts that period a little sooner; zeros assume “signal ended.”
A concrete walk-through ()
Assign complex probes
( points ⇒ four butterfly stages after a bit-reversal shuffle). Store each sample as . Many codes flatten to a length- real buffer for contiguous access; that is a memory layout choice, not new mathematics.
Pipeline:
- Bit-reverse permute the complex samples (or accept bit-reversed output).
- For : run butterflies of span with twiddles .
- Optionally multiply by the chapter’s (and on the inverse path) so that FFTiFFT recovers .
The DC bin without the physics factor is simply . For (9.78),
and with both real and imaginary parts become .
Original sketch (structure only)
# fft_sketch.py — educational structure (original; not a textbook dump)
# Require N == 2**n. data: list of complex length N.
def bitrev_permute(data):
... # swap i <-> reverse_bits(i)
def fft_inplace(data, inverse=False):
bitrev_permute(data)
sign = +1 if inverse else -1
length = 2
while length <= N:
# butterflies of this span; twiddle = exp(sign*2πi/length)
...
length *= 2
if inverse:
for k in range(N):
data[k] /= N
# optional: scale by 1/sqrt(2π) for physics FT convention
Call a trusted library FFT for production work; implement a tiny or once so bit-reversal and butterflies stop feeling magical.
§9.7 Assessment checklist
- Run your FFT on (or any §9.3 test tone) and read the bins.
- Inverse-transform; check (with consistent norms, they match; proportional is the minimum bar).
- Same signal through a direct DFT: compare precision and wall time as grows.
FFT implementation
1 / 4Radix-2 FFTs require N to be…
Pick an answer to see if you are right.
Next: 9.6b FFT implementation labs.