How Can Sine Waves Create a Square Wave? The Mathematics of Fourier Series

Mathematical Transforms and Their Applications

A sine wave is smooth and rounded. A square wave is flat across the top and bottom, with sudden jumps between them. Yet a square wave can be constructed by adding ordinary sine waves with carefully chosen frequencies and amplitudes. This is the central idea of Fourier series, used in electronics, music, heat flow, and vibration.

1. The puzzle: can smooth waves produce sudden jumps?

Consider the periodic square wave

f(x)=\begin{cases}1,&0<x<\pi,\\-1,&-\pi<x<0,\end{cases}\qquad f(x+2\pi)=f(x).

At the jump points, we may define f(k\pi)=0; this matches the value of its Fourier series there. The remarkable representation is

f(x)\sim\frac4\pi\left(\sin x+\frac{\sin3x}{3}+\frac{\sin5x}{5}+\cdots\right).

At every continuity point the series equals f(x); at each jump it converges to the midpoint of the one-sided limits, namely zero.

2. What is a Fourier series?

A sufficiently regular 2\pi-periodic function can be represented by

f(x)\sim\frac{a_0}{2}+\sum_{n=1}^{\infty}\bigl(a_n\cos nx+b_n\sin nx\bigr),

where the coefficients are obtained by integration:

a_0=\frac1\pi\int_{-\pi}^{\pi}f(x)\,dx,\qquad a_n=\frac1\pi\int_{-\pi}^{\pi}f(x)\cos(nx)\,dx,
b_n=\frac1\pi\int_{-\pi}^{\pi}f(x)\sin(nx)\,dx.

Why does this work? Sines and cosines of different integer frequencies are orthogonal. For example, for positive integers m,n,

\int_{-\pi}^{\pi}\sin(mx)\sin(nx)\,dx=\begin{cases}0,&m\ne n,\\\pi,&m=n.\end{cases}

Integration therefore isolates one frequency at a time, much as a dot product isolates a component along a perpendicular direction.

3. Deriving the square-wave formula

The square wave is odd: f(-x)=-f(x). Its constant and cosine coefficients vanish, so only sine terms remain. Since f(x)=1 on (0,\pi),

b_n=\frac2\pi\int_0^\pi\sin(nx)\,dx=\frac{2}{n\pi}\bigl(1-(-1)^n\bigr).

For even n this is zero; for odd n it is 4/(n\pi). Hence

f(x)\sim\frac4\pi\sum_{k=0}^{\infty}\frac{\sin((2k+1)x)}{2k+1}.

Only odd harmonics appear. Their frequencies are 1,3,5,7,\ldots, and their amplitudes decrease like 1/n.

4. Watch the square wave emerge

The approximation using the first N nonzero harmonics is

S_N(x)=\frac4\pi\sum_{k=0}^{N-1}\frac{\sin((2k+1)x)}{2k+1}.
10−1−π−π/20π/2π
Fourier approximation Ideal square wave. Move the slider to add harmonics.

With more harmonics, the flat portions become flatter and the transitions sharper. But near each jump, a small oscillatory overshoot persists.

5. The Gibbs phenomenon

Even when many sine waves are added, the Fourier approximation rises above 1 near a jump from -1 to 1. The limiting overshoot is about 8.949% of the jump height:

0.08949\times2\approx0.17898.

Thus the peak approaches approximately 1.17898, not 1. The region of oscillation becomes narrower as more terms are added, but its limiting height does not vanish. This is the Gibbs phenomenon. The Fourier series converges pointwise, but not uniformly across a discontinuity.

6. An unexpected infinite series for π

At x=\pi/2, the square wave equals 1. Substituting this value into its Fourier series gives

1=\frac4\pi\left(1-\frac13+\frac15-\frac17+\cdots\right),

so we recover the Leibniz series:

\frac\pi4=1-\frac13+\frac15-\frac17+\cdots.

We can obtain a second identity from Parseval’s identity. Since f(x)^2=1 almost everywhere,

\frac1\pi\int_{-\pi}^{\pi}f(x)^2\,dx=2=\sum_{n=1}^{\infty}b_n^2.

Using the coefficients already found,

2=\frac{16}{\pi^2}\left(1+\frac1{3^2}+\frac1{5^2}+\cdots\right),

and therefore

1+\frac1{3^2}+\frac1{5^2}+\cdots=\frac{\pi^2}{8}.

7. A second example: the triangle wave

Consider the odd, 2\pi-periodic triangle wave

g(x)=\begin{cases}-\dfrac{2}{\pi}(x+\pi),&-\pi\le x<-\pi/2,\\\dfrac{2x}{\pi},&-\pi/2\le x\le\pi/2,\\\dfrac{2}{\pi}(\pi-x),&\pi/2<x\le\pi.\end{cases}

Its Fourier series is

g(x)=\frac8{\pi^2}\left(\sin x-\frac{\sin3x}{3^2}+\frac{\sin5x}{5^2}-\cdots\right).

For the square wave, coefficients decay like 1/n; for the continuous triangle wave, they decay like 1/n^2. The smoother the function, the faster its Fourier coefficients generally decrease. Sharp changes require more high-frequency content.

8. Why does this matter?

Electronic signals

Digital circuits use signals switching between voltage levels. A real circuit has limited bandwidth, so it cannot preserve infinitely many harmonics; sharp transitions become rounded.

Musical instruments

Most musical notes contain a fundamental frequency and higher harmonics. Their relative strengths contribute to an instrument’s characteristic timbre. Square and triangle waves sound different because their harmonic amplitudes differ.

Heat and vibrations

A complicated temperature distribution or vibrating-string shape can be decomposed into simple modes. Each mode evolves according to a simpler equation, and the results are added to reconstruct the solution.

9. Fourier series versus Fourier transforms

Fourier series describe periodic signals through discrete harmonics. Fourier transforms extend frequency decomposition to more general, nonperiodic signals, where frequencies vary continuously. Both approaches reveal hidden structure by expressing a complicated signal in simpler frequency components.

10. Final takeaway

A square wave looks nothing like a sine wave, yet

f(x)\sim\frac4\pi\left(\sin x+\frac{\sin3x}{3}+\frac{\sin5x}{5}+\cdots\right).

This formula connects symmetry, orthogonality, convergence, infinite series, sound, and signal processing. A complicated shape can become simple when viewed in the right mathematical representation.

Further reading

  • Joseph Fourier, The Analytical Theory of Heat (1822).
  • Gilbert Strang, Introduction to Applied Mathematics, Wellesley-Cambridge Press.
  • Elias M. Stein and Rami Shakarchi, Fourier Analysis: An Introduction, Princeton University Press.

A Sum of Cosines in Closed Form

Before summing infinitely many waves, it helps to see what a finite sum of cosines looks like. Euler's formula reveals a geometric series hiding inside it.

Continue exploring: A Sum of Cosines Is a Geometric Series—Could You Believe It?


From Fourier Series to the Fourier Transform

A Fourier series breaks a periodic signal, like a square wave, into sine waves with whole-number frequencies. But most real sounds do not repeat exactly. How do we find the frequencies hidden inside them?

The answer is the Fourier transform, which extends the same idea to signals that need not be periodic.

Continue exploring: The Fourier Transform — How Mathematics Decomposes Sound into Frequencies

Leave a Reply

Your email address will not be published. Required fields are marked *