Introduction to Fourier Series
Representing periodic functions as sums of trigonometric functions
Introduction (High School Level)
Introduction
As we saw in the previous chapter, superposing sine waves lets us build complex waveforms. But can we go the other way and express an arbitrary periodic function as a sum of sine waves? The answer to that question is the Fourier series.
The Idea of Fourier Series
We represent a function $f(x)$ of period $2\pi$ as an infinite sum of trigonometric functions:
$$f(x) = \dfrac{a_0}{2} + \displaystyle\sum_{n=1}^{\infty}\left(a_n\cos nx + b_n\sin nx\right)$$
The meaning of each term on the right-hand side:
- $\dfrac{a_0}{2}$: the constant term (the "average value" of the function)
- $a_n\cos nx$: the cosine component at frequency $n$
- $b_n\sin nx$: the sine component at frequency $n$
The coefficients $a_n$ and $b_n$ are called the Fourier coefficients. By choosing them appropriately, a surprisingly large class of periodic functions can be written in this form.
Computing the Fourier Coefficients
The Fourier coefficients are computed with the following formulas:
$$a_0 = \dfrac{1}{\pi}\displaystyle\int_{-\pi}^{\pi}f(x)\,dx$$
$$a_n = \dfrac{1}{\pi}\displaystyle\int_{-\pi}^{\pi}f(x)\cos nx\,dx \quad (n \geq 1)$$
$$b_n = \dfrac{1}{\pi}\displaystyle\int_{-\pi}^{\pi}f(x)\sin nx\,dx \quad (n \geq 1)$$
Why these formulas hold
The key is the orthogonality of the trigonometric functions (which we studied in "A Review of Trigonometric Functions"). For example, to find $a_n$, multiply both sides of the Fourier series by $\cos nx$ and integrate from $-\pi$ to $\pi$. By orthogonality, the integral of the product of $\cos mx$ and $\cos nx$ (with $m \neq n$) is $0$, so only the $a_n$ term survives.
The Meaning of the Fourier Coefficients
The Fourier coefficients describe the "strength" of each frequency component contained in the function.
- $|a_n|$ or $|b_n|$ large → the component at frequency $n$ is strong
- $|a_n|$ or $|b_n|$ small → the component at frequency $n$ is weak
This is analogous to the frequency analysis of sound. When you hear a chord, quantifying which notes (frequencies) are present and how strongly is exactly the same idea.
Spectrum
Plotting the magnitude $\sqrt{a_n^2 + b_n^2}$ of the coefficients against each frequency $n$ gives what is called the spectrum. It lets us visualize the "frequency content" of a function.
A Simple Example
Example: $f(x) = x$ (for $-\pi < x < \pi$)
Repeating $f(x) = x$ with period $2\pi$ produces a waveform that climbs along a straight line and then drops sharply at regular intervals. This is called a sawtooth wave, and, true to its name, it has the jagged shape of the teeth of a saw.
This function is odd, so $a_n = 0$ for every $n$. Only $b_n$ remains, so let us compute it straight from the definition.
$$b_n = \dfrac{1}{\pi}\displaystyle\int_{-\pi}^{\pi}x\sin nx\,dx$$
The integrand is a product of "$x$" and "$\sin nx$", so we use integration by parts. The formula taught in high school takes the form:
$$\int f(x)g'(x)\,dx = f(x)g(x) - \int f'(x)g(x)\,dx$$
This formula integrates one factor $g'$ into $g$, and then subtracts an integral built from $g$ and the derivative $f'$ of the other factor. To use it well, assign $f$ and $g'$ so that both of the following hold at once:
- Choose for $f$ the factor that becomes simpler when differentiated (so the remaining integral $\int f'(x)g(x)\,dx$ becomes easier)
- Choose for $g'$ the factor that is easy to integrate (so that $g$ can actually be found)
Here, differentiating $x$ gives $1$ and makes it vanish, and $\sin nx$ can be integrated (it becomes $-\dfrac{1}{n}\cos nx$). Both conditions are satisfied, so we choose $f(x) = x$ and $g'(x) = \sin nx$.
Then $f'(x) = 1$ and $g(x) = \displaystyle\int \sin nx\,dx = -\dfrac{1}{n}\cos nx$. Substituting into the formula:
$$\int x\sin nx\,dx = x\cdot\left(-\dfrac{1}{n}\cos nx\right) - \int 1\cdot\left(-\dfrac{1}{n}\cos nx\right)dx$$
Tidying up the right-hand side:
$$\int x\sin nx\,dx = -\dfrac{x}{n}\cos nx + \dfrac{1}{n}\int \cos nx\,dx$$
The remaining integral is $\displaystyle\int\cos nx\,dx = \dfrac{1}{n}\sin nx$, so the antiderivative is:
$$\int x\sin nx\,dx = -\dfrac{x}{n}\cos nx + \dfrac{1}{n^2}\sin nx$$
Now substitute $x=\pi$ and $x=-\pi$ and subtract (the definite integral). The key point is that, since $n$ is an integer, $\sin n\pi = 0$, so the second term (the one with $\sin$) vanishes at both endpoints.
- At $x=\pi$: $-\dfrac{\pi}{n}\cos n\pi + 0 = -\dfrac{\pi}{n}\cos n\pi$
- At $x=-\pi$: $+\dfrac{\pi}{n}\cos n\pi + 0 = +\dfrac{\pi}{n}\cos n\pi$ (since $\cos$ is even, $\cos(-n\pi)=\cos n\pi$)
Subtracting the lower-endpoint value from the upper-endpoint value:
$$\left[-\dfrac{x}{n}\cos nx + \dfrac{1}{n^2}\sin nx\right]_{-\pi}^{\pi} = -\dfrac{\pi}{n}\cos n\pi - \dfrac{\pi}{n}\cos n\pi = -\dfrac{2\pi}{n}\cos n\pi$$
Here $\cos n\pi$ equals $1$ when $n$ is even and $-1$ when $n$ is odd, which we can write compactly as $\cos n\pi = (-1)^n$. Substituting this and multiplying by the leading $\dfrac{1}{\pi}$:
$$b_n = \dfrac{1}{\pi}\cdot\left(-\dfrac{2\pi}{n}(-1)^n\right) = -\dfrac{2(-1)^n}{n} = 2(-1)^{n+1}\dfrac{1}{n}$$
In the last step we rewrote the sign as $-(-1)^n = (-1)^{n+1}$. This gives $b_n$. Therefore:
$$f(x) = 2\left(\sin x - \dfrac{1}{2}\sin 2x + \dfrac{1}{3}\sin 3x - \dfrac{1}{4}\sin 4x + \cdots\right) \tag{1}$$
This shows that a sawtooth wave can be represented using sine waves alone. The magnitude of the coefficient $b_n = 2(-1)^{n+1}\dfrac{1}{n}$ is $|b_n| = \dfrac{2}{n}$, which decreases gently as $n$ grows (i.e. for higher frequencies). Drawn as a spectrum, it looks like this.
Optional (you may skip this on a first reading): Equation (1) does not strictly hold at discontinuities. There the series converges to the average of the right-hand and left-hand limits (in this example $0$, e.g. at $x = \pm\pi$). This convergence behaviour at discontinuities and the Gibbs phenomenon are discussed in "Intuitive Understanding of Convergence".
Summary
- A Fourier series represents a periodic function as an infinite sum of trigonometric functions
- The Fourier coefficients are computed with integral formulas
- The orthogonality of trigonometric functions is used to derive the formulas
- The Fourier coefficients describe the strength of each frequency component
Frequently Asked Questions
Q1: What is a Fourier series?
A: It is the expansion of a periodic function $f(x)$ of period $2\pi$ into the form $f(x) = \dfrac{a_0}{2} + \displaystyle\sum_{n=1}^{\infty}(a_n \cos nx + b_n \sin nx)$. The coefficients are given by $a_n = \dfrac{1}{\pi}\int_{-\pi}^{\pi} f(x)\cos nx\,dx$ and $b_n = \dfrac{1}{\pi}\int_{-\pi}^{\pi} f(x)\sin nx\,dx$.
Q2: How are the Fourier coefficients computed?
A: They follow from the orthogonality of the trigonometric system. Multiplying both sides of the Fourier series by $\cos nx$ and integrating from $-\pi$ to $\pi$, orthogonality makes every term except the one with index $n$ integrate to $0$, leaving only the $a_n$ term. This yields $a_n = \dfrac{1}{\pi}\int_{-\pi}^{\pi} f(x)\cos nx\,dx$. One then simply evaluates the integral.
Q3: Why is the constant term written as $\dfrac{a_0}{2}$, dividing by $2$?
A: Writing it this way makes the coefficient formula $a_n = \dfrac{1}{\pi}\int_{-\pi}^{\pi}f(x)\cos nx\,dx$ produce the constant term directly when $n=0$. Since $\cos 0 = 1$, we get $a_0 = \dfrac{1}{\pi}\int_{-\pi}^{\pi}f(x)\,dx$, and dividing by $2$ gives $\dfrac{a_0}{2} = \dfrac{1}{2\pi}\int_{-\pi}^{\pi}f(x)\,dx$, which is exactly the average value of $f(x)$ over one period. In other words, the constant term represents the "average height" of the function, and dividing by $2$ is a convention that keeps the formulas uniform.