The goal
We want the output to be a square wave: +1 V for half a millisecond, then −1 V, over and over. It repeats every T0 = 1 ms, so its frequency is f0 = 1/T0 = 1 kHz. Can smooth sines make sharp corners?
Adding sines
Switch in a 1 kHz sine of amplitude 4/π ≈ 1.27 V. It has the same period as the square and rises and falls with it. Close, but round, and too high in the middle: 1.27 V at t = 0.25 ms.
Only sines that fit a whole number of times into T0 repeat every T0: f0, 2f0, 3f0 ... These are the harmonics. Watch the dials: harmonic k turns k times while the first turns once. Each arm's length is its amplitude.
Switch in 3 kHz with amplitude 4/(3π) ≈ 0.42 V. At t = 0.25 ms it is at its lowest, so it pulls the bump down: 1.27 − 0.42 = 0.85 V. The top flattens and the edges get steeper.
Add 5 kHz (0.25 V) and 7 kHz (0.18 V). With four sines the output at t = 0.25 ms is 0.92 V, and the wave already looks square. Each new harmonic corrects some of the error that is left.
Finding the amplitudes
Where does 0.42 V come from? Multiply the square by a 3 kHz sine, average over one period, double it: b3 = (2/T0)∫x(t)·sin(3ω0t)dt = 4/(3π). This is a correlation: how much of that sine the wave holds.
For even k the integral is 0: the second half of the square is the first half flipped, which cancels them. Amplitude against frequency is the spectrum: lines at 1, 3, 5, 7 kHz of 1.27, 0.42, 0.25, 0.18 V, shrinking as 1/k.
Many sines
In Python with numpy, t holds 1000 instants 1 µs apart: one period. The loop adds the odd harmonics k = 1, 3 ... 49, which is 25 sines, far more than the bench. np.sin works in radians, so w = 2π·1000.
With 25 sines the edges are steep, yet each jump still overshoots to 1.18 V. More sines squeeze the ripple narrower but not lower: it stays near 9% of the 2 V jump. This is the Gibbs phenomenon.
The square is one example. A periodic signal met in practice (a voice vowel, a violin note, a clock signal) is a sum of its harmonics with its own amplitudes and phases. Next, the Fourier transform does this for signals that never repeat.
The working
# step 1/10 · square target x(t), one period T0 = 1 ms: +1 V for 0 <= t < 0.5 ms −1 V for 0.5 <= t < 1 ms then it repeats: x(t + T0) = x(t) f0 = 1 / T0 = 1 / 0.001 s = 1000 Hz = 1 kHz Fourier's claim: a periodic signal is a sum of sines at f0, 2·f0, 3·f0 ... (harmonics)
The square wave (±1 V, 1 kHz) is a chosen example. Every amplitude, curve and value in the figure is computed from the coefficient integrals in this model; the closed form b_k = 4/(πk) is used only to check them. The motion is slowed down a great deal: a real 1 kHz oscillator turns its phasor a thousand times a second.