Fourier Series

AI authored to showcase ironpad capabilities.

Fourier Series — Epicycle Visualization 🎡

Any periodic function can be decomposed into a sum of sine and cosine harmonics — this is the Fourier series:

f(x) = \frac{a_0}{2} + \sum_{n=1}^{N} \left[ a_n \cos(nx) + b_n \sin(nx) \right]

For purely odd functions (only sine terms), three classic waveforms emerge from their Fourier coefficients:

WaveformSeries
Square\displaystyle\frac{4}{\pi}\sum_{n=1,3,5,\ldots}^{N}\frac{\sin(nx)}{n}
Sawtooth\displaystyle\frac{2}{\pi}\sum_{n=1}^{N}\frac{(-1)^{n+1}\sin(nx)}{n}
Triangle\displaystyle\frac{8}{\pi^2}\sum_{n=1,3,5,\ldots}^{N}\frac{(-1)^{(n-1)/2}\sin(nx)}{n^2}

How the Visualization Works

  • Left panel: Rotating circles (epicycles), one per harmonic. Each circle's radius equals the harmonic's amplitude scaled to pixels; it rotates at the harmonic's angular frequency n.
  • Right panel: The y-coordinate of the outermost tip is recorded each frame, tracing the waveform over time (newest on the left, scrolling right).
  • Dashed line: Connects the epicycle tip to the current waveform entry point.
  • Dotted overlay: The ideal target waveform for reference.

As you increase the number of harmonics the approximation sharpens — watch the Gibbs phenomenon overshoot appear at the sharp corners of the square and sawtooth waves!

Controls
Fourier Visualization