Fourier series

Any periodic signal can be built from sinusoids. Add sine terms one at a time and watch them approach a square wave, with its sharp corners, and see why jumps need so many high frequencies.

Partial sum Sn(t)S_n(t) over one period target f(t)f(t) Sn(t)S_n(t) newest term earlier terms
Coefficients bkb_k over the harmonic kk included newest next terms

Signals as sums of sinusoids

A signal with period TT can be written as a sum of sinusoids whose frequencies are multiples of the fundamental frequency 1/T1/T, the harmonics:

f(t)=a02+∑k=1∞(akcos⁡(2πktT)+bksin⁡(2πktT))f(t) = \frac{a_0}{2} + \sum_{k = 1}^{\infty} \Big( a_k \cos\big(2\pi k \tfrac{t}{T}\big) + b_k \sin\big(2\pi k \tfrac{t}{T}\big) \Big)

The waves here are odd, f(−t)=−f(t)f(-t) = -f(t), so all aka_k vanish and only sines remain. Here T=1T = 1. The sines of different frequencies are orthogonal: the integral of sin⁡(2πkt)sin⁡(2πlt)\sin(2\pi k t) \sin(2\pi l t) over a period is 0 for k≠lk \ne l. Each coefficient is therefore just the projection of the signal onto its sine,

bk=2T∫0Tf(t) sin⁡(2πktT) dt,b_k = \frac{2}{T} \int_0^T f(t) \, \sin\big(2\pi k \tfrac{t}{T}\big) \, dt,

and adding a term never changes the coefficients found so far. For the square wave, which jumps between +1+1 and −1-1, this gives

f(t)=4π(sin⁡(2πt)+13sin⁡(2π⋅3t)+15sin⁡(2π⋅5t)+…)f(t) = \frac{4}{\pi} \Big( \sin(2\pi t) + \frac{1}{3} \sin(2\pi \cdot 3 t) + \frac{1}{5} \sin(2\pi \cdot 5 t) + \dots \Big)

with only odd harmonics, because the second half of each period is the negative of the first, f(t+T/2)=−f(t)f(t + T/2) = -f(t). The partial sum SnS_n of the first nn terms is the best approximation of ff with these frequencies in the least-squares sense.

Smoothness and decay

How fast the coefficients decay depends on how smooth the signal is. A signal with jumps, like the square and sawtooth waves, has coefficients that fall off like 1/k1/k: many high frequencies are needed to build the steep edges. The triangle wave is continuous and only its slope jumps; its coefficients fall off like 1/k21/k^2, and a few terms already look almost exact. Sharp edges in an image need high frequencies in the same way, which is why blurring (removing high frequencies) softens edges, and why edges alias so easily when an image is subsampled.

Energy

The energy of the signal is split among its terms. By Parseval's theorem, the mean of f2f^2 over a period is ∑kbk2/2\sum_k b_k^2 / 2. For the square wave the mean of f2f^2 is 1, and the first term alone already carries 8/π2≈81 %8 / \pi^2 \approx 81\,\% of it.

The Gibbs phenomenon

At a jump, the partial sums overshoot. With more terms the ripples get narrower and move closer to the jump, but the first peak does not get lower: it stays at about 9 % of the jump height, max⁡Sn≈1.179\max S_n \approx 1.179 for the square wave. The series still converges at every point, and the error energy goes to 0, but not uniformly. The same ringing appears next to edges in images when high frequencies are cut off abruptly, for example by an ideal low-pass filter in the 2D Fourier transform.

Try this