Square Wave Reconstruction with the Fourier Theorem
January 31, 2016
AIS1209
Description of the Application
- Use a Fourier series to approximate a square wave of amplitude equal to 1 and period T

- The user can change the number of terms used in the computation of the Fourier series, the period of the wave and the number of cycles (periods) displayed
- The application computes the approximation of the square wave using its Fourier series and the selected parameters, and plots the reconstruction of the square wave and its frequency spectrum
- The user has the option to download a CSV file containing the data
- Potential applications include numerical simulations of systems (ex., electrical circuits) where a step input is needed
Some Theory
- According to Fourier theory, almost any periodic function can be represented as an infinite sum of sinusoidal components (sine or cosine functios)
- If the function is not periodic, it can be made periodic by repeating copies of the function
- The sum is called the Fourier series of function f and it has the general form
\[ f(x) = \frac{1}{2} a_0 + \sum_{i=1}^\infty a_n cos(nx) + \sum_{i=1}^\infty b_n sin(nx)\]
- Fourier coefficients \(a_n\) and \(b_n\) depend on function f
- The Fourier series of a square wave of amplitude 1 and period T is
\[f(x) = \frac{4}{\pi} \sum_{n=1,3,5, \ldots}^\infty \frac{1}{n} sin\left(\frac{n\pi x}{T}\right) =
\frac{4}{\pi} \sum_{n = 0}^\infty \frac{1}{2n+1} sin\left(\frac{(2n+1)\pi x}{T}\right) \]
Example 1: Approximation with Two Terms (N = 2)
- Shown is the case with period T = 1 and one cycle (C = 1)
- Notice the approximation/reconstruction could use some improvement (left plot)
- Also notice the two peaks on the frequency spectrum (right plot) corresponding to the two terms used in the reconstruction

Example 2: Approximation with N = 90 Terms
- Shown is the case with period T = 2 and three cycles (C = 3)
- Notice the far better approximation/reconstruction of the square wave (left plot)
- The Gibbs phenomenon is present (the oscillations at "corners"), and is due to the numerical reconstruction
- The frequency spectrum plot (right) shows that the height of the frequency components decreases, which is consistent with the fact that the coefficients of the sinusoidal functions decrease with the number of terms used in the Fourier sum (see last equation on slide 3)
