# Fourier series > How do sine waves build a square wave? Add harmonics one by one and watch a square, sawtooth or triangle wave take shape, with the Gibbs overshoot and the spectrum. See a Fourier series build a square, sawtooth or triangle wave from 1 to 100 sine terms, with the error, the Gibbs overshoot and the harmonic amplitudes. - Page: https://how.box/fourier/ - Runs entirely in the browser. - License: HowToolbox's own text and data (titles, explanations, FAQs, tool descriptions and schemas, this file) are CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/); AI training and answers are welcome. Attribute "HowToolbox (how.box)" with a link to the page used. Third-party data keeps its own terms; the name and logo are not licensed. Publisher: HowToolbox, contact@how.box. Terms: https://how.box/about/terms/ ## Inputs Answer link: https://how.box/fourier/?w={w}&n={n} - `w` (square, sawtooth or triangle): square, sawtooth or triangle. Example: `sawtooth`. - `n` (whole number 1 to 100): Number of non-zero harmonics. Example: `5`. Example answer: https://how.box/fourier/?w=sawtooth&n=5 A complete link carries the primary answer in the page HTML; a missing or invalid value shows the default page. ## Agent tools - `fourier_series`: Fourier sine series of a square, sawtooth or triangle wave (amplitude 1, period 1) with the first `terms` non-zero harmonics. - MCP, one POST to https://how.box/mcp: `{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"fourier_series","arguments":{"shape":"sawtooth","terms":5}}}` - GET: https://how.box/mcp/run/fourier_series?shape=sawtooth&terms=5 ## How it works Any repeating wave can be built by adding sine waves whose frequencies are whole multiples of the wave's own: the harmonics. This is a Fourier series. Each new harmonic corrects the sum a little more, so the curve hugs the target ever closer. It is how a synthesizer shapes a sound and how an MP3 stores music. For a square wave of height 1 the recipe is (4/π)·[sin(2πx) + sin(6πx)/3 + sin(10πx)/5 + …]: only the odd harmonics, with amplitude 4/(πn) for harmonic n. The sawtooth uses every harmonic with amplitude 2/(πn), and the triangle only odd ones falling as 8/(π²n²), so it converges much faster. With 5 terms the square wave is matched within about 20 % RMS and with 100 within about 4.5 %; the error is found with Parseval's theorem from the amplitudes left out. Next to a jump the sum always overshoots by about 9 % of the jump, however many terms are added: the Gibbs phenomenon. More terms squeeze the ripple closer to the jump but never shrink its height. Sources: MathWorld, "Fourier Series" and "Gibbs Phenomenon"; Paul's Online Math Notes, Lamar University, "Fourier Series". ## FAQ **What does a negative harmonic amplitude mean?** It reverses that sine wave, equivalent to shifting its phase by half a cycle. Keep the sign when adding harmonics; using only their magnitudes would produce a different shape. **What value does the series give exactly at a jump?** It gives the midpoint between the values on either side. For the square and sawtooth waves here, that midpoint is zero. **Does 20% RMS error mean every point is within 20%?** No. RMS error summarizes the squared differences over a whole period, relative to the target wave’s RMS. Individual points can differ by much more, especially near a jump. **Can I analyse a recording or draw my own wave?** No. This explorer builds three preset waves from their known harmonics. It does not analyse audio or accept a custom waveform. **Does five terms mean the fifth harmonic?** Only for the sawtooth, which uses every harmonic. For the square and triangle waves, five non-zero terms reach the ninth harmonic. More: [HowToolbox index](https://how.box/llms.txt) · [Agent Skill](https://how.box/skill.md) · [agent terms](https://how.box/about/agents/)