Mathematics Physics
Building a square wave from sine waves
A square wave switches suddenly between two values. A sine wave changes smoothly. It is surprising, then, that smooth sine waves can be added together to build a square wave. This lesson shows how it works.
The idea
The square wave in this lesson equals \(1\) for \(0 < x < \pi\) and \(-1\) for \(\pi < x < 2\pi\), and then repeats. Its Fourier series uses only sine waves with odd frequencies:
$$f(x) = \frac{4}{\pi}\left( \sin x + \frac{\sin 3x}{3} + \frac{\sin 5x}{5} + \frac{\sin 7x}{7} + \cdots \right)$$Keeping only the first \(n\) terms gives the approximation \(f_n(x)\). Move the slider to add terms one at a time.
Partial sums of the series
What to notice
- More terms, closer fit. Each new term corrects part of the error left by the previous ones, so the curve gets flatter on the top and bottom and steeper at the jumps.
- Only odd frequencies. The square wave has the same shape on both halves of its period, only flipped. Sine waves with even frequencies do not have this property, so their coefficients are zero.
- The overshoot does not go away. Near each jump the sum overshoots to about \(1.18\), roughly 9% of the jump height. Adding terms makes the overshoot narrower but not lower. This is called the Gibbs phenomenon.
Where it appears in physics
The same idea explains why a violin and a flute sound different when playing the same note: each instrument adds a different mix of higher frequencies to the base frequency. In electronics, a square-wave signal from a digital circuit contains many odd harmonics, which is why fast switching can cause interference at higher frequencies.
Practice
-
Write the first three nonzero terms of the series.
Show answer
\(\dfrac{4}{\pi}\sin x,\ \dfrac{4}{3\pi}\sin 3x,\ \dfrac{4}{5\pi}\sin 5x\)
-
With only one term, the peak of the curve is higher than 1. What is its height?
Show answer
\(\dfrac{4}{\pi} \approx 1.27\), reached at \(x = \dfrac{\pi}{2}\).
-
Set \(x = \dfrac{\pi}{2}\) in the series. Since \(f\left(\dfrac{\pi}{2}\right) = 1\), what famous result for \(\pi\) follows?
Show answer
\(\sin\left(\dfrac{(2k-1)\pi}{2}\right)\) alternates between \(1\) and \(-1\), so \(1 = \dfrac{4}{\pi}\left(1 - \dfrac{1}{3} + \dfrac{1}{5} - \dfrac{1}{7} + \cdots\right)\), which gives \(\dfrac{\pi}{4} = 1 - \dfrac{1}{3} + \dfrac{1}{5} - \cdots\) (the Leibniz series).