This demonstration shows how a periodic square wave can be built by summing sine and cosine waves with specific frequencies and amplitudes (Fourier series). Each term in the Fourier series is shown in the upper plot. The sum of the terms and the actual square wave are shown in the bottom plot. Change the number of terms in the Fourier series using the slider bar. As the number of terms increases, the summation approaches the actual square wave.
A periodic square wave of amplitude \(A\) and period \(T_p\) can be represented by the Fourier series:
\[ f(t) \;=\; \frac{4A}{\pi} \sum_{n=1}^{N} \frac{\sin\!\big(2\pi\,(2n-1)\,f_0\,t\big)}{2n-1} \]where:
\(f(t)\) = sum of the Fourier series terms (amplitude, a.u.)
\(A\) = amplitude of the square wave (\(A = 1\) a.u.)
\(f_0\) = fundamental frequency (\(f_0 = 1/T_p = 1\) Hz)
\(T_p\) = period of the square wave (\(T_p = 1\) s)
\(n\) = term index
\(N\) = number of terms in the summation (set by the slider)
\(t\) = time (s)
Each individual term in the summation,
\[ F_n(t) \;=\; \frac{4A}{\pi}\,\frac{\sin\!\big(2\pi\,(2n-1)\,f_0\,t\big)}{2n-1}, \]is a sine wave with frequency \((2n-1)f_0\) (the odd harmonics of the fundamental frequency) and amplitude \(\dfrac{4A}{\pi(2n-1)}\); these terms are plotted in the upper plot. Only odd harmonics appear because the square wave is an odd function with half-wave symmetry, so the cosine coefficients and the even sine coefficients are zero. As \(N \to \infty\), the sum converges to the square wave everywhere except at the discontinuities, where the overshoot that remains near the jumps is known as the Gibbs phenomenon.
This simulation was created in the Department of Chemical and Biological Engineering at University of Colorado Boulder for LearnChemE.com by John L. Falconer using Claude AI. It is a JavaScript/HTML5 implementation of a MATLAB simulation by Keith Regner. It was prepared with financial support from the National Science Foundation (DUE 2336987 and 2336988). Address any questions or comments to LearnChemE@gmail.com.