Expansions of Simple Functions

Learning Fourier series through concrete examples

Introduction (High School Level)

Introduction

Let us apply the Fourier series formulas to concrete functions and work through several important examples. These examples not only deepen our understanding of Fourier analysis but are also important in applications.

Square Wave

Consider the square wave of period $2\pi$:

$$f(x) = \begin{cases} 1 & (0 < x < \pi) \\ -1 & (-\pi < x < 0) \end{cases}$$

x f(x) π
Figure 1: The square wave (period $2\pi$). Dashed lines mark the jumps at the discontinuities.

Computing the Fourier Coefficients

This function is odd, so $a_n = 0$. Computing $b_n$:

$$b_n = \dfrac{1}{\pi}\displaystyle\int_{-\pi}^{\pi}f(x)\sin nx\,dx = \dfrac{2}{\pi}\displaystyle\int_0^{\pi}\sin nx\,dx$$

$$= \dfrac{2}{\pi}\left[-\dfrac{\cos nx}{n}\right]_0^{\pi} = \dfrac{2}{n\pi}(1 - \cos n\pi) = \dfrac{2}{n\pi}(1 - (-1)^n)$$

When $n$ is even, $b_n = 0$; when $n$ is odd, $b_n = \dfrac{4}{n\pi}$.

Result

$$f(x) = \dfrac{4}{\pi}\left(\sin x + \dfrac{1}{3}\sin 3x + \dfrac{1}{5}\sin 5x + \dfrac{1}{7}\sin 7x + \cdots\right)$$

It consists only of odd-harmonic sine waves, reflecting the symmetry of the square wave.

n |bₙ| 1 3 5 7 9
Figure 2: Spectrum of the square wave. Only odd harmonics, decaying as $1/n$.

Triangle Wave

Consider the triangle wave of period $2\pi$:

$$f(x) = |x| \quad (-\pi \leq x \leq \pi)$$

x f(x) π
Figure 3: The triangle wave $|x|$ (period $2\pi$).

Computing the Fourier Coefficients

This function is even, so $b_n = 0$.

$$a_0 = \dfrac{1}{\pi}\displaystyle\int_{-\pi}^{\pi}|x|\,dx = \dfrac{2}{\pi}\displaystyle\int_0^{\pi}x\,dx = \pi$$

$$a_n = \dfrac{2}{\pi}\displaystyle\int_0^{\pi}x\cos nx\,dx = \dfrac{2}{n^2\pi}(\cos n\pi - 1) = \dfrac{2}{n^2\pi}((-1)^n - 1)$$

When $n$ is even, $a_n = 0$; when $n$ is odd, $a_n = -\dfrac{4}{n^2\pi}$.

Result

$$|x| = \dfrac{\pi}{2} - \dfrac{4}{\pi}\left(\cos x + \dfrac{1}{9}\cos 3x + \dfrac{1}{25}\cos 5x + \cdots\right)$$

Since the coefficients decay as $1/n^2$, convergence is faster than for the square wave.

n |aₙ| 0 1 3 5 7
Figure 4: Spectrum of the triangle wave. Constant term ($n=0$) plus odd harmonics, decaying as $1/n^2$.

Sawtooth Wave

The sawtooth wave of period $2\pi$ (the example from the previous chapter):

$$f(x) = x \quad (-\pi < x < \pi)$$

x f(x) π
Figure 5: The sawtooth wave (period $2\pi$). Dashed lines mark the jumps at the discontinuities.

Result (recap)

$$x = 2\left(\sin x - \dfrac{1}{2}\sin 2x + \dfrac{1}{3}\sin 3x - \dfrac{1}{4}\sin 4x + \cdots\right)$$

$$= 2\displaystyle\sum_{n=1}^{\infty}\dfrac{(-1)^{n+1}}{n}\sin nx$$

n |bₙ| 1 2 3 4 5
Figure 6: Spectrum of the sawtooth wave. All harmonics, decaying as $1/n$.

Parabola

The parabola of period $2\pi$:

$$f(x) = x^2 \quad (-\pi \leq x \leq \pi)$$

x f(x) π
Figure 7: The parabola $x^2$ (period $2\pi$).

Computing the Fourier Coefficients

Since it is even, $b_n = 0$.

$$a_0 = \dfrac{1}{\pi}\displaystyle\int_{-\pi}^{\pi}x^2\,dx = \dfrac{2\pi^2}{3}$$

$$a_n = \dfrac{2}{\pi}\displaystyle\int_0^{\pi}x^2\cos nx\,dx = \dfrac{4(-1)^n}{n^2}$$

Result

$$x^2 = \dfrac{\pi^2}{3} + 4\left(-\cos x + \dfrac{1}{4}\cos 2x - \dfrac{1}{9}\cos 3x + \cdots\right)$$

n |aₙ| 0 1 2 3 4 5
Figure 8: Spectrum of the parabola. Constant term ($n=0$) plus all harmonics, decaying as $1/n^2$.

Application to computing $\pi^2$

Substituting $x = \pi$:

$$\pi^2 = \dfrac{\pi^2}{3} + 4\left(1 + \dfrac{1}{4} + \dfrac{1}{9} + \cdots\right)$$

Rearranging:

$$\displaystyle\sum_{n=1}^{\infty}\dfrac{1}{n^2} = \dfrac{\pi^2}{6}$$

we obtain the famous result known as Euler's Basel problem.

Comparison of Convergence Speed

Function Coefficient decay Convergence speed
Square wave $1/n$ Slow
Sawtooth wave $1/n$ Slow
Triangle wave $1/n^2$ Fast
Parabola $1/n^2$ Fast

In general, the smoother the function, the faster its Fourier coefficients decay and the faster the series converges. Functions with discontinuities (the square and sawtooth waves) converge slowly.

π x Square wave, 5 terms (1/n) Triangle wave, 5 terms (1/n²)
Figure 9: Comparison using the same 5 terms. The triangle wave ($1/n^2$) nearly coincides with the ideal shape, while the square wave ($1/n$) oscillates near the discontinuities (the Gibbs phenomenon). The faint dashed lines are the ideal waveforms.

Summary

  • A square wave is a sum of odd-harmonic sine waves
  • A triangle wave is a sum of odd-harmonic cosine waves
  • A sawtooth wave is a sum of sine waves of all orders
  • The smoother the function, the faster its Fourier coefficients decay
  • Series identities such as $\pi^2/6$ can be derived from Fourier series

Frequently Asked Questions

Q1: Can you give examples of Fourier expansions of simple functions?

A: The square wave $f(x) = \mathrm{sgn}(\sin x)$ (for $-\pi < x < \pi$) is $f(x) = \dfrac{4}{\pi}\displaystyle\sum_{n=1,3,5,\dots}^{\infty} \dfrac{1}{n}\sin nx$. The Fourier series of $x$ (for $-\pi < x < \pi$) is $2\displaystyle\sum_{n=1}^{\infty} \dfrac{(-1)^{n+1}}{n}\sin nx$, and Parseval's identity then gives $\displaystyle\sum_{n=1}^{\infty} \dfrac{1}{n^2} = \dfrac{\pi^2}{6}$.

Q2: Why does the triangle wave converge faster than the square wave?

A: Because the smoother the function, the faster its Fourier coefficients decay. The square and sawtooth waves have discontinuities and their coefficients decay as $1/n$, whereas the triangle wave and parabola are continuous and decay as $1/n^2$. Faster decay means fewer terms are needed to approximate the function, so the triangle wave converges faster.

Q3: What form do the Fourier expansions of even and odd functions take?

A: An even function ($f(-x) = f(x)$) becomes a cosine-only Fourier cosine series $\dfrac{a_0}{2} + \displaystyle\sum_{n=1}^{\infty} a_n \cos nx$ (with $b_n = 0$). An odd function ($f(-x) = -f(x)$) becomes a sine-only Fourier sine series $\displaystyle\sum_{n=1}^{\infty} b_n \sin nx$ (with $a_n = 0$).