Fourier Series

The harmonic analysis of continuous waveforms

Written by Guy Fernando

Created Jan 2020 - Last modified Nov 2024


Introduction

Jean-Baptiste Joseph Fourier (c. 1768 - c. 1830) was a French mathematician and physicist noted for his investigations into heat flow, and scientific advisor to Napoleon. He is also recognized for discovering that any periodic motion can be described as a infinite series of trigonometric functions, now commonly known as the Fourier series. He is lesser known for the discovery of the greenhouse effect, having determined that the temperature on Earth would in fact be lower if not for the insulating properties of the atmosphere. Believing that heat also held healing properties, he met his fate by tripping down the stairs in his house possibly while being wrapped up in a blanket.

Waveform Graph

Fourier Series

In 1807, Fourier submitted his paper to the Institut de France, claiming that any periodic signal could be represented by a series. The principle idea of a Fourier series expansion is to represent a function f(x) of period 2π as an infinite series of sinusoidal and cosinusoidal functions, given by the following equations.


\( \begin{aligned} f(x) = \frac{a_{0}}{2} + a_{1}.cos \; x + a_{2}.cos \; 2x + a_{3}.cos \; 3x \; + ... + \; b_{1}.sin \; x + b_{2}.sin \; 2x + b_{3}.sin \; 3x ... \end{aligned} \)

\( \begin{aligned} f(x) = \frac{a_{0}}{2} + \sum_{n=1}^ \infty (a_{n}.cos(nx) + b_{n}.sin(nx)) \;\;\;\;\;\;(1) \end{aligned} \)

Where integrals are used to find the Fourier series coefficients, given by the following equations.

\( \begin{aligned}\;\;\;\;\; a_{0} = \frac{1}{\pi } \int_{0}^{2\pi} f(x) \; dx \;\;\;\;\;\;(2) \end{aligned} \)

\( \begin{aligned}\;\;\;\;\; a_{n} = \frac{1}{\pi } \int_{0}^{2\pi} f(x).cos(nx) \; dx \;\;\;\;\;\;(3) \end{aligned} \)

\( \begin{aligned}\;\;\;\;\; b_{n} = \frac{1}{\pi } \int_{0}^{2\pi} f(x).sin(nx) \; dx \;\;\;\;\;\;(4) \end{aligned} \)

Note, all waveforms presented in this article are symmetric about the x-axis, and so will have no DC component.
\( \begin{aligned} \therefore a_{0} = 0 \end{aligned} \)

Also note, all waveforms are asymmetric about the y-axis (odd functions), and so will have no cosine terms.
\( \begin{aligned} \therefore a_{n} = 0 \end{aligned} \)

The Sine Wave

A sine wave or sinusoid is a mathematical curve that describes a smooth periodic oscillation.


By definition a sine wave is the first and the only term in a Fourier series. It having only the first harmonic that being the fundamental tone.


\( \begin{aligned} b_{1} = 1 \end{aligned} \)

\( \begin{aligned} f(x) = A.sin(x) \end{aligned} \)

The Square Wave

A square wave is a non-sinusoidal periodic waveform in which the amplitude alternates at a steady frequency between fixed minimum and maximum values, with the same duration at minimum and maximum.


A single period of the square wave between 0 and 2π can be broken down into two discrete intervals, and the integral of each interval taken.


Using equation (4).

\( \begin{aligned} b_{n} = \frac{1}{\pi} \int_0^\pi A.sin(nx) \; dx \; + \; \frac{1}{ \pi } \int_\pi^{2\pi} -A.sin(nx) \; dx \end{aligned} \)

\( \begin{aligned} \;\;\; = \frac{A}{\pi} \big\{ \left[\frac{-cos(nx)}{n}\right]_0^\pi - \left[\frac{-cos(nx)}{n}\right]_\pi^{2\pi}\big\} \end{aligned} \)

\( \begin{aligned} \;\;\; = \frac{A}{n\pi} \big\{ \left[-cos(n\pi)-(cos(0))\right] - \left[-cos(2n\pi)-(-cos(n\pi))\right] \big\} \end{aligned} \)

\( \begin{aligned} \;\;\; = \frac{A}{n\pi} \big\{ \left[1-cos(n\pi) \right] - \left[cos(n\pi)-1 \right] \big\} \end{aligned} \)

\( \begin{aligned} b_{n} = \frac{4A}{\pi} \left[\frac{1-cos(n\pi)}{2n}\right] \end{aligned} \)

Substituting values of bn back into equation (1).

\( \begin{aligned} f(x) = \frac{4A}{ \pi } \left[ sin(x) + \frac{1}{3}sin(3x) + \frac{1}{5}sin(5x) + \frac{1}{7}sin(7x) \; ... \right] \end{aligned} \)

The equation shows that a square wave contains only odd harmonics, with subsequent overtones decreasing in amplitude.



The Sawtooth Wave

The sawtooth wave is a non-sinusoidal waveform. It is so named based on its resemblance to the teeth of a plain-toothed saw with a zero rake angle. The convention is that a sawtooth wave ramps upward and then sharply drops.


A single period of the sawtooth wave between 0 and 2π can be broken down into two discrete intervals, and the integral of each interval taken.


Using equation (4).

\( \begin{aligned} b_{n} = \frac{1}{\pi} \int_0^\pi \big(\frac{Ax}{\pi}\big) .sin(nx) \; dx \; + \; \frac{1}{ \pi } \int_\pi^{2\pi} \big(\frac{Ax}{\pi}-2A\big) .sin(nx) \; dx \end{aligned} \)

Using integration by parts.

\( \begin{aligned} \;\;\; = \frac{A}{\pi} \big\{ \left[\frac{sin(nx)-nx.cos(nx)}{ {\pi}n^{2} }\right]_0^\pi + \left[\frac{sin(nx)-n(x-2\pi).cos(nx)}{{\pi}n^{2}}\right]_\pi^{2\pi}\big\} \end{aligned} \)

After simplifying, for values of n > 0.

\( \begin{aligned} b_{n} = \frac{2A}{\pi} \left[\frac{-(-1)^{n} }{n}\right] \end{aligned} \)

Substituting values of bn back into equation (1).

\( \begin{aligned} f(x) = \frac{2A}{ \pi } \left[ sin(x) - \frac{1}{2}sin(2x) + \frac{1}{3}sin(3x) - \frac{1}{4}sin(4x) \; ... \right] \end{aligned} \)

The equation shows that a sawtooth wave contains all harmonics, with subsequent overtones decreasing in amplitude.



The Triangle Wave

A triangle wave is a non-sinusoidal waveform named for its triangular shape. It is a periodic, piecewise linear, continuous real function.


A single period of the triangle wave between 0 and 2π can be broken down into three discrete intervals, and the integral of each interval taken.


Using equation (4).

\( \begin{aligned} b_{n} = \frac{1}{\pi}\int_0^{\frac{\pi}{2}}\big(\frac{2Ax}{\pi}\big).sin(nx)\;dx \; + \; \frac{1}{\pi}\int_{\frac{\pi}{2}}^{\frac{3\pi}{2}}\big(\frac{-2Ax}{\pi}+2A\big).sin(nx)\;dx \; + \; \frac{1}{\pi}\int_{\frac{3\pi}{2}}^{2\pi}\big(\frac{2Ax}{\pi}-4A\big).sin(nx)\;dx \end{aligned} \)

Using integration by parts.

\( \begin{aligned} \;\;\; = \frac{A}{\pi}\big\{\left[\frac{2(sin(nx)-nx.cos(nx))}{ {\pi}n^{2} }\right]_0^{\frac{\pi}{2}} + \left[\frac{-2(sin(nx)+({\pi}x-nx).cos(nx))}{{\pi}n^{2}}\right]_{ \frac{\pi}{2} }^{\frac{3\pi}{2}} + \left[\frac{2(sin(nx)+(2{\pi}n-nx).cos(nx))}{{\pi}n^{2}}\right]_{\frac{3\pi}{2}}^{2\pi}\big\} \end{aligned} \)

After simplifying, for values of n > 0.

\( \begin{aligned} b_{n} = \frac{8A}{\pi^2}\left[\frac{(-(-1)^{n}(1-cos(n\pi)))}{2n^2}\right] \end{aligned} \)

Substituting values of bn back into equation (1).

\( \begin{aligned} f(x) = \frac{8A}{\pi^{2}}\left[ sin(x) - \frac{1}{9}sin(3x) + \frac{1}{25}sin(5x) - \frac{1}{49}sin(7x) \; ... \right] \end{aligned} \)

The equation shows that a triangle wave contains only odd harmonics, with subsequent overtones decreasing in amplitude.



Testing the Theory

Now that we have calculated the coefficients of each Fourier series term, we can plot the series using javascript to see how close it resembles the ideal waveform it represents. Recall that to generate square, sawtooth or triangle waveforms, an infinite number of terms is required, however below, only the first four terms are plotted.





Notice that the plotted waveform resembles the ideal waveform, but is far from perfect. You can add additional terms by typing them into the "series" textbox above. This will illustrate that when more terms are included, the closer the waveform approximation approaches the ideal. Change the "waveform" dropdown list above to show different waveform approximations.

Conclusion

The sine, square, sawtooth and triangle waveforms produced by common audio signal generators is described here, however the Fourier series for any periodic waveform may be calculated using this method. See this example of an online Audio Signal Generator here on i4cy.com.

A signal synthesised by a signal generator at its upper frequency limit is often imperfect, and appears similar to a Fourier series missing its higher harmonic terms. This in reality is mainly due to the limited frequency response of analogue electronic circuitry, and in the case of digital electronic synthesis, the digital to analogue converter's Nyquist limit.

Widely available computing tools make it far easier to learn about the Fourier series compared to when I was taught the subject as a student. Even though relatively involved calculus is required, for example when solving expressions that require "integration by parts", free tools such WolframAlpha or Symbolab can be used to evaluate such steps without knowledge of advanced mathematics.