Fourier Series & the Fourier Transform

Mathematics Lesson 13 Waves & Analysis ~55 min 6 interactive labs

Fourier methods represent signals using sine and cosine components. They help analyze sound, images, and data from MRI scanners, with different assumptions in each setting. In this lesson you will stack components to approximate a repeating wave, hear harmonics arrive one at a time, draw a wave with your finger and inspect its frequency recipe, then explore an image-compression model.

  • 🎑 Spin epicycles
  • πŸ”Š Hear each harmonic
  • ✏️ Draw your own wave
  • πŸ” Magnify Gibbs
  • 🎀 Analyse live sound
  • πŸ–ΌοΈ Compress an image
Code with waves

Use the guided Signal Garden project to turn sine-wave relationships into animated ribbons, flow fields, and demoscene compositions.

Download Creative Coding Pack

🎑 Start here: a sine wave is just a circle, unrolled

Watch the dot go around the circle at a steady speed. Its height is traced out to the right as time passes β€” and that trace is exactly a sine wave. Nothing else. Every idea in this lesson grows from this one picture: a sine wave is circular motion seen from the side. Fourier's claim was that if you allow yourself enough circles, spinning at whole-number multiples of each other, you can trace any repeating shape at all.

the spinning circle the height it traces = sin(ΞΈ)

πŸ‘¨β€πŸ”¬ Who Was Joseph Fourier?

Jean-Baptiste Joseph Fourier
1768 – 1830 Β· French Mathematician & Physicist
Fourier was born to a tailor in Auxerre, France, and orphaned at age nine. He rose to become a professor, was nearly guillotined during the French Revolution, accompanied Napoleon to Egypt as a scientific adviser, governed a French province β€” and, in his spare hours, invented the mathematics that now runs inside every phone on Earth.
1807
On the Propagation of Heat in Solid Bodies Fourier submits a paper to the French Academy of Sciences claiming that heat flow can be described by trigonometric series. Reviewers Lagrange and Laplace are unimpressed β€” Lagrange in particular refuses to believe that a sum of smooth sines could ever produce a sharp corner. The paper is not published.
1811
He wins the prize anyway β€” with an asterisk Fourier enters a rewritten version in the Academy's prize competition on heat. He wins, but the judges attach a public note complaining about a lack of rigour. He was right and they were right: the idea was correct, and the proof of exactly when it works took another century.
1822
ThΓ©orie analytique de la chaleur After fifteen years of refinement he publishes his masterwork β€” The Analytical Theory of Heat. It introduces the Fourier Series, and reshapes mathematical physics permanently. In the same era he also describes what we now call the greenhouse effect.
1829
Dirichlet supplies the proof Peter Gustav Lejeune Dirichlet finally proves convergence for a broad class of functions, settling the argument the 1807 reviewers started. Chasing the edge cases of "which functions have a Fourier series?" later pushed Cantor into inventing set theory.
1898
A brass machine finds the wiggle Albert Michelson builds a mechanical harmonic analyser out of springs and gears. It keeps overshooting near sharp jumps, and he suspects a mechanical fault. J. Willard Gibbs shows the machine is fine β€” the overshoot is real mathematics. You will magnify it yourself in Lab D.
1965
The Fast Fourier Transform (FFT) Cooley & Tukey publish an algorithm that computes Fourier transforms enormously faster. It becomes arguably the most important numerical algorithm of the 20th century β€” and it turns out Gauss had already worked out the same trick in 1805, in a notebook nobody read.
Today
Many applications Fourier methods help encode audio, transmit wireless signals, compress JPEG images, reconstruct MRI data, and analyze signals in scientific instruments.

Fourier's key insight started with a humble problem: how does heat spread through a metal bar? Heat flow is easy to describe for one smooth sine-shaped temperature pattern β€” each such pattern just fades away at its own steady rate. So Fourier asked the audacious question: can any starting temperature be written as a sum of sines? If yes, then a hard problem becomes a pile of easy ones. The answer β€” yes β€” launched a revolution that we still live inside today.

πŸ”Š What Is a Fourier Series?

A Fourier Series expresses a periodic function as a sum of sine and cosine waves β€” each at a whole-number multiple of one base frequency. Think of it as musical harmony: a rich chord is really just several pure tones sounding at once, and your ear is doing the decomposition.

f(x) = aβ‚€/2 + Ξ£β‚™ [ aβ‚™Β·cos(nx) + bβ‚™Β·sin(nx) ] aβ‚€/2 is the average level (the "DC offset"); aβ‚™ and bβ‚™ say how much of frequency n is present, and in what mix of cosine and sine

The vocabulary, in one place

  • Fundamental β€” the slowest wave, n = 1. It sets the pitch you hear and the period of the whole shape.
  • Harmonic β€” wave number n, spinning n times faster than the fundamental.
  • Amplitude β€” how tall harmonic n is. Written √(aβ‚™Β² + bβ‚™Β²).
  • Phase β€” where in its cycle harmonic n starts. The aβ‚™-vs-bβ‚™ mix is just phase in disguise, because aΒ·cos(nx) + bΒ·sin(nx) = RΒ·sin(nx + Ο†).
  • Spectrum β€” the whole list of amplitudes, drawn as bars. The signal's "recipe card".
  • Partial sum β€” what you get when you stop after N terms. Every lab on this page draws a partial sum.

Building a Square Wave

The classic demonstration is the square wave. A perfect square wave jumps instantly between +1 and βˆ’1 β€” the complete opposite of a smooth sine. Yet Fourier proved it can be built from sines alone:

square(x) = (4/Ο€) Β· [ sin(x) + sin(3x)/3 + sin(5x)/5 + sin(7x)/7 + … ] odd harmonics only, amplitudes shrinking as 1/n β€” more terms β†’ sharper corners

Each term adds one more harmonic. The fundamental (n=1) sets the pitch. The 3rd harmonic (n=3) flattens the tops. The 5th, 7th, 9th… each sharpen the corners a little more. Only with infinitely many terms do you get a perfect square.

n = 1
Fundamental
The base sine wave. Sets the frequency β€” and carries about 81% of the square wave's total energy all by itself.
n = 3
3rd Harmonic
3x the frequency, β…“ the amplitude. Pushes the middle of each hump down and starts flattening the top.
n = 5, 7, 9…
Upper Harmonics
Small, fast ripples that live almost entirely near the corners. Detail costs high frequency.
n β†’ ∞
The limit
Converges to a perfect square everywhere except right at the jump β€” see the Gibbs lab below.

Why only odd harmonics? A square wave has a symmetry: shift it half a period and it flips upside-down. Every even harmonic survives that half-period shift unchanged, so it would break the symmetry β€” the only way to respect it is for all even coefficients to be exactly zero. In Lab A, switch to the pulse wave and drag the duty cycle away from 50%: you are breaking that symmetry by hand, and you will watch the even harmonics grow straight out of the floor.

πŸŽ›οΈ Lab A Β· Synthesis

The Epicycle Waveform Builder

Circles stacked tip-to-tail, each spinning n times faster and shrinking as it goes. The final tip drags out the wave you see on the right. Add terms and watch a stack of smooth circles conjure a sharp corner β€” then press Hear it and listen to the same thing happen in your ears.

Try muting n=1
1
1.2x
Epicycles β†’ the wave they draw
Each harmonic, drawn separately
Partial sum vs the ideal target
partial sum (what you get) ideal target (what you want)

Spectrum β€” click any bar to mute that harmonic

Bar height = amplitude of that harmonic. Greyed bars are not in the sum yet; hatched red bars are ones you have muted. Mute the fundamental and the wave keeps its shape but loses its bass β€” exactly what a small phone speaker does to music.

1 Terms in sum
1 Highest harmonic
β€” Mean error vs target
β€” Energy captured
sin(x) Current series

πŸ”Ž How Do You Find the Recipe?

Building a wave out of harmonics you already know is the easy direction. The hard β€” and far more useful β€” direction is the reverse: someone hands you a messy signal and you must work out which frequencies are hiding inside it. That is analysis, and Fourier's trick for it is startlingly simple.

bβ‚™ = (1/Ο€) βˆ«β‚€^2Ο€ f(x) Β· sin(nx) dx multiply your signal by the frequency you are hunting for, then average over one period

Why does multiplying and averaging work? Because of a property called orthogonality. Multiply two sine waves of different whole-number frequencies and average the result over a full period, and you always get exactly zero β€” the product spends as much time positive as negative. But multiply a sine wave by itself and the product is never negative, so the average is a healthy positive number.

So the integral acts like a tuning fork. Every frequency that is not in your signal cancels itself into nothing, and only the matching frequency leaves a residue. That single idea β€” probe with a wave, average, keep what survives β€” is the whole of Fourier analysis. The lab below lets you do the probing by hand.

Worked example β€” the first coefficient of a square wave. Take f(x) = +1 on (0, Ο€) and βˆ’1 on (Ο€, 2Ο€), and probe with sin(x):

b₁ = (1/Ο€)[ βˆ«β‚€^Ο€ (1)Β·sin x dx + ∫_Ο€^2Ο€ (βˆ’1)Β·sin x dx ] = (1/Ο€)[ 2 + 2 ] = 4/Ο€ β‰ˆ 1.273

That 4/Ο€ is exactly the leading amplitude in the square-wave formula above. Notice it is bigger than 1 β€” the fundamental alone overshoots a wave that never exceeds 1, and the higher harmonics spend their lives pulling it back down. Probe the same square wave with sin(2x) and the two halves cancel exactly: bβ‚‚ = 0, which is the "odd harmonics only" rule falling out of the arithmetic.

πŸ•΅οΈ Lab B Β· Analysis

The Frequency Detector

A mystery signal is hiding two or three pure tones. Sweep the probe frequency and watch what happens to the shaded area under the product: almost everywhere it cancels to nothing, but when your probe locks onto a frequency that really is in there, the area suddenly piles up on one side. That spike is the Fourier coefficient.

Hunt the hidden tones
1.00
β‘  The mystery signal f(x)
β‘‘ Multiply it by your probe: f(x)Β·sin(kx)
area above the axis area below the axis if they balance, the frequency is not in the signal
β‘’ Detector output for every k β€” the spectrum, built by sweeping
1.00 Probe frequency
0.00 Detector output
β€” Verdict
hidden True recipe
✏️ Lab C · Your turn

Draw a Wave, Read Its Recipe

Drag inside the top panel to draw any shape you like across one period. The page runs the multiply-and-average procedure on your drawing 32 times β€” once per harmonic β€” and immediately rebuilds your curve out of nothing but sines and cosines. Slide the term count down to watch your drawing dissolve into its own blurry outline, which is precisely what lossy compression does.

Draw a spike, then compress it
8
Your drawing (drag here) + the rebuild from N harmonics
what you drew rebuilt from harmonics
Your drawing's spectrum β€” amplitude of each harmonic
8 Harmonics kept
β€” Energy captured
β€” RMS error
n = 1 Strongest harmonic
β€” Numbers stored vs samples

πŸ“ˆ The Stubborn 9%: the Gibbs Phenomenon

Here is the strangest fact in this whole lesson. Take a square wave and add more and more harmonics. The approximation gets better everywhere β€” except right beside the jump, where the partial sum always shoots past the target by the same stubborn amount, no matter how many terms you throw at it. Adding harmonics makes the overshoot narrower, never shorter.

The peak of the partial sum climbs to about 1.17898 against a target of 1 β€” an overshoot of roughly 17.9% of the target height, or about 8.95% of the total jump of 2. That number is not an accident of arithmetic; it is (2/Ο€)Β·Si(Ο€), where Si is the sine-integral function, and it is the same for every jump discontinuity in every function anyone will ever write down.

This is not a bug to be fixed. It is the mathematics telling you something physical: a perfectly sharp edge needs infinite bandwidth. Any real system β€” a speaker, a camera lens, a radio channel, a JPEG file β€” has a finite frequency ceiling, so every sharp edge it reproduces comes with a little ring beside it. Those faint halos you sometimes see hugging high-contrast edges in a heavily compressed photo are Gibbs, sitting right there in your holiday snaps.

πŸ” Lab D Β· Magnifier

Magnify the Overshoot

Crank the harmonics all the way to 200 and zoom into the jump. Watch the ripple squeeze itself into an ever-thinner sliver against the edge β€” while the height of that first peak refuses to budge.

Limit β‰ˆ 8.9490%
8
1x
Partial sum near the jump β€” the dotted line is the 1.17898 limit
Overshoot vs harmonic count — it drops fast, then stops
β€” Peak value
β€” Overshoot (% of jump)
β€” Ripple width
8.9490% Theoretical limit

∫ From Series to Transform

The Fourier Series works for periodic functions β€” ones that repeat forever. But what about a single drum hit, a spoken word, or one heartbeat on an EKG? Those never repeat. For them we need the Fourier Transform, which you can think of as a Fourier Series in the limit where the period is stretched out to infinity, so the discrete comb of harmonics fills in and becomes a continuous smear of frequency.

Fourier Series
Periodic Functions

Decomposes a repeating wave into a discrete set of frequencies β€” only whole-number harmonics (n = 1, 2, 3…) exist. In: a periodic function. Out: a list of amplitudes and phases. Spectrum looks like a picket fence.

Fourier Transform
Beyond periodic signals

Represents a broad class of signals, including one-time events, with a continuous frequency spectrum. The transform requires suitable mathematical conditions. Its spectrum can show where frequency content is concentrated.

FΜ‚(ΞΎ) = βˆ«β‚‹βˆž^∞ f(x) Β· e^(βˆ’2Ο€iΞΎx) dx the same multiply-and-average trick as before β€” the complex exponential just probes with sine and cosine at the same time

Euler's formula eiΞΈ = cos(ΞΈ) + iΒ·sin(ΞΈ) is what makes that compact notation work: the complex exponential is a cosine and a sine bolted together, which is exactly the pair of probes you need to catch a wave of unknown phase. This is the same spinning-circle picture from the top of the page, written in the language mathematicians actually use.

Time Domain vs Frequency Domain

  • Time domain β€” the signal as it changes moment to moment. What an oscilloscope shows you.
  • Frequency domain β€” the same signal sorted into its component pitches. What a graphic equaliser shows you.

Neither view is more "real" than the other; they hold identical information, just filed differently. The reason we bother switching is that problems which are horrible in one view are often trivial in the other. Removing a 60 Hz hum from a recording means hunting an invisible squiggle in the time domain β€” but in the frequency domain it is one tall spike you can simply delete.

Two rules the transform will not let you break

Rule 1
The uncertainty principle

A signal cannot be both brief in time and narrow in frequency. Squeeze it in one domain and it spreads in the other. A very short click contains every pitch at once; a very pure pitch must last a long time. This is the same theorem that gives quantum mechanics its uncertainty principle β€” the physics is downstream of the mathematics.

Rule 2
Nyquist & aliasing

To capture a frequency you must sample at more than twice that rate. Sample too slowly and high frequencies come back disguised as low ones β€” this is why wagon wheels spin backwards in old films, and why CDs sample at 44.1 kHz to cover human hearing up to about 20 kHz.

The Fast Fourier Transform (FFT): computing a transform directly on N samples costs about NΒ² multiplications. In 1965 Cooley and Tukey published a way to do it in NΒ·log N by noticing that the calculation contains the same sub-sums over and over. For a 1024-point transform that is roughly a hundred-fold speed-up; for a million points it is about fifty thousand-fold. That gap is the difference between "theoretically possible" and "runs on a phone while you walk", which is why the FFT quietly underwrites the whole of modern digital life.

🎀 Lab E · Live signal

The Spectrum Lab

A real FFT, running about sixty times a second, on real sound. Play the built-in timbres and compare their spectra β€” a flute is nearly one bar, a sawtooth is a whole staircase. Then turn on the microphone and watch your own voice paint the spectrogram. Whistling gives you a single clean line; saying "shhh" floods the whole top end.

Try whistling
220 Hz
Time domain β€” the oscilloscope view
Frequency domain β€” the FFT view

Spectrogram β€” frequency (up) against time (rightwards)

β€” Loudest frequency
β€” Nearest note
Idle Source
1024 FFT bins

Audio starts only when you press a button. The microphone needs your browser's permission, is never recorded, and never leaves this page β€” turn it off again with the same button.

πŸ–ΌοΈ Lab F Β· Two dimensions

Pictures Are Waves Too

JPEG chops an image into 8x8 blocks and rewrites every block as a sum of the 64 striped patterns below. Most blocks turn out to be nearly all low-frequency, so the file throws the rest away. Drag the slider to decide how many coefficients per block survive, and watch the picture degrade in the distinctive blocky, ringing way you have seen a thousand times online.

Slide to 2 and look at the edges
6
Original
Rebuilt from kept coefficients
What was thrown away
6 / 64 Coefficients per block
10.7x Data reduction
β€” Quality (PSNR)
β€” Energy captured

Notice how forgiving the smooth areas are and how badly the sharp edges suffer. That is Gibbs again, in two dimensions β€” and it is why text and line art look terrible as JPEGs while photographs of clouds survive brutal compression almost untouched.

🌍 Real-World Applications

Fourier's mathematics is not a museum piece. It is running, right now, in the device you are reading this on β€” probably several times a second.

Audio & Music
MP3 and AAC use frequency-domain ideas and perceptual models to compress audio. The amount removed and what a listener notices depend on the encoding settings and the sound.
MRI Scanning
An MRI machine does not photograph you. It measures the frequency domain directly β€” radiologists call it "k-space" β€” and an inverse Fourier transform turns those numbers into the picture the doctor reads.
JPEG Images
JPEG commonly transforms 8Γ—8 image blocks and quantizes their frequency coefficients. Lab F is a simplified version; other image formats use different methods.
WiFi & 5G
OFDM packs data onto hundreds of overlapping frequency carriers at once, and separates them again with an FFT. Orthogonality β€” the same cancelling trick from Lab B β€” is what keeps the channels from smearing into each other.
Noise Cancelling
Headphones analyse the roar around you, work out its frequency make-up, and emit exactly that spectrum flipped upside down. Two waves that cancel are just a negative Fourier coefficient.
Seismology
Geologists decompose earthquake traces into frequencies to tell fault types apart, locate epicentres, and X-ray the interior of the planet using the ringing it makes.
Radio Astronomy
A radio telescope array does not record an image β€” it records interference patterns, which are the image's Fourier transform. The Event Horizon Telescope's black hole photograph was assembled this way.
Gravitational Waves
LIGO's black-hole "chirp" is buried far below the noise in the time domain and completely invisible. In the frequency domain, with the right filter, it stands out clearly enough to win a Nobel Prize.

✏️ Practice Problems

Work these out on paper first β€” the labs above will confirm every answer.

1. A square wave has fundamental frequency 100 Hz. What are the frequencies of the next three harmonics that actually appear in it, and how tall is each compared with the fundamental?

Show answer

300 Hz, 500 Hz and 700 Hz β€” only odd multiples appear. Their amplitudes are 1/3, 1/5 and 1/7 of the fundamental (about 33%, 20% and 14%). Check it in Lab A: set the target to square and read the spectrum bars.

2. A triangle wave and a square wave both use only odd harmonics. The triangle's amplitudes fall off as 1/nΒ² while the square's fall off as 1/n. Which one needs fewer terms to look right, and why does that make sense from the shape?

Show answer

The triangle. Its coefficients shrink much faster β€” the 9th harmonic is 1/81 of the fundamental rather than 1/9 β€” so the tail contributes almost nothing. That matches the shapes: a triangle has corners but no jumps, and a corner is a much gentler kind of sharpness than a vertical cliff. Sharper features always cost more high frequency.

3. You are recording a bird whose song reaches 9 kHz. Your recorder samples 12,000 times a second. What goes wrong, and what would you change?

Show answer

You need to sample above twice the highest frequency β€” above 18 kHz here β€” so 12 kHz is far too slow. The 9 kHz content will alias, folding back and appearing as a spurious low tone that was never in the air. Fix it by sampling at 44.1 kHz, or by filtering out everything above 6 kHz before sampling so there is nothing left to fold.

4. In Lab B you probe the mystery signal with k = 2.5 and the detector reads almost zero. Does that prove there is no energy near frequency 2.5 in the signal?

Show answer

For a signal that is exactly periodic over the window, yes β€” non-integer frequencies genuinely cannot be present, because the signal is built from whole harmonics only. But be careful with real measurements: a sine probe alone also returns zero for a component that is 90Β° out of phase with it (a pure cosine). That is precisely why the real transform probes with sine and cosine together, and reports the amplitude √(aΒ² + bΒ²).

5. Lab F stores 6 numbers instead of 64 per block. Estimate the data reduction, and explain why the picture does not look 10 times worse.

Show answer

About 10.7x fewer numbers. The image survives because the energy is not spread evenly across the 64 patterns β€” natural images are dominated by a few low-frequency ones, so a handful of coefficients typically carry well over 95% of the energy in a block. Compression is only possible because real data is lopsided like this; genuinely random noise cannot be compressed at all.

βœ… Check Your Understanding

0 of 10 answered

1. What was the original problem that led Fourier to develop his series?

2. A square wave's Fourier series uses only which harmonics?

3. Why does multiplying a signal by sin(nx) and averaging pick out just one frequency?

4. What is the key difference between a Fourier Series and a Fourier Transform?

5. The Gibbs phenomenon describes what behaviour near a sharp jump?

6. In Lab A, which change makes even-numbered harmonics appear?

7. A signal is a very short click. What does its frequency spectrum look like?

8. You record a 9 kHz sound while sampling only 12,000 times per second. What happens?

9. Why does JPEG compression work well on photographs of clouds but badly on screenshots of text?

10. An MRI machine measures signals in "k-space". What does that mean?

See it in context β†’ The Equations Iceberg