Fourier Series
A Fourier series writes a periodic function as a sum of sines and cosines. For a function with period 2L, f(x) = a₀/2 + Σ [aₙ cos(nπx/L) + bₙ sin(nπx/L)], and each coefficient comes from an integral of f times a cosine or sine. Fourier series can even match functions with jumps, such as a square wave.
Before this lesson: Boundary Value Problems, Integration by Parts and Even and Odd Functions
The idea behind Fourier series
A Taylor series builds a function out of powers of x, and it only works well near one point. A Fourier series builds a periodic function out of waves: a constant, plus cos x and sin x, plus cos 2x and sin 2x, and so on. Each wave is called a harmonic.
Because every wave repeats, the sum repeats too, so it can describe a whole periodic signal at once. A sound wave, a vibrating string or an alternating voltage can all be written this way. Only the coefficients change from one function to the next.
Fourier series formula
Suppose f has period 2L, so f(x + 2L) = f(x). Its Fourier series and Fourier coefficients are:
f(x) \sim \frac{a_0}{2} + \sum_{n=1}^{\infty}\left(a_n\cos\frac{n\pi x}{L} + b_n\sin\frac{n\pi x}{L}\right)a_n = \frac{1}{L}\int_{-L}^{L} f(x)\cos\frac{n\pi x}{L}\,dx \quad (n \ge 0),\qquad b_n = \frac{1}{L}\int_{-L}^{L} f(x)\sin\frac{n\pi x}{L}\,dx \quad (n \ge 1)The constant term a₀/2 is the average value of f over one period. When the period is 2π, L = π and the terms are simply cos nx and sin nx.
Why the coefficient formulas work
Over one period, the product of two different harmonics integrates to 0. This property is called orthogonality:
\int_{-L}^{L}\sin\frac{m\pi x}{L}\sin\frac{n\pi x}{L}\,dx = \begin{cases}0, & m \ne n\\ L, & m = n\end{cases},\qquad \int_{-L}^{L}\sin\frac{m\pi x}{L}\cos\frac{n\pi x}{L}\,dx = 0The cosines behave the same way. So when you multiply the whole series by sin(nπx/L) and integrate, every term drops out except bₙ times L. Dividing by L gives the formula for bₙ. These sines and cosines are the eigenfunctions from boundary value problems.
Shortcuts for even and odd functions
| If f is | Then | Coefficients to compute |
|---|---|---|
| even, f(−x) = f(x) | every bₙ = 0 (a cosine series) | a_n = \frac{2}{L}\int_0^L f(x)\cos\frac{n\pi x}{L}\,dx |
| odd, f(−x) = −f(x) | every aₙ = 0, including a₀ (a sine series) | b_n = \frac{2}{L}\int_0^L f(x)\sin\frac{n\pi x}{L}\,dx |
Where the series converges
If f and f′ are piecewise continuous, the Fourier series converges to f(x) wherever f is continuous. At a jump, it converges to the average of the two one-sided limits, [f(x⁻) + f(x⁺)]/2.
Fourier series examples
Example 1: Square wave
Find the Fourier series of the square wave with period 2π given by f(x) = −1 for −π < x < 0 and f(x) = 1 for 0 < x < π.
a_n = 0 \text{ for all } n \ge 0f is odd, so it is a sine series (even and odd functions).
b_n = \frac{2}{\pi}\int_0^{\pi} \sin nx\,dxUse the odd-function shortcut with L = π and f = 1 on (0, π).
\int_0^{\pi}\sin nx\,dx = \left[-\frac{\cos nx}{n}\right]_0^{\pi}Antiderivative of sin nx (u-substitution with u = nx).
= \frac{1 - \cos n\pi}{n} = \frac{1 - (-1)^n}{n}Evaluate; cos nπ = (−1)ⁿ.
b_n = \frac{2\left(1 - (-1)^n\right)}{n\pi}Multiply by 2/π.
b_n = \frac{4}{n\pi} \text{ (n odd)},\quad b_n = 0 \text{ (n even)}1 − (−1)ⁿ is 2 for odd n and 0 for even n.
Answer: f(x) ∼ (4/π)(sin x + sin 3x/3 + sin 5x/5 + ⋯). At the jump x = 0 every term is 0, so the series gives 0, the average of −1 and 1. The graph shows the sums getting closer to the square wave as terms are added.
Example 2: Sawtooth wave f(x) = x
Find the Fourier series of f(x) = x for −π < x < π, extended with period 2π.
a_n = 0
f(x) = x is odd.
b_n = \frac{2}{\pi}\int_0^{\pi} x\sin nx\,dxOdd-function shortcut with L = π.
\int_0^{\pi} x\sin nx\,dx = \left[-\frac{x\cos nx}{n}\right]_0^{\pi} + \frac{1}{n}\int_0^{\pi}\cos nx\,dxIntegration by parts with u = x and dv = sin nx dx.
= -\frac{\pi\cos n\pi}{n} + 0The cosine integral is [sin nx/n] from 0 to π, which is 0.
= \frac{\pi(-1)^{n+1}}{n}cos nπ = (−1)ⁿ, and −(−1)ⁿ = (−1)ⁿ⁺¹.
b_n = \frac{2(-1)^{n+1}}{n}Multiply by 2/π.
Answer: x ∼ 2(sin x − sin 2x/2 + sin 3x/3 − ⋯) for −π < x < π. At x = ±π the extended function jumps from π to −π, so the series gives 0 there.
Example 3: f(x) = x² with period 2
Find the Fourier series of f(x) = x² for −1 ≤ x ≤ 1, extended with period 2.
b_n = 0
x² is even, so use the cosine shortcut with L = 1.
a_0 = 2\int_0^1 x^2\,dx = \frac{2}{3}n = 0: cos 0 = 1. So a₀/2 = 1/3.
a_n = 2\int_0^1 x^2\cos n\pi x\,dx
Cosine shortcut for n ≥ 1.
\int_0^1 x^2\cos n\pi x\,dx = \left[\frac{x^2\sin n\pi x}{n\pi}\right]_0^1 - \frac{2}{n\pi}\int_0^1 x\sin n\pi x\,dxIntegrate by parts with u = x²; the bracket is 0 because sin nπ = 0.
\int_0^1 x\sin n\pi x\,dx = -\frac{\cos n\pi}{n\pi} = -\frac{(-1)^n}{n\pi}Integrate by parts again, as in Example 2.
\int_0^1 x^2\cos n\pi x\,dx = -\frac{2}{n\pi}\cdot\left(-\frac{(-1)^n}{n\pi}\right) = \frac{2(-1)^n}{n^2\pi^2}Substitute.
a_n = \frac{4(-1)^n}{n^2\pi^2}Multiply by 2.
Answer: x² ∼ 1/3 + (4/π²) Σ (−1)ⁿ cos(nπx)/n² = 1/3 − (4/π²)(cos πx − cos 2πx/4 + cos 3πx/9 − ⋯). The extended function has no jumps, so the series equals x² for every x in [−1, 1].
Example 4: Summing a series with a Fourier series
Use Example 3 at x = 1 to find the sum 1 + 1/4 + 1/9 + 1/16 + ⋯.
1 = \frac{1}{3} + \frac{4}{\pi^2}\sum_{n=1}^{\infty}\frac{(-1)^n\cos n\pi}{n^2}Substitute x = 1; the series equals f(1) = 1.
(-1)^n\cos n\pi = (-1)^n(-1)^n = 1
Simplify each term.
1 = \frac{1}{3} + \frac{4}{\pi^2}\sum_{n=1}^{\infty}\frac{1}{n^2}Substitute.
\frac{2}{3} = \frac{4}{\pi^2}\sum_{n=1}^{\infty}\frac{1}{n^2}Subtract 1/3 from both sides.
\sum_{n=1}^{\infty}\frac{1}{n^2} = \frac{2}{3}\cdot\frac{\pi^2}{4} = \frac{\pi^2}{6}Multiply both sides by π²/4.
Answer: 1 + 1/4 + 1/9 + ⋯ = π²/6 ≈ 1.6449. This is the famous Basel problem. The p-series test only says this series converges; the Fourier series gives its exact value.
Example 5: Square wave voltage (word problem)
A signal generator puts out 5 volts for half of each cycle and 0 volts for the other half. With t in milliseconds, v(t) = 0 for −1 < t < 0 and v(t) = 5 for 0 < t < 1, with period 2 ms. Find its Fourier series, and give the amplitudes of the first and third harmonics.
L = 1,\quad a_0 = \int_{-1}^{1} v(t)\,dt = \int_0^1 5\,dt = 5Period 2, so L = 1; v is 0 on (−1, 0).
\frac{a_0}{2} = 2.5The average voltage.
a_n = \int_0^1 5\cos n\pi t\,dt = \frac{5\sin n\pi}{n\pi} = 0sin nπ = 0 for every whole number n.
b_n = \int_0^1 5\sin n\pi t\,dt = \frac{5\left(1 - (-1)^n\right)}{n\pi}Same integral as in Example 1, with nπt.
b_n = \frac{10}{n\pi} \text{ (n odd)},\quad b_n = 0 \text{ (n even)}1 − (−1)ⁿ is 2 for odd n.
b_1 = \frac{10}{\pi} \approx 3.183,\quad b_3 = \frac{10}{3\pi} \approx 1.061Use n = 1 and n = 3.
Answer: v(t) ∼ 2.5 + (10/π)(sin πt + sin 3πt/3 + sin 5πt/5 + ⋯). The first harmonic has amplitude about 3.18 V at 500 Hz (one cycle every 2 ms), and the third has about 1.06 V at 1500 Hz. A filter that removes the higher harmonics turns the square wave into a smoother wave.
Common mistakes
| Mistake | Example of the error | Fix |
|---|---|---|
| Using a₀ instead of a₀/2 as the constant term | Writing 2/3 + ⋯ for x² in Example 3 | The constant term is a₀/2 = 1/3, the average of f. |
| Dividing by 2L instead of L | Using 1/(2π) in front of the integral for bₙ | The coefficient formulas have 1/L, or 2/L with the even and odd shortcuts. |
| Treating cos nπ as 1 | Getting bₙ = 0 for the square wave | cos nπ = (−1)ⁿ, which alternates. |
| Computing coefficients that symmetry makes 0 | Integrating x cos nx in Example 2 | An odd function has every aₙ = 0; an even one has every bₙ = 0. |
| Saying the series equals f at a jump | Claiming the square wave series gives 1 at x = 0 | At a jump the series gives the average, here 0. |
| Using n² in the wrong place | Writing 4(−1)ⁿ/(nπ²) in Example 3 | Integrating by parts twice gives n² in the denominator. |
Related ideas
The Gibbs phenomenon
Near a jump, the partial sums always overshoot the function by about 9% of the jump, no matter how many terms you add. You can see the overshoot in the orange curve of the Example 1 graph. The overshoot gets narrower as you add terms, but it does not get shorter.
Half-range series
A function given only on 0 < x < L can be extended to be even or odd, which gives a pure cosine or pure sine series. That is the topic of the next lesson, Fourier Sine and Cosine Series, and it is the form used to solve the heat and wave equations.
Practice problems
- Is f(x) = x³ on (−π, π) even or odd? Which Fourier coefficients are 0?
- Find a₀/2 for f(x) = x + 2 on (−π, π).
- Find the Fourier series of f(x) = 0 for −π < x < 0 and f(x) = 1 for 0 < x < π.
- What value does the square wave series in Example 1 give at x = π?
- Find the Fourier series of f(x) = |x| on (−π, π).
- Use Problem 5 at x = 0 to find 1 + 1/9 + 1/25 + 1/49 + ⋯.
- Write the first three nonzero terms of the series in Example 2.
- Find a₀, a₄ and b₁ for f(x) = 3 + 2 cos 4x − sin x.
- Find b₂ for f(x) = x on (−1, 1) with period 2.
- A signal is −3 V for −2 < t < 0 and 3 V for 0 < t < 2 (t in ms, period 4 ms). Find bₙ and the amplitude of the first harmonic.
Show answers
1.
(-x)^3 = -x^3
Test f(−x).
Answer: x³ is odd, so every aₙ = 0 (including a₀); only the bₙ remain
2.
a_0 = \frac{1}{\pi}\int_{-\pi}^{\pi}(x + 2)\,dx = \frac{1}{\pi}(0 + 4\pi) = 4The integral of x over a symmetric interval is 0.
Answer: a₀/2 = 2
3.
a_0 = \frac{1}{\pi}\int_0^{\pi} 1\,dx = 1f is 0 on (−π, 0).
a_n = \frac{1}{\pi}\int_0^{\pi}\cos nx\,dx = \frac{\sin n\pi}{n\pi} = 0sin nπ = 0.
b_n = \frac{1}{\pi}\int_0^{\pi}\sin nx\,dx = \frac{1 - (-1)^n}{n\pi}Same integral as in Example 1.
Answer: f(x) ∼ 1/2 + (2/π)(sin x + sin 3x/3 + sin 5x/5 + ⋯)
4.
\frac{f(\pi^-) + f(\pi^+)}{2} = \frac{1 + (-1)}{2} = 0The wave jumps from 1 down to −1 at x = π.
Answer: 0 (every term sin nπ is 0 as well)
5.
a_0 = \frac{2}{\pi}\int_0^{\pi} x\,dx = \frac{2}{\pi}\cdot\frac{\pi^2}{2} = \pi|x| is even; use the cosine shortcut.
a_n = \frac{2}{\pi}\left[\frac{x\sin nx}{n} + \frac{\cos nx}{n^2}\right]_0^{\pi}Integrate x cos nx by parts.
a_n = \frac{2}{\pi}\cdot\frac{(-1)^n - 1}{n^2}Evaluate; the sine terms are 0.
a_n = -\frac{4}{\pi n^2} \text{ (n odd)},\quad a_n = 0 \text{ (n even)}(−1)ⁿ − 1 is −2 for odd n.
Answer: |x| ∼ π/2 − (4/π)(cos x + cos 3x/9 + cos 5x/25 + ⋯)
6.
0 = \frac{\pi}{2} - \frac{4}{\pi}\left(1 + \frac{1}{9} + \frac{1}{25} + \cdots\right)Substitute x = 0; |x| is continuous there.
1 + \frac{1}{9} + \frac{1}{25} + \cdots = \frac{\pi}{2}\cdot\frac{\pi}{4} = \frac{\pi^2}{8}Solve for the sum.
Answer: π²/8 ≈ 1.2337
7.
b_1 = 2,\quad b_2 = -1,\quad b_3 = \frac{2}{3}Use bₙ = 2(−1)ⁿ⁺¹/n.
Answer: 2 sin x − sin 2x + (2/3) sin 3x
8.
\frac{a_0}{2} = 3,\quad a_4 = 2,\quad b_1 = -1The function is already a Fourier series; match terms.
Answer: a₀ = 6, a₄ = 2 and b₁ = −1
9.
b_n = 2\int_0^1 x\sin n\pi x\,dx = -\frac{2(-1)^n}{n\pi}Odd shortcut with L = 1; the integral is from Example 3.
b_2 = -\frac{2}{2\pi} = -\frac{1}{\pi}Use n = 2.
Answer: b₂ = −1/π ≈ −0.318
10.
b_n = \frac{2}{2}\int_0^2 3\sin\frac{n\pi t}{2}\,dt = \frac{6\left(1 - (-1)^n\right)}{n\pi}Odd shortcut with L = 2.
b_n = \frac{12}{n\pi} \text{ (n odd)},\quad b_1 = \frac{12}{\pi} \approx 3.82Use n = 1.
Answer: bₙ = 12/(nπ) for odd n (0 for even n); the first harmonic has amplitude about 3.82 V
Fourier series FAQ
What is a Fourier series used for?
It breaks a periodic signal into simple waves. Engineers use it to study sound, vibrations and electric signals, and it is the key step in solving the heat and wave equations.
How do you find Fourier coefficients?
Multiply f by cos(nπx/L) or sin(nπx/L), integrate over one period, and divide by L. Check for even or odd symmetry first, since it makes half of the coefficients 0.
Does a Fourier series always converge to the function?
For piecewise smooth functions it converges to f(x) wherever f is continuous. At a jump it converges to the average of the values on the two sides.
What is the difference between a Fourier series and a Taylor series?
A Taylor series uses powers of x and matches a smooth function near one point. A Fourier series uses sines and cosines and matches a periodic function over a whole period, even with jumps.
Summary
- A Fourier series writes a function with period 2L as a₀/2 plus a sum of cosines and sines of nπx/L.
- aₙ and bₙ come from integrals of f times a cosine or sine over one period, divided by L.
- Even functions give cosine series; odd functions give sine series.
- The series converges to f where f is continuous and to the average at a jump.
- Fourier series can find exact sums, such as 1 + 1/4 + 1/9 + ⋯ = π²/6.
Previous lesson: Boundary Value Problems
Next lesson: Fourier Sine and Cosine Series
Back to the Differential Equations Index