Search

Search papers and lessons

Fourier Series

Level 2 · 12 min read

A Fourier series writes a repeating function as a sum of sines and cosines at whole-number multiples of one base frequency, with each coefficient found by a single integral.

On this page

  • Colour = topic mix
  • Discrete math
  • Calculus
  • Linear algebra
  • ReadReady to readNot yet

TL;DR

Many repeating signals, such as a musical note or the voltage in a power supply, can be built from pure sine and cosine waves. A Fourier series is that building recipe: a sum of waves whose frequencies are whole-number multiples of the signal's repetition rate, each with a weight that tells how much of that wave is present. Each weight is found with one Definite Integral, so the decomposition is computed, not guessed.

Builds on: Definite Integral, Euler's Formula · Leads to: Fourier Transform for signals that do not repeat, and Discrete Fourier Transform for signals stored as samples

Where it's used

Musical tones. A plucked guitar string vibrates at a base frequency and also at exact multiples of it, called harmonics. The sound you hear is the sum of those waves, each at its own strength. Audio tools that show the harmonic content of a note are plotting the coefficients of its Fourier series.

Power electronics. The switching circuit in many power supplies produces a square wave, which flips between two voltages. A square wave is a Fourier series with only odd harmonics, with the nnth harmonic at 1n\frac{1}{n} of the fundamental's strength. Engineers use that list of strengths to design the filter that removes the unwanted harmonics.

Heat and vibration problems. Joseph Fourier introduced the method to solve the heat equation, which describes how temperature spreads through a metal bar. The bar's starting temperature is written as a sum of sine waves, and each wave decays at its own rate. The same idea solves many wave and vibration equations in physics.

How it works

Before the general formula, look at the core move with a tiny signal. Take a Function ff that repeats every 2π2\pi units and is built from pieces we already know: f(x)=1+3cos⁡x+2sin⁡2xf(x) = 1 + 3\cos x + 2\sin 2x. The question is whether an integral can recover the three pieces from the function alone.

  1. Ask for the constant part. Integrate ff over one full period from −π-\pi to π\pi. The cosine and sine terms each average to zero over a full period, so only the constant 11 survives, giving 2π2\pi. Check: the integral of 11 over a length 2π2\pi interval is 2π2\pi. Dividing by π\pi gives a0=2a_0 = 2, and the constant term is half of that, 11.

  2. Multiply by one cosine and integrate. To find the weight of cos⁡x\cos x, multiply ff by cos⁡x\cos x and integrate over one period. Every term except 3cos⁡x⋅cos⁡x3\cos x \cdot \cos x integrates to zero, because a cosine times a different wave averages to zero over a full period. Check: the integral of 3cos⁡2x3\cos^2 x over one period is 3π3\pi, and dividing by π\pi returns the weight 33.

  3. Repeat for the sine at frequency 2. Multiply ff by sin⁡2x\sin 2x and integrate. Only 2sin⁡2x⋅sin⁡2x2\sin 2x \cdot \sin 2x survives, giving 2π2\pi, so the weight is 2ππ=2\frac{2\pi}{\pi} = 2. Check: the constant and the cosine at frequency 1 both integrate to zero against sin⁡2x\sin 2x, so they contribute nothing.

  4. Read off the recipe. The function is 1+3cos⁡x+2sin⁡2x1 + 3\cos x + 2\sin 2x, exactly what went in. The three integrals found the three weights and nothing else. Check: any term that is not in the signal gives a weight of zero.

  5. Handle a sharp edge. A square wave cannot be a finite sum of smooth waves, so its series needs infinitely many terms. The sum of the first few odd harmonics already looks like a square wave, and each extra term sharpens the edges.

−6−4−20246−101xpartial sum
  • 1 term
  • 2 terms
  • 3 terms
Adding odd harmonics pulls a single sine wave toward a square wave of height 1, which the sum approaches at every point except the jumps.
flowchart LR
  A[Repeating signal f] --> B[Integrate f times each cosine and sine]
  B --> C[Coefficients a and b]
  C --> D[Sum of waves reproduces f]

The math

Definition: Fourier series

For a function ff with period 2π2\pi, the Fourier series is

f(x)≈a02+∑n=1∞(ancos⁡nx+bnsin⁡nx),f(x) \approx \frac{a_0}{2} + \sum_{n=1}^{\infty} \big(a_n \cos nx + b_n \sin nx\big),

where the coefficients are

an=1π∫−ππf(x)cos⁡nx dx,bn=1π∫−ππf(x)sin⁡nx dx.a_n = \frac{1}{\pi}\int_{-\pi}^{\pi} f(x)\cos nx \, dx, \qquad b_n = \frac{1}{\pi}\int_{-\pi}^{\pi} f(x)\sin nx \, dx .

The constant term a02\frac{a_0}{2} is the average value of ff over one period. For a piecewise smooth ff, equality holds at points where ff is continuous, and the series converges to the midpoint of the two one-sided values at a jump.

Step 1 in symbols: the building blocks are orthogonal

The integrals work because the waves are orthogonal, meaning the integral of their product over a period is zero unless the two are the same wave. Using cos⁡Acos⁡B=12[cos⁡(A−B)+cos⁡(A+B)]\cos A \cos B = \tfrac{1}{2}\big[\cos(A - B) + \cos(A + B)\big] and the fact that ∫−ππcos⁡kx dx=0\int_{-\pi}^{\pi} \cos kx \, dx = 0 for every whole number k≠0k \ne 0:

∫−ππcos⁡mxcos⁡nx dx={πm=n≥10m≠n\int_{-\pi}^{\pi} \cos mx \cos nx \, dx = \begin{cases} \pi & m = n \ge 1 \\ 0 & m \ne n \end{cases}

The sine version works the same way, and the product cos⁡mxsin⁡nx\cos mx \sin nx integrates to zero for all whole numbers mm and nn. The same result follows in one line from Euler's Formula: writing cos⁡nx=12(einx+e−inx)\cos nx = \tfrac{1}{2}(e^{inx} + e^{-inx}) turns each product into exponentials, and an exponential integrates to zero over a period unless its exponent is zero. This integral is the inner product of two functions, the function version of the Dot Product, and the functions live in a Hilbert space.

Step 2 in symbols: why the integral picks out one weight

Multiply the series by cos⁡kx\cos kx and integrate over one period. By Step 1, every term vanishes except the one with n=kn = k, which gives πak\pi a_k. Divide by π\pi and the formula for aka_k follows. Dividing by π\pi is dividing by the squared length of cos⁡kx\cos kx, so aka_k is the projection of ff onto that wave. The same argument with sin⁡kx\sin kx gives bkb_k.

Check with the walkthrough: multiplying by cos⁡x\cos x left only 3π3\pi, and 3π÷π=33\pi \div \pi = 3.

Step 3 in symbols: the square wave

Take f(x)=1f(x) = 1 on 0<x<π0 < x < \pi and f(x)=−1f(x) = -1 on −π<x<0-\pi < x < 0. This function is odd, meaning f(−x)=−f(x)f(-x) = -f(x), so every cosine coefficient is zero. For the sines,

bn=2π∫0πsin⁡nx dx=2π⋅1−cos⁡nπn.b_n = \frac{2}{\pi}\int_0^{\pi} \sin nx \, dx = \frac{2}{\pi}\cdot\frac{1 - \cos n\pi}{n}.

When nn is even, cos⁡nπ=1\cos n\pi = 1 and bn=0b_n = 0. When nn is odd, cos⁡nπ=−1\cos n\pi = -1 and bn=4πnb_n = \frac{4}{\pi n}. So the series is

f(x)=4π∑k=0∞sin⁡((2k+1)x)2k+1.f(x) = \frac{4}{\pi}\sum_{k=0}^{\infty} \frac{\sin\big((2k+1)x\big)}{2k+1}.

Each odd harmonic has strength 1n\frac{1}{n} of the first, as the power-electronics example said.

Worked examples

Example
1. A three-term signal

Let f(x)=1+3cos⁡x+2sin⁡2xf(x) = 1 + 3\cos x + 2\sin 2x on −π<x<π-\pi < x < \pi.

  1. Constant weight: a0=1π∫−ππ1 dx=2ππ=2a_0 = \frac{1}{\pi}\int_{-\pi}^{\pi} 1 \, dx = \frac{2\pi}{\pi} = 2. So the constant term a02\frac{a_0}{2} is 11.
  2. Cosine weight at frequency 1: a1=1π∫−ππ3cos⁡2x dx=3ππ=3a_1 = \frac{1}{\pi}\int_{-\pi}^{\pi} 3\cos^2 x \, dx = \frac{3\pi}{\pi} = 3.
  3. Sine weight at frequency 2: b2=1π∫−ππ2sin⁡22x dx=2ππ=2b_2 = \frac{1}{\pi}\int_{-\pi}^{\pi} 2\sin^2 2x \, dx = \frac{2\pi}{\pi} = 2.
  4. Every other coefficient is 00, because the integrals of the mismatched products vanish.
  5. The recipe is 1+3cos⁡x+2sin⁡2x1 + 3\cos x + 2\sin 2x, the original function.
Example
2. The square wave's first terms

Use bn=4πnb_n = \frac{4}{\pi n} for odd nn. Evaluate the three-term partial sum at x=π2x = \frac{\pi}{2}.

  1. Odd coefficients: b1=4πb_1 = \frac{4}{\pi}, b3=43πb_3 = \frac{4}{3\pi}, b5=45πb_5 = \frac{4}{5\pi}.
  2. Sine values at π2\frac{\pi}{2}: sin⁡π2=1\sin\frac{\pi}{2} = 1, sin⁡3π2=−1\sin\frac{3\pi}{2} = -1, sin⁡5π2=1\sin\frac{5\pi}{2} = 1.
  3. Partial sum: 4π⋅1+43π⋅(−1)+45π⋅1=4π(1−13+15)\frac{4}{\pi}\cdot 1 + \frac{4}{3\pi}\cdot(-1) + \frac{4}{5\pi}\cdot 1 = \frac{4}{\pi}\left(1 - \frac{1}{3} + \frac{1}{5}\right).
  4. Inside the bracket: 1−13=231 - \frac{1}{3} = \frac{2}{3}, and 23+15=1315\frac{2}{3} + \frac{1}{5} = \frac{13}{15}.
  5. The sum is 4π⋅1315=5215π≈1.10\frac{4}{\pi}\cdot\frac{13}{15} = \frac{52}{15\pi} \approx 1.10. The true value at π2\frac{\pi}{2} is 11, so three terms are already close, and the next terms bring it closer.
Example
3. A realistic signal: a 2 kHz square wave

A clock line switches between 0 and 5 volts at 2 kHz. Shift it to a zero average and it is a square wave with fundamental frequency f1=2f_1 = 2 kHz.

  1. Harmonics are at odd multiples of the fundamental: fn=n×2f_n = n \times 2 kHz for odd nn.
  2. The 3rd harmonic is at 66 kHz with strength 13\frac{1}{3} of the fundamental. The 5th is at 1010 kHz with strength 15\frac{1}{5}.
  3. The 7th harmonic is at 7×2=147 \times 2 = 14 kHz with strength 17≈0.143\frac{1}{7} \approx 0.143 of the fundamental.
  4. Relative to the fundamental, the 6 kHz component is one third as strong and the 10 kHz component one fifth as strong. A filter that passes 2 kHz and blocks everything above 4 kHz removes both, and the designer knows exactly which frequencies to block from the list.
  5. The series turns a sharp digital edge into a short list of frequencies and strengths, and the filter is designed from that list.

Try it: a square wave repeats at 500500 Hz. What are the frequencies of the 3rd and 9th harmonics, and what is the 9th harmonic's strength relative to the fundamental? Answer: 3×500=15003 \times 500 = 1500 Hz and 9×500=45009 \times 500 = 4500 Hz. The 9th harmonic's strength is 19≈0.111\frac{1}{9} \approx 0.111 of the fundamental.

Common mistakes and tradeoffs

It is tempting to think that a Fourier series only works for smooth functions. In fact jumps are fine: the series converges to the midpoint of the two sides at a jump. What jumps cause is a slow approach and an overshoot near the jump. For a square wave the partial sums overshoot by about 9% of the jump size, and the overshoot does not shrink as more terms are added, only narrows. This is the Gibbs phenomenon.

It is tempting to think a Fourier series needs the function to be a sum of sines in the first place. In fact the integrals give coefficients for any function that is integrable over one period, including ones with no obvious sine form. For piecewise smooth functions, the sine-and-cosine sum represents the function exactly at points of continuity.

It is tempting to think the coefficients are the function's values at some points. In fact each coefficient is an integral over the whole period, so changing the function at a single point does not change any coefficient.

Use a Fourier series when a signal repeats exactly and you want its frequency content. Do not use it for a signal that does not repeat; there the Fourier Transform replaces the whole-number harmonics with a continuous range of frequencies. For a signal stored as samples, use the Discrete Fourier Transform, which the computer can evaluate.

History

In 1807, Joseph Fourier submitted a memoir on heat conduction that used sums of sines and cosines to solve the heat equation, and his book on the topic appeared in 1822. Mathematicians of the time doubted that an arbitrary function, with jumps or kinks, could be written this way, and the argument over which functions the series represent went on for decades. Peter Gustav Lejeune Dirichlet gave the first precise convergence conditions in 1829, which settled the question for a broad class of functions.

The overshoot at jumps was noticed in the late 1890s, and it bears the name of Josiah Willard Gibbs, who wrote about it. The method caught on because it turned a hard differential equation into a set of simple coefficients, and the same coefficient calculation later became the basis of signal analysis in engineering.

Recap

  • A repeating signal can be written as a constant plus cosines and sines at whole-number multiples of its base frequency.
  • Each coefficient is an integral of the signal against one wave, and the orthogonality of the waves makes all other terms vanish.
  • A square wave has only odd harmonics, with strength 1n\frac{1}{n} for the nnth.
  • Jumps cause overshoot that does not disappear as more terms are added.
  • The non-repeating version is the Fourier Transform, and the sampled version is the Discrete Fourier Transform.

Read next: Fourier Transform to see the same idea for signals that do not repeat.

Check yourself

QuestionWhat do the Fourier coefficient a0a_0 and the constant term a02\frac{a_0}{2} measure?Show answer

a02\frac{a_0}{2} is the average value of the function over one period. a0a_0 is twice that average, because a0=1π∫−ππf(x) dxa_0 = \frac{1}{\pi}\int_{-\pi}^{\pi} f(x)\,dx divides the integral over a length of 2π2\pi by π\pi.

QuestionFor f(x)=2cos⁡3x−sin⁡xf(x) = 2\cos 3x - \sin x on −π<x<π-\pi < x < \pi, what are a3a_3 and b1b_1?Show answer

a3=1π∫−ππ2cos⁡23x dx=2ππ=2a_3 = \frac{1}{\pi}\int_{-\pi}^{\pi} 2\cos^2 3x\,dx = \frac{2\pi}{\pi} = 2, and b1=1π∫−ππ(−sin⁡2x) dx=−1b_1 = \frac{1}{\pi}\int_{-\pi}^{\pi} (-\sin^2 x)\,dx = -1. All other coefficients are zero because the cross terms integrate to zero.

QuestionWhy does a square wave's Fourier series contain only odd harmonics?Show answer

Its coefficients bn=2π⋅1−cos⁡nπnb_n = \frac{2}{\pi}\cdot\frac{1 - \cos n\pi}{n} vanish when nn is even, because cos⁡nπ=1\cos n\pi = 1 for even nn. Only odd nn give cos⁡nπ=−1\cos n\pi = -1, which makes the coefficient nonzero.

QuestionA student says a Fourier series of a function with a jump will never converge at any point. Is that correct?Show answer

No. At the jump the series converges to the midpoint of the two one-sided values, and at points of continuity it converges to the function. What the jump causes is slow convergence and an overshoot near the jump, which does not vanish as terms are added.

QuestionA signal repeats every 0.250.25 seconds. What is its base frequency, and what is the frequency of its 4th harmonic?Show answer

The base frequency is 10.25=4\frac{1}{0.25} = 4 Hz. The 4th harmonic is at 4×4=164 \times 4 = 16 Hz.

Sources