Waves & Oscillations · Simulation
20 February 2026 · Updated 15 November 2026 · on the concept map
Fourier Series: How Sine Waves Build Any Shape
A sine wave is the plainest sound there is: a smooth, endless up-and-down, like the hum of a tuning fork. A square wave is the opposite: flat, then a sudden jump, flat again, then a sudden drop. It seems impossible to make one from the other. Yet add the right sine waves together, in the right sizes, and the corners of a square wave appear out of nothing but smooth curves.
That is the idea behind the Fourier series: almost any repeating shape, however jagged, is a sum of sine waves whose frequencies are whole-number multiples of one basic frequency. Joseph Fourier put it forward in 1807 while trying to work out how heat spreads through a metal bar. Two centuries later the same idea sits inside music synthesisers, image compression, the radio in your phone and the mathematics of quantum mechanics. On this page you can stack the sines yourself, watch the shape sharpen, and see the one place where the sum never quite behaves.
What Is a Fourier Series? Sounds as Recipes of Sine Waves
Think of a repeating shape as a dish and the sine waves as its ingredients. A Fourier series is the recipe: a list of which sine waves go in and how much of each. The ingredients are not chosen freely. If the shape repeats 100 times a second, the only sines allowed are the ones that also fit a whole number of times into each repeat: 100 times a second, 200, 300, 400 and so on. The recipe says how much of each to use, and that is all it says.
This is a strong claim. It says that the shape of the wave, the thing you see on an oscilloscope, and the list of amounts, the thing you would see on a bar chart of frequencies, carry exactly the same information. You can go from one to the other and back without losing anything. The waveform is the dish; the bar chart is the recipe; they describe the same thing in two languages.
What are harmonics?
The ingredients have a name. The slowest one, the frequency at which the whole shape repeats, is the fundamental. The others are its harmonics: the 2nd harmonic at twice the fundamental frequency, the 3rd at three times, and so on. On a guitar string these are real, physical vibrations. A plucked string vibrates as a whole, in halves, in thirds and in quarters all at once, and each of those patterns is one of the standing waves on a string with its own whole-number frequency. The Fourier series is the mathematics of that mixture.
Why do a violin and a flute sound different on the same note?
Play concert A, 440 Hz, on a flute and on a violin. The pitch is the same because the fundamental is the same: both waves repeat 440 times a second. What differs is the recipe. A flute's tone is close to a pure sine, with a strong fundamental and only small amounts of the upper harmonics, which is why it sounds soft and round. A bowed violin string is dragged along by the bow and then snaps back, over and over, and the wave it sends into the body of the instrument is close to a sawtooth. A sawtooth contains every harmonic, falling off steadily in size, which gives the violin its bright, buzzing edge. A clarinet in its low register favours the odd harmonics, a little like the square wave you will build below, which is part of its hollow, woody sound.
This quality, the thing that lets you tell two instruments apart at the same pitch and loudness, is called timbre, and to a large extent it is the recipe of harmonics. Your ear does a rough Fourier analysis of its own: different parts of the cochlea respond to different frequencies, so the brain receives something closer to the bar chart than to the waveform. When a synthesiser copies an instrument by mixing harmonics, or an equaliser turns up the treble, it is editing the recipe directly.
How Do You Build a Square Wave from Sine Waves?
Start with a single sine wave at the fundamental. It already has the right rhythm: up for half the cycle, down for the other half. But it is rounded where a square wave is flat, and it overshoots, peaking at about 1.27 when the square wave sits at 1. Now add the 3rd harmonic, one third as tall. Where the fundamental bulges, the 3rd harmonic pushes back down; near the edges, it pushes up. The top flattens and the sides steepen. Add the 5th harmonic at one fifth the size, then the 7th at one seventh, and each one fixes a little more of what the earlier ones got wrong. The square wave uses only odd harmonics, and the size of harmonic n is proportional to 1/n.
Choose a wave type and drag the harmonics slider in the simulation below. The upper graph shows the sum (solid) against the exact wave it is building towards (dotted). The lower graph shows the size of each harmonic in the recipe: the same bar chart your ear works from.
Things to Try
- Square wave, 1 harmonic. You see a single sine wave peaking at 1.27, which is 4/π. Raise the slider to 3, then 5, and watch the top flatten and the sides steepen. The bars appear only at odd n: a slider value of 5 means harmonics 1 to 5, with the even ones at zero.
- Square wave, 30 harmonics. Look at the corners. The sum still overshoots each jump and peaks at about 1.18, not 1. Go back to 9 and 15 harmonics and compare the peak in the readout: 1.18 both times. That overshoot is the Gibbs phenomenon, and it never goes away; it only gets narrower.
- Triangle wave, 3 to 5 harmonics. It already looks almost exact. Its harmonics shrink as 1/n², so the bars fall away much faster than the square wave's.
- Sawtooth wave. It uses every harmonic, even and odd. Watch the peak creep upwards as you add harmonics (about 1.01 at 5, 1.15 at 30): the steep drop at the middle is a jump, so the sawtooth gets its own Gibbs overshoot too.
- Compare all three at 5 harmonics. The triangle is nearly perfect, while the square and the sawtooth both still ripple, worst beside their jumps. Smoothness of the target decides how fast the sum gets there.
Why Do Some Fourier Series Converge Faster Than Others?
All three waves in the simulation are made of sines, yet with the same number of harmonics the triangle looks finished and the square wave still ripples. The reason is in the bars. How fast the harmonic sizes shrink tells you how fast the sum settles down to the target, and how fast they shrink depends on how smooth the target is.
Square and sawtooth waves: harmonics that fall as 1/n
A square wave jumps. A sudden jump is a very sharp feature, and only fast-wiggling sines can draw something that sharp, so the recipe has to keep a lot of high harmonics: the 99th harmonic is still one ninety-ninth the size of the fundamental. A sawtooth has a jump too, once per cycle, and its harmonics also fall as 1/n. With harmonics that shrink this slowly, every new term still makes a visible change, and the ripples along the flat parts die away only slowly.
Triangle wave: harmonics that fall as 1/n²
A triangle wave never jumps. It has corners, places where its slope changes suddenly, but the wave itself is continuous. Corners are gentler than jumps, and the recipe reflects that: the harmonics fall as 1/n². The 9th harmonic of a square wave is one ninth the size of the fundamental; the 9th harmonic of a triangle wave is one eighty-first. By the time you have three odd harmonics in, the remaining ones are almost too small to see.
One way to feel the difference: the fundamental alone carries about 81% of a square wave's power, but about 98.6% of a triangle wave's. A triangle wave is, very nearly, a single sine wave with a little sharpening at the tips.
The rule: smoothness sets the speed
This is a general rule, not a coincidence of these three shapes. A wave with jumps has harmonics that fall as 1/n. A wave with no jumps but with sharp corners has harmonics that fall as 1/n². Smooth the corners out as well and the harmonics fall faster still. The smoother the shape, the faster the recipe runs out of important ingredients. It is also why a muted, mellow tone has little treble, and why a click or a snare hit, both sudden, spreads across a wide band of frequencies.
What Is the Gibbs Phenomenon?
Add harmonics to the square wave and you might expect the sum to fit it more and more snugly, everywhere. Away from the jumps, it does. But right next to each jump the sum overshoots, climbing past the top of the square wave before settling back, and that overshoot refuses to shrink. This stubborn spike is the Gibbs phenomenon.
Why the 9% overshoot never goes away
In the simulation the square wave runs from −1 to +1, so each jump is 2 units tall. With many harmonics the sum peaks at about 1.18 next to every jump: it overshoots by about 0.18, which is about 9% of the size of the jump (or about 18% of the 1-unit height on either side of zero). Add 10 harmonics or 10,000 and the overshoot stays at that height. What changes is its width. The spike gets narrower and hugs the jump more closely, so it takes up less and less of the cycle, but its peak does not come down.
This sounds like the series has failed, and in a sense it is a real limit: a sum of finitely many smooth sines cannot make a clean jump. But on average the fit does keep improving. The region where the sum is wrong shrinks towards nothing, and at the exact point of the jump the series lands halfway, at zero, the average of the two sides. Mathematicians say the series converges at every point, but not uniformly: there is always a sliver near the jump where it is still badly off.
Where Gibbs ringing shows up
The Gibbs phenomenon is not just a curiosity of textbooks. Any time a signal with a sharp edge has its high frequencies cut off, the edge picks up ripples. A heavily compressed JPEG shows faint halos beside sharp edges, partly for this reason. An MRI scan, which is built from a limited range of spatial frequencies, can show "truncation" ripples beside sharp tissue boundaries, and radiologists call them Gibbs artefacts. An audio filter with a very steep cut-off makes a sharp click ring. Engineers soften those edges on purpose, by tapering the high harmonics instead of chopping them off, to keep the ringing down. That trade-off is at the heart of the low-pass and high-pass filters in every piece of audio equipment.
Who Invented the Fourier Series? Joseph Fourier and the Heat Equation
The series is named after Joseph Fourier, a French mathematician who had travelled with Napoleon's expedition to Egypt and then served as a regional governor in Grenoble. He was not trying to analyse sound. He wanted to know how heat flows.
The 1807 memoir and its doubters
Picture an iron bar heated unevenly, hot in some places and cool in others. How does the pattern of temperature change over time? Fourier wrote down an equation for it, now called the heat equation, and found that he could solve it easily if the starting temperature happened to be a sine-shaped curve along the bar. His bold step was to claim that any starting temperature, even one with sudden jumps, could be written as a sum of such sine curves. Solve for each sine separately, add the answers, and you have solved the whole problem.
He presented this to the Paris Institute in December 1807. The examiners, who included Lagrange and Laplace, were not convinced. The idea that a sum of smooth curves could produce a jump looked wrong to some of the best mathematicians alive, and Fourier's arguments were not rigorous. His later prize essay won the Institute's prize in 1812 but was still criticised for its lack of rigour, and his full account, The Analytical Theory of Heat, only appeared in 1822. The rigorous proof of when the series works came later, from Dirichlet in 1829. Fourier was right about the big idea long before anyone could prove it.
Why heat smooths out: high harmonics die first
Fourier's solution has a lovely physical meaning. Each sine-shaped temperature pattern fades away at its own rate, and the rate grows with the square of the harmonic number: the 3rd harmonic fades 9 times faster than the fundamental, the 10th harmonic 100 times faster. Sharp features in the temperature, which are made of high harmonics, vanish almost at once. Broad, gentle differences, made of the low harmonics, linger. This is why a hot spot on a metal plate blurs out quickly at first and then fades slowly, and why the temperature along a cooling bar soon looks like a single smooth hump. You can explore how heat moves through solids, liquids and space in conduction, convection and radiation.
Fourier Series: The Math
Everything above can be made exact. This section is for readers who have met calculus.
The Fourier series formula
A periodic function with period can be written as:
where is the fundamental angular frequency and the coefficients , determine how much of each harmonic is present. The term is the average value of the function over one period. Cosine terms carry the part of the shape that is symmetric about , sine terms the part that is antisymmetric. The three waves in the simulation are all odd functions, so only sine terms appear.
How do you find the Fourier coefficients?
The key fact is orthogonality. Multiply two sines of different harmonic numbers together and average over one period, and you get exactly zero:
The same holds for cosines, and any sine times any cosine averages to zero too. So if you multiply by and average, every term of the series vanishes except the one with the same . That single fact lets you pull out each coefficient on its own:
The same "multiply and average" trick is how the Fourier transform tests a recorded signal for each frequency, which is the basis of pulling a signal out of noise with the FFT.
Worked example: the square wave's coefficients
Take (so ) and the square wave for and for . It is odd, so every . For the sine coefficients, the two halves give equal contributions:
When is even, and . When is odd, and . So
which is exactly the first row of the table below, and exactly what the simulation adds up.
Fourier series of square, sawtooth and triangle waves
| Target Wave | Non-zero Terms | Series |
|---|---|---|
| Square wave | Odd harmonics only () | |
| Sawtooth wave | All harmonics | |
| Triangle wave | Odd harmonics only |
Notice that the triangle wave coefficients fall off as (much faster than the square wave's ), which is why it converges more smoothly. Each of these waves runs between −1 and +1. The square wave's coefficients follow from the worked example. The sawtooth here rises linearly as between and and then drops back; the simulation draws the same wave over a window that starts at instead, so its drop falls in the middle, at . The triangle wave is, up to a scale and a shift in time, the integral of a square wave, and integrating a harmonic of number divides its size by : that is where the extra power of comes from.
Parseval's theorem: where the power goes
The average of over a period, the signal's mean power, equals the sum of the powers of its harmonics:
For the square wave, everywhere, so the mean power is 1. The fundamental alone carries of it. For the triangle wave the mean power is , and its fundamental carries , or about 98.6%. That is the precise version of "the triangle looks finished after a couple of harmonics".
The Gibbs constant: where the 9% comes from
For the square wave summed up to harmonic (with odd), the first and highest peak beside the jump at sits at . As grows, its height tends to
The overshoot above the target of 1 is therefore about 0.179. Measured against the full jump of 2, that is about 8.95%, the "9%" quoted for the Gibbs phenomenon. The peak's position moves in towards the jump in proportion to , but its height has a fixed limit: the overshoot narrows and never shrinks. The effect was first described by Henry Wilbraham in 1848 and explained again by J. Willard Gibbs in letters to Nature in 1898 and 1899.
The heat equation solution
For a bar of length whose ends are held at zero temperature, Fourier's heat equation is solved by
where the are the Fourier coefficients of the starting temperature. The decay rate of each term is proportional to , which is why high harmonics, the sharp features, die out first.
Where Are Fourier Series Used?
The Fourier series is one of those ideas that, once seen, turns up everywhere.
Music and sound. Additive synthesisers build tones by mixing harmonics in chosen sizes, and an equaliser boosts or cuts bands of frequencies. When you see a spectrum display bouncing on a music player, you are looking at the recipe of the sound in real time.
Images. JPEG compression splits a picture into small blocks and describes each one with the discrete cosine transform, a close cousin of the Fourier series built from cosines. Most of the fine high-frequency detail is thrown away, because the eye barely notices, and that is where most of the saving in file size comes from.
Signals and noise. For a sound or signal that does not repeat, the series becomes the Fourier transform, which spreads the recipe over a continuous range of frequencies instead of whole-number harmonics. Computers calculate it with the Fast Fourier Transform, and it is how radios, phones and lab instruments separate a signal from noise. See it in action in FFT denoising: recovering a signal from noise.
Quantum mechanics. A particle's wave function in terms of position and its wave function in terms of momentum are Fourier transforms of each other. A short, sharp burst needs many frequencies to build it, which is the idea behind wave packets and the uncertainty principle.
Heat. Fourier's original problem: how a temperature pattern spreads and fades, one harmonic at a time.
From series to transform. The Fourier series works for periodic functions. For non-periodic signals, we generalise to the Fourier transform, which decomposes a function into a continuous spectrum of frequencies rather than discrete harmonics. Learn more in Signal Recovery with the Fast Fourier Transform.
Frequently Asked Questions
Explore more simulations
Every concept on PhysicStuff has an interactive simulation. No login, no setup required.
Keep going.
Related concepts
- FFT Denoising: How the Fourier Transform Pulls a Signal Out of NoiseRunning the transform backwards to strip noise out of a real signal.next step
- How Do Filters Work? Low-Pass and High-Pass Filters Explainedrelated
- Wave Packetsrelated
- Standing Waves and Resonance: Why Everything Has a Natural FrequencyWhere harmonics come from: the whole-number patterns a string or pipe can hold.related
- Coupled Oscillatorsrelated
- Wave Speed Calculator — Frequency, Wavelength and the Wave EquationThe properties of the individual sine components being summed.see also
See how every topic connects on the concept map.
More interactive simulations
- Standing Waves and Resonance: Why Everything Has a Natural Frequency
- How Do Filters Work? Low-Pass and High-Pass Filters Explained
- Wave Speed Calculator — Frequency, Wavelength and the Wave Equation
- FFT Denoising: How the Fourier Transform Pulls a Signal Out of Noise
- The Doppler Effect
- Wave Packets
- Lissajous Figures
Browse every simulation in the PhysicsLab.