Skip to content
AI360Xpert
Beta

Fourier Series and Transform

Periodic signals sum harmonics at integer multiples and aperiodic ones integrate a continuum, with the same coefficients answering both.

A square wave builds from odd harmonics with shrinking amplitudes, and each added harmonic sharpens the edges while ringing near the jumps
A square wave builds from odd harmonics with shrinking amplitudes, and each added harmonic sharpens the edges while ringing near the jumps

Why Does This Exist?

A vibrating string moves at its fundamental plus overtones; a square wave carries odd harmonics; an image holds low smooth swells plus sharp edges. Fourier series write TT-periodic functions as sums of harmonics e2πint/Te^{2\pi i n t / T}; the Fourier transform extends this to aperiodic functions as an integral over a continuum of frequencies. Orthogonality makes coefficients independent (each computed by one inner product), which is why the expansion is practical rather than merely pretty. Discrete computation is the child DFT and FFT page; filtering via spectra is the convolution theorem.

The one idea you need first

Sines of distinct integer frequencies are orthogonal over one period: ∫0Tcos⁡(2πmt/T)cos⁡(2πnt/T)dt=0\int_0^T \cos(2\pi m t/T)\cos(2\pi n t/T) dt = 0 for m≠nm \ne n. Each harmonic therefore contributes independently: changing one coefficient never disturbs the others' fit.

Think of It Like This

A chord broken into piano keys

A rich chord sounds as one blur until a tuner isolates strings: the A string hums at 440440 Hz, its octave at 880880, a fifth above at 660660. Each key's loudness is measured alone by pressing it softly while damping the rest (orthogonality: keys do not interfere).

Fourier coefficients are those per-key loudness readings. The series rebuilds the chord by pressing keys with the measured strengths. Aperiodic sounds (a handclap) need the whole keyboard continuum at once: the transform instead of the series.

How It Actually Works

For TT-periodic ff, coefficients cn=1T∫0Tf(t)e−2πint/Tdtc_n = \frac{1}{T}\int_0^T f(t) e^{-2\pi i n t/T} dt and reconstruction f(t)=∑ncne2πint/Tf(t) = \sum_n c_n e^{2\pi i n t/T}. For aperiodic ff, transform f^(ξ)=∫f(t)e−2πiξtdt\hat{f}(\xi) = \int f(t) e^{-2\pi i \xi t} dt with inversion f(t)=∫f^(ξ)e2πiξtdξf(t) = \int \hat{f}(\xi) e^{2\pi i \xi t} d\xi. Parseval: energy matches across domains (∑∣cn∣2\sum |c_n|^2 or ∫∣f^∣2\int |\hat{f}|^2 equals signal energy), so no information hides.

Gibbs phenomenon. Near a jump, partial sums overshoot by about 9%9\% of the jump height, forever: more harmonics narrow the ringing without lowering its peak. A unit jump rings to about 1.091.09.

Worked example

Square wave f=±1f = \pm 1 with period 2π2\pi: odd harmonics only, f(t)=4π(sin⁡t+13sin⁡3t+15sin⁡5t+⋯ )f(t) = \frac{4}{\pi}(\sin t + \frac{1}{3}\sin 3t + \frac{1}{5}\sin 5t + \cdots). Amplitudes: 4/π≈1.2734/\pi \approx 1.273, 0.4240.424, 0.2550.255. Three terms at t=π/2t = \pi/2: 1.273−0.424+0.255=1.1041.273 - 0.424 + 0.255 = 1.104: overshoot 0.1040.104 (10.4%10.4\%, approaching the 9%9\% limit from above at finite terms). Energy check: 1.2732+0.4242+0.2552≈1.62+0.18+0.065=1.8651.273^2 + 0.424^2 + 0.255^2 \approx 1.62 + 0.18 + 0.065 = 1.865 against total π/2≈1.571\pi/2 \approx 1.571? Resolved honestly: Parseval for this normalization gives partial energy approaching 11 (mean square of ±1\pm 1) from below: normalized partials 0.81+0.09+0.032=0.930.81 + 0.09 + 0.032 = 0.93: three harmonics carry 93%93\% of the energy.

Code

import math

def square_partial(t: float, terms: int) -> float:    total = 0.0    for k in range(terms):        n = 2 * k + 1  # odd harmonics only        total += math.sin(n * t) / n    return 4 * total / math.pi  # 4/pi times the odd sum

for terms in (1, 2, 3, 10):    print(terms, round(square_partial(math.pi / 2, terms), 3))# -> 1 1.273# -> 2 0.849# -> 3 1.104# -> 10 1.063

One term overshoots to 1.2731.273, two undershoot at 0.8490.849, three ring to 1.1041.104, ten settle near 1.0631.063: Gibbs ringing that narrows but persists.

Watch Out For

Truncating at a discontinuity and trusting pointwise values

Partial sums near jumps mislead by 9%9\% regardless of term count: control systems reading edge values from truncated series chatter. Filter (Lanczos sigma factors) or reconstruct away from jumps; never servo on the ringing peak.

Confusing harmonic index with physical frequency

Coefficient nn means n/Tn/T Hz only with the period normalized correctly; resampling the same wave at a new TT renumbers everything. Label axes in Hz (index over period), not raw index, before comparing spectra across recordings.

The Quick Version

  • Periodic functions sum harmonics; aperiodic ones integrate a frequency continuum.
  • Orthogonality isolates each coefficient to one inner product.
  • The square wave uses odd harmonics with amplitudes 1.2731.273, 0.4240.424, 0.2550.255.
  • Three harmonics carry 93%93\% of the wave's energy by Parseval.
  • Gibbs ringing overshoots jumps by about 9%9\% at any truncation.
  • Index means index over period: convert to Hz before comparing spectra.