The Fast Fourier Transform & Spectral Methods

spectral differentiation

Taking a derivative numerically usually means subtracting nearby values and dividing by a small step — finite differences — which is only modestly accurate and grows noisy as the step shrinks. Spectral differentiation does something cleverer: it transforms the function into its frequency components, where differentiation turns into nothing more than multiplication, and for smooth periodic functions this gives staggeringly accurate derivatives.

The key fact is how differentiation acts on a single wave. The derivative of e^(i*k*x) is i*k*e^(i*k*x) — the same wave, just multiplied by i*k. So differentiating a function in physical space is equivalent to multiplying each of its Fourier coefficients by i*k in frequency space. The recipe is therefore: FFT the sampled function to get its coefficients, multiply the coefficient at frequency k by i*k, then inverse-FFT back. Three fast operations replace the whole apparatus of difference formulas, and for a smooth, periodic function the accuracy is not merely high — it is SPECTRAL, meaning the error decays faster than any fixed power of the grid spacing (often exponentially), so doubling the number of points can square the accuracy rather than just halve the error. Second and higher derivatives just multiply by (i*k)^2, (i*k)^3, and so on.

Spectral differentiation is the engine inside spectral methods for differential equations, and the trade-offs are clear-eyed. Its exponential accuracy holds ONLY for smooth functions; a discontinuity or sharp corner triggers the Gibbs phenomenon — persistent oscillations near the jump — and the accuracy collapses to first order, no better than crude differences. The plain Fourier version also requires the function to be PERIODIC; for non-periodic problems on an interval you switch to a Chebyshev basis (using cosine transforms), which gives the same spectral accuracy without needing periodicity. Within its domain of smooth, well-behaved functions, though, no general-purpose method computes derivatives more accurately per grid point.

Differentiate sin(x) on a periodic grid of 16 points. The FFT yields coefficients concentrated at k = +/-1; multiplying by i*k turns sin(x) into cos(x) exactly, to within rounding. A second-order finite difference on the same 16 points would carry a visible error of order h^2; the spectral result is correct to nearly machine precision.

Multiply each Fourier coefficient by i*k — the derivative, with spectral accuracy.

Spectral accuracy is a reward for SMOOTHNESS only: a single discontinuity unleashes the Gibbs phenomenon and drops the order to first, with ringing near the jump. And the plain Fourier form demands a periodic function — use Chebyshev for non-periodic intervals.

Also called
Fourier differentiationdifferentiation in frequency space傅立葉微分頻域微分