Fourier Series & the Fourier Transform
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.
Use the guided Signal Garden project to turn sine-wave relationships into animated ribbons, flow fields, and demoscene compositions.
π‘ 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.
π¨βπ¬ Who Was Joseph Fourier?
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.
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:
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.
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.
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.
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.
π 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.
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.
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.
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.
π 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.
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.
β« 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.
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.
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.
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
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.
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.
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.
Spectrogram β frequency (up) against time (rightwards)
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.
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.
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.
βοΈ 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
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?