---
title: "Fourier series: finding coefficients by correlation"
heading: Measuring how much of each sinusoid a signal contains
eyebrow: A10 · Lesson 2 · Fourier coefficients
xp: 40
---

::: hook
Lesson 1 took the square wave's recipe on trust: odd harmonics, amplitudes $4/n\pi$. How would you find the recipe for a signal you've never seen? Multiply it by a test sinusoid and average over one period. If the signal contains that sinusoid, the product leans positive and the average is big; if not, the positive and negative parts cancel to exactly zero. That multiply-and-average step, a correlation, is how every spectrum analyzer and every radio receiver picks out one frequency from many.

::: play
- The square wave (period 1 s) is multiplied by a test sinusoid at harmonic $n$; the shaded area is their product over one period. The readout is the Fourier coefficient: twice the product's average.
- Try $n = 1, 2, 3, 4$. Which harmonics give zero, and how can you see it in the shading?
- Delay the square wave with $d$. Switch the test from sine ($c = 0$) to cosine ($c = 1$). Where does the harmonic go?
:::
:::

```sim plot
view: graph
x: t = 0..1 s
y: v = -1.5..1.5
slider: n = 1..7 step 1 = 1
slider: d = 0..0.5 step 0.05 = 0
slider: c = 0..1 step 1 = 0
plot: sign(sin(2*pi*(t - d))) | label: square wave
plot: (1 - c)*sin(2*pi*n*t) + c*cos(2*pi*n*t) | dashed | color: ch3 | label: test
plot: sign(sin(2*pi*(t - d)))*((1 - c)*sin(2*pi*n*t) + c*cos(2*pi*n*t)) | fill: 0..1 | color: ch2 | samples: 2000 | label: product
readout: coefficient = (2*(1 - cos(n*pi))/(n*pi))*((1 - c)*cos(2*pi*n*d) - c*sin(2*pi*n*d))
```

::: predict
## The square wave is multiplied by $\sin(2\cdot 2\pi t)$, its second harmonic. What is the average of the product over one period?

- [ ] Positive
- [ ] Negative
- [x] Zero
- [ ] It depends on the square wave's amplitude

::: reveal
Zero. In each half of the square wave, the test sine goes through one full cycle, half positive and half negative, so the product's area cancels exactly. A symmetric square wave has no even harmonics, and this is the reason: they're orthogonal to it.
:::
:::

::: nameit
## Fourier coefficients

**Orthogonality.** Over one period $T$, the average of the product of two harmonics is zero unless they're the same frequency and the same type:

$$\frac{1}{T}\int_0^T \sin(m\omega_0t)\sin(n\omega_0t)\,dt = \begin{cases}\tfrac12 & m = n\\ 0 & m \ne n\end{cases}$$

and the same for cosines, while every sine is orthogonal to every cosine. So when you multiply $x(t) = a_0 + \sum (a_n\cos n\omega_0t + b_n\sin n\omega_0t)$ by $\sin(k\omega_0t)$ and average, every term vanishes except $b_k/2$. That gives the coefficients:

$$a_0 = \frac1T\int_0^T x\,dt \qquad a_n = \frac2T\int_0^T x\cos(n\omega_0t)\,dt \qquad b_n = \frac2T\int_0^T x\sin(n\omega_0t)\,dt$$

The amplitude of the $n$th harmonic is $A_n = \sqrt{a_n^2 + b_n^2}$, however the signal is shifted in time. Shifting it just moves the harmonic between its sine and cosine parts, which is what the $d$ slider shows.

**The square wave.** For $x = +1$ on the first half period and $-1$ on the second, $b_n = \frac{2}{n\pi}\big(1 - \cos n\pi\big)$: that's $\frac{4}{n\pi}$ for odd $n$ and 0 for even $n$, the recipe from lesson 1.

**Symmetry shortcuts.** If $x(t)$ is **even** ($x(-t) = x(t)$), all the $b_n$ are zero; if it's **odd** ($x(-t) = -x(t)$), all the $a_n$ are zero.

**The complex form.** Using $e^{j\theta} = \cos\theta + j\sin\theta$ packs each pair into one complex number:

$$x(t) = \sum_{n=-\infty}^{\infty} c_ne^{jn\omega_0t} \qquad c_n = \frac1T\int_0^T x(t)\,e^{-jn\omega_0t}\,dt$$

For a real signal, $c_{-n}$ is the conjugate of $c_n$, and $|c_n| = A_n/2$: each sinusoid splits into two counter-rotating phasors (A3), half the amplitude each.

**Power adds up by harmonic** (Parseval's theorem). The average power of a signal, its mean square, is $a_0^2 + \sum A_n^2/2$. For the ±1 square wave, the mean square is 1, and the fundamental alone carries $\tfrac12(4/\pi)^2 = 81\%$ of it.
:::

::: example
## Find the Fourier coefficients of the sawtooth $x(t) = \frac{2t}{T} - 1$ for $0 \le t < T$, repeating.

::: solution
1. **The DC term.** The sawtooth's average is 0, so $a_0 = 0$.
2. **The cosine terms.** The repeating sawtooth is odd about $t = 0$ (just before 0 it's near $+1$, just after, near $-1$), so every $a_n$ is zero too.
3. **The integral for the sines.** The $-1$ integrates to zero over a period, and
   $$\int_0^T t\sin(n\omega_0t)\,dt = -\frac{T^2}{2\pi n}$$
4. **The sine terms.**
   $$\begin{aligned} b_n &= \frac{2}{T}\cdot\frac{2}{T}\cdot\left(-\frac{T^2}{2\pi n}\right) \\ &= -\frac{2}{\pi n} \end{aligned}$$
5. **The sizes.** Every harmonic is present, falling as $1/n$: 0.637, 0.318, 0.212 and so on.

**Answer:** $a_0$ and every $a_n$ are zero, and $b_n = -\frac{2}{\pi n}$, so the harmonics have sizes 0.637, 0.318, 0.212 and so on.
:::
:::

::: example
## What fraction of the sawtooth's power is in its fundamental?

::: solution
1. **The total power.** The sawtooth sweeps evenly from $-1$ to $1$, so its mean square is $\frac{1}{3}$.
2. **The fundamental's power.**
   $$\begin{aligned} P_1 &= \frac{1}{2}\left(\frac{2}{\pi}\right)^2 \\ &= 0.203 \end{aligned}$$
3. **The fraction.**
   $$\frac{0.203}{1/3} = 61\%$$
4. **Compare with a square wave.** A square wave puts 81% in its fundamental. The sawtooth spreads more into its harmonics because it has even ones too.

**Answer:** 61% of the sawtooth's power is in its fundamental.
:::
:::

::: example
## A half-wave rectifier passes the positive halves of a 10 V sine. What are its DC level, fundamental and 2nd harmonic?

::: solution
1. **The DC level.** For a half-wave rectified sine of peak $A = 10$ V:
   $$\begin{aligned} \frac{A}{\pi} &= \frac{10\ \text{V}}{\pi} \\ &= 3.18\ \text{V} \end{aligned}$$
2. **The fundamental.** Its amplitude is
   $$\frac{A}{2} = 5\ \text{V}$$
3. **The 2nd harmonic.** The even harmonics have amplitudes $\frac{2A}{\pi(n^2 - 1)}$, so for $n = 2$:
   $$\begin{aligned} V_2 &= \frac{20}{3\pi} \\ &= 2.12\ \text{V} \end{aligned}$$
   The odd harmonics above the first are zero.
4. **What the supply's filter faces.** A power supply's filter has to suppress that 2.12 V component at twice the line frequency, along with the fundamental.

**Answer:** the DC level is 3.18 V, the fundamental 5 V and the 2nd harmonic 2.12 V.
:::
:::

::: check
given: A = 2..12 int; D = 0.1 | 0.2 | 0.25 | 0.4
answer: A*D
unit: V
tolerance: 0.5%

## A pulse train is {A} V for a fraction {D} of each period and 0 V the rest of the time. What is its DC coefficient $a_0$?

::: right
Right. $a_0$ is the average: {A} V × {D} = {answer}.
:::

::: misses
- [A/2] That's for a 50% duty cycle. Average over the actual fraction of time it's high.
- [A] That's its peak. $a_0$ is the average.
- [any] Not yet. $a_0 = \frac1T\int_0^T x\,dt$.
:::
:::

::: check
kind: parts
given: p = 1..9 int; q = -9..-1 int; r = 2..9 int

## A periodic signal is $x(t) = \given{r} + \given{p}\sin(\omega_0t) + (\given{q})\cos(3\omega_0t)$.

::: part
answer: r
tolerance: 0.5%

### What is $a_0$?

::: misses
- [0] The constant term is the average.
- [any] The average over a period.
:::
:::

::: part
answer: p
tolerance: 0.5%

### What is $b_1$?

::: misses
- [0] There is a $\sin\omega_0t$ term.
- [any] The coefficient of $\sin\omega_0t$.
:::
:::

::: part
answer: q
tolerance: 0.5%

### What is $a_3$?

::: misses
- [-q] Keep its sign.
- [0] There is a $\cos 3\omega_0t$ term.
- [any] The coefficient of $\cos 3\omega_0t$.
:::
:::

::: right
Right. When a signal is already written as a sum of harmonics, the coefficients are just read off; correlation would find the same numbers.
:::
:::

::: check
given: a = -9..-1 int; b = 1..9 int
answer: sqrt(a^2 + b^2)
tolerance: 0.5%

## A harmonic has $a_n$ = {a} and $b_n$ = {b}. What is its amplitude?

::: right
Right. $A_n = \sqrt{a_n^2 + b_n^2}$ = {answer}.
:::

::: misses
- [abs(a) + abs(b)] They're perpendicular parts: combine them with Pythagoras.
- [a + b] Combine with Pythagoras.
- [any] Not yet. $A_n = \sqrt{a_n^2 + b_n^2}$.
:::
:::

::: check
given: A = 1..9 int; D = 0.1 | 0.2 | 0.3
answer: 2*A/pi*sin(pi*D)
tolerance: 0.5%

## A pulse train of height {A} and duty cycle {D} is centered on $t = 0$, so it's even. Its fundamental's cosine coefficient is $a_1 = \frac{2A}{\pi}\sin(\pi D)$. What is $a_1$?

::: right
Right. {answer}. Narrow pulses (small D) have small harmonics, spread out to very high frequencies.
:::

::: misses
- [2*A/pi*sin(D)] The argument is $\pi D$ in radians.
- [2*A*D] That's the small-D estimate, close but not exact.
- [any] Not yet. Evaluate $\frac{2A}{\pi}\sin(\pi D)$.
:::
:::

::: check
given: n = 1 | 3 | 5
answer: 100*(4/(n*pi))^2/2
unit: %
tolerance: 1%

## What percentage of a ±1 square wave's power is in its {n}th harmonic?

::: right
Right. The harmonic has amplitude $4/(n\pi)$ and power $A_n^2/2$, against a total mean square of 1: {answer}.
:::

::: misses
- [100*4/(n*pi)] Power goes as the amplitude squared, halved for a sinusoid.
- [100*(4/(n*pi))^2] A sinusoid's mean square is half its amplitude squared.
- [any] Not yet. Power in a harmonic is $A_n^2/2$.
:::
:::

::: check
kind: parts
given: A = 5 | 9 | 12 | 15 | 24 | 120 | 170

## A half-wave rectifier passes the positive halves of a sine of peak {A} V.

::: part
answer: A/pi
unit: V
tolerance: 0.5%

### What is the DC level?

::: misses
- [2*A/pi] That's the full-wave rectifier's DC level.
- [any] $\frac{1}{T}\int$ over one period.
:::
:::

::: part
answer: 2*A/(3*pi)
unit: V
tolerance: 0.5%

### What is the 2nd harmonic's amplitude?

::: misses
- [any] $\frac{2A}{\pi(n^2 - 1)}$ with $n = 2$.
:::
:::
:::

::: check
kind: derivation
vars: A = 1..10, T = 0.5..5

## Find the average of the sawtooth $x = A\frac{t}{T}$ over $0 \le t < T$.

::: step
answer: A*T/2

### What is $\int_0^TA\frac tT\,dt$?
:::

::: step
answer: A/2

### What is the average, $a_0$?
:::

::: right
Right. The DC coefficient is the average: half the peak for a sawtooth that starts at zero.
:::
:::

::: explain
## Why does multiplying a signal by $\sin(k\omega_0t)$ and averaging pick out just the $k$th sine coefficient?

::: model
Write the signal as its sum of harmonics. Multiplying by $\sin(k\omega_0t)$ multiplies every term, and averaging over a period then kills every product of two different harmonics, and every sine-times-cosine product, because over a full period they're positive and negative by equal amounts. The only term that survives is $b_k\sin^2(k\omega_0t)$, which averages to $b_k/2$. So twice the average is exactly $b_k$.
:::
:::

::: practice

::: check
given: c = 1..9 int; a = 2..9 int
answer: c
tolerance: 0.5%

## What is the average value of $\given{c} + \given{a}\cos(\omega_0t)$ over a period?

::: misses
- [c + a] The cosine averages to zero.
- [any] The average is $a_0$.
:::
:::

::: check
kind: choice

## A periodic signal is even: $x(-t) = x(t)$. Which of its Fourier coefficients must be zero?

- [ ] All the $a_n$
- [x] All the $b_n$
- [ ] $a_0$
- [ ] None of them

::: right
Right. An even signal is built from cosines, which are even. Sines are odd, so they can't appear.
:::

::: misses
- [1] Even signals use cosines: it's the sine terms that vanish.
- [3] The average can be anything.
- [4] Symmetry forces the sine terms to zero.
:::
:::

::: check
given: m = 2..5 int; k = 6..9 int
answer: 0
tolerance: 0.001

## What is the average of $\sin(\given{m}\omega_0t)\sin(\given{k}\omega_0t)$ over one period of $\omega_0$?

::: misses
- [0.5] That's for the same frequency. These differ.
- [any] Different harmonics are orthogonal.
:::
:::
:::
