Skip to content
Toolcroft

Math Calculators

Fourier Series Visualizer - Square, Sawtooth & Triangle Waves

See how adding sine wave harmonics builds square, sawtooth, and triangle waves. Animate the rotating phasor vectors and watch the Fourier approximation improve with more terms.

What is the Fourier transform?

The Fourier transform is a mathematical technique that decomposes any periodic signal into a sum of simple sine and cosine waves. Named after French mathematician Joseph Fourier (1768–1830), it answers the question: “What are the individual frequency components hidden inside this complex waveform?” Just as white light splits into a rainbow through a prism, the Fourier transform reveals the “spectrum” of frequencies inside any signal.

The Fourier series formula

Any periodic function f(x) can be written as an infinite sum:

f(x) = a₀/2 + Σ [aₙ cos(nx) + bₙ sin(nx)]

Each term in the sum is a “harmonic”: a cosine or sine wave at a whole-number multiple of the fundamental frequency. The coefficients aₙ and bₙ control the amplitude and phase of each harmonic. Adding more harmonics makes the approximation more accurate.

How to interact with this visualizer

  • Add or remove harmonics by adjusting the number of frequency components. Watch how the approximation sharpens with each added term.
  • Change amplitudes: dragging a slider changes how much of that frequency is present in the composite signal.
  • Square wave: start with the square wave preset to see the classic Gibbs phenomenon - the overshoot near discontinuities that never fully disappears.
  • Rotating phasors: the spinning arrows (phasors) each represent one harmonic; their sum traces the output waveform.

Why it matters

The Fourier transform is one of the most widely applied mathematical tools in existence:

  • Audio (MP3): MP3 compression uses a modified discrete cosine transform (closely related to Fourier) to remove frequency components the human ear cannot easily hear, reducing file size by 10× or more.
  • Images (JPEG): JPEG applies a 2-D discrete cosine transform to 8×8 pixel blocks, then discards high-frequency details below a threshold.
  • MRI scanners: A raw MRI scan is collected in “k-space” (Fourier domain); the image you see on screen is the inverse Fourier transform of that raw data.
  • Signal processing: Radio, radar, Wi-Fi, and every communications technology relies on Fourier analysis to separate signals from noise.

Real-world connections

When a guitar string vibrates, it produces a fundamental frequency plus overtones (harmonics) at integer multiples of that fundamental. The timbre that distinguishes a guitar from a piano playing the same note is entirely determined by the relative amplitudes of those harmonics - exactly what the Fourier series captures. Adjusting the sliders in this visualizer is literally the same mathematics as an audio equalizer or a synthesizer’s harmonic control.

The Fast Fourier Transform (FFT)

Computing the Discrete Fourier Transform (DFT) directly requires O(n²) operations - impractically slow for large signals. The Cooley–Tukey FFT algorithm (1965) reduced this to O(n log n), making real-time audio analysis and image processing feasible. The FFT is the algorithm behind spectrograms, noise-canceling headphones, WiFi signal decoding, and JPEG image compression.

Common waveform decompositions

WaveformHarmonic content
Sine waveSingle frequency only - the purest tone
Square waveOdd harmonics only: fundamental + 1/3 + 1/5 + 1/7…
Sawtooth waveAll harmonics: fundamental + 1/2 + 1/3 + 1/4…
Triangle waveOdd harmonics with alternating signs: 1 − 1/9 + 1/25…