---
title: OFDM, as used in Wi-Fi and DSL
heading: Splitting a fast stream into many slow subcarriers, orthogonality and the FFT that makes it cheap, the cyclic prefix that turns echoes into one complex gain per subcarrier, one-tap equalization, frequency offsets and the leakage they cause, and the numbers behind Wi-Fi's 54 Mb/s
eyebrow: D12 · Lesson 13 · OFDM
xp: 40
---

::: hook
A single fast carrier in a room full of echoes needs a long, adaptive equalizer. OFDM sidesteps the problem by sending hundreds of slow carriers side by side, each so slow that an echo is short compared with its symbols. A short guard interval, the **cyclic prefix**, absorbs the echo completely, and then each subcarrier sees nothing worse than a fixed gain and phase, removed by one division. An inverse FFT builds all the subcarriers at once and an FFT separates them. Wi-Fi, DSL, LTE, 5G and digital TV all work this way.
:::

::: play
- Six neighboring subcarriers' spectra, each a sinc centered on its frequency, with frequency measured in subcarrier spacings.
- Each sinc passes through zero exactly at every other subcarrier's center, so sampling subcarrier 2 at its center sees only its own symbol: the subcarriers overlap and still don't interfere.
- Give the receiver a frequency offset ε and the marker moves off center. Its own subcarrier shrinks and the neighbors leak in: inter-carrier interference.
:::

```sim plot
view: graph
x: f = -1..7
y: A = -0.35..1.1
slider: e = 0..0.5 step 0.01 = 0
plot: sinc(f) | samples: 800 | label: subcarrier 0 (f in subcarrier spacings)
plot: sinc(f - 1) | samples: 800 | color: ch2 | label: 1
plot: sinc(f - 2) | samples: 800 | color: ch3 | label: 2
plot: sinc(f - 3) | samples: 800 | color: ch4 | label: 3
plot: sinc(f - 4) | samples: 800 | color: ch1 | label: 4
plot: sinc(f - 5) | samples: 800 | color: ch2 | label: 5
marker: x = 2 + e | label: where the receiver samples subcarrier 2
readout: own subcarrier = sinc(e) | digits: 3
readout: nearest neighbor's leakage, dB = 20*log(abs(sinc(1 - e)) + 1e-12) | digits: 3
```

::: predict
## An OFDM system uses 64 subcarriers and a 16-sample cyclic prefix. An echo arrives 10 samples after the direct path. What does it do to the subcarriers?

- [x] Each subcarrier just gets its own fixed gain and phase
- [ ] Every subcarrier interferes with every other
- [ ] The symbols smear into each other
- [ ] Nothing at all

::: reveal
The echo is shorter than the prefix, so within the FFT window every subcarrier sees whole cycles of both the direct path and the echo. Two sinusoids of the same frequency add to one sinusoid of that frequency, so each subcarrier comes out multiplied by one complex number, $H(f_k)$, different for each subcarrier. Dividing by it undoes the echo. An echo longer than 16 samples would spill into the next symbol.
:::
:::

::: nameit
## Subcarriers

N subcarriers spaced $\Delta f = f_s/N$ apart, each carrying one symbol $X_k$ for a time $T = N/f_s = 1/\Delta f$. Over that time each subcarrier is a whole number of cycles, so they're orthogonal: their spectra are sincs with zeros on every other center. The transmitter builds the sum with an inverse FFT; the receiver separates it with an FFT, at a cost of $N\log_2 N$ operations instead of $N^2$.

## The cyclic prefix

Copying the last $N_{cp}$ samples to the front makes the channel's linear convolution look circular within the FFT window, as long as the channel's impulse response is no longer than the prefix. Then

$$Y_k = H_kX_k + \text{noise}, \qquad H_k = \sum_n h[n]e^{-j2\pi kn/N}$$

and a **one-tap equalizer** divides by $H_k$, estimated from known pilot subcarriers or a training symbol. The prefix costs $N_{cp}/(N + N_{cp})$ of the airtime.

## Frequency offset

An offset of ε subcarrier spacings shrinks each subcarrier to sinc(ε) and leaks sinc(1 − ε) from each neighbor: −19.2 dB at ε = 0.1. OFDM receivers estimate and remove the offset from the preamble to a few percent of a spacing.

## Practical details

Subcarriers in a deep notch carry little, so codes spread each bit across many subcarriers, and DSL loads more bits onto subcarriers with better SNR. The sum of many subcarriers has a high peak-to-average ratio, so transmitters need linear amplifiers with back-off (lesson 9).
:::

::: example
## Wi-Fi (802.11a/g) samples at 20 MHz with a 64-point FFT and a 16-sample prefix, and 48 of the subcarriers carry data. What's its subcarrier spacing, symbol time and top data rate with 64-QAM at rate 3/4?

::: solution
1. **Subcarrier spacing.**
   $$\begin{aligned} \Delta f &= \frac{20\ \text{MHz}}{64} \\ &= 312.5\ \text{kHz} \end{aligned}$$
2. **Symbol time.** The FFT window plus the prefix:
   $$\begin{aligned} T &= \frac{64}{20\ \text{MHz}} + 0.8\ \mu\text{s} \\ &= 3.2\ \mu\text{s} + 0.8\ \mu\text{s} \\ &= 4\ \mu\text{s} \end{aligned}$$
3. **Data bits per symbol.** 64-QAM carries 6 bits per subcarrier:
   $$48 \times 6 \times \tfrac{3}{4} = 216\ \text{bits}$$
4. **Data rate.**
   $$\begin{aligned} R &= \frac{216\ \text{bits}}{4\ \mu\text{s}} \\ &= 54\ \text{Mb/s} \end{aligned}$$
5. **Echo tolerance.** The prefix absorbs echoes up to 0.8 µs, 240 m of extra path.

**Answer:** 312.5 kHz spacing, a 4 µs symbol and a top rate of 54 Mb/s.
:::
:::

::: example
## An acoustic OFDM modem samples at 9600 Hz with 256 subcarriers and a 64-sample prefix. What spacing, symbol time and echo tolerance does it have?

::: solution
1. **Subcarrier spacing.**
   $$\frac{9600}{256} = 37.5\ \text{Hz}$$
2. **Symbol time.**
   $$\begin{aligned} T &= \frac{256}{9600}\ \text{s} \\ &= 26.7\ \text{ms} \end{aligned}$$
3. **Prefix.**
   $$\begin{aligned} T_{\text{cp}} &= \frac{64}{9600}\ \text{s} \\ &= 6.7\ \text{ms} \end{aligned}$$
   That's 20% overhead, and it absorbs echoes from up to 2.3 m of extra path.
4. **Real rooms.** Rooms reverberate for longer than that, so acoustic modems accept some leftover interference or use longer prefixes.

**Answer:** 37.5 Hz spacing, 26.7 ms symbols plus a 6.7 ms prefix, and tolerance for echoes from up to 2.3 m of extra path.
:::
:::

::: example
## What is the worst-case peak-to-average power ratio of OFDM with 256 subcarriers?

::: solution
1. **The worst case.** If all 256 subcarriers line up in phase, the peak is 256 times the average:
   $$10\log_{10}256 = 24.1\ \text{dB}$$
2. **Real symbols.** They rarely come close, but peaks of 10 to 12 dB are common.
3. **Headroom.** The transmitter's amplifier (here a speaker) must have that much headroom or the signal clips.

**Answer:** 256 times the average power, or 24.1 dB.
:::
:::

::: check
kind: python

## Build an OFDM modulator and demodulator with a cyclic prefix, and equalize a channel.

```python starter
import numpy as np

N, CP = 64, 16   # subcarriers and cyclic-prefix samples

def ofdm_mod(X):
    # X has one row of N subcarrier values per OFDM symbol. For each row, take np.fft.ifft,
    # put a copy of its last CP samples in front, and join all the symbols into one array.
    return np.zeros(len(X)*(N + CP), dtype=complex)

def ofdm_demod(y, nsym):
    # The reverse for nsym symbols: drop each symbol's CP and take np.fft.fft of the remaining N
    # samples. Return an (nsym, N) array.
    return np.zeros((nsym, N), dtype=complex)

def equalize(Y, h):
    # One tap per subcarrier: divide every row of Y by the channel's frequency response,
    # np.fft.fft(h, N), for an impulse response h.
    return Y
```

```python solution
import numpy as np

N, CP = 64, 16   # subcarriers and cyclic-prefix samples

def ofdm_mod(X):
    out = []
    for row in X:
        x = np.fft.ifft(row)
        out.append(np.r_[x[-CP:], x])
    return np.concatenate(out)

def ofdm_demod(y, nsym):
    blocks = np.asarray(y[:nsym*(N + CP)]).reshape(nsym, N + CP)
    return np.fft.fft(blocks[:, CP:], axis=1)

def equalize(Y, h):
    return Y/np.fft.fft(h, N)
```

```python tests
_rng = np.random.default_rng(13)
_X = (_rng.choice([-1, 1], (10, N)) + 1j*_rng.choice([-1, 1], (10, N)))/np.sqrt(2)
_x = ofdm_mod(_X)
assert len(_x) == 10*(N + CP), "Each symbol is N + CP samples long."
assert np.allclose(_x[:CP], _x[N:N + CP]), "The cyclic prefix is a copy of the symbol's end."
assert np.allclose(ofdm_demod(_x, 10), _X), "Without a channel, demodulation returns the subcarriers exactly."
_h = np.zeros(12, dtype=complex); _h[0] = 1; _h[5] = 0.6j; _h[11] = -0.3
_y = np.convolve(_x, _h)[:len(_x)]
assert np.allclose(equalize(ofdm_demod(_y, 10), _h), _X), "An echo shorter than the prefix becomes one complex gain per subcarrier, which one division removes."
_h2 = np.zeros(25, dtype=complex); _h2[0] = 1; _h2[24] = 0.5
_y2 = np.convolve(_x, _h2)[:len(_x)]
assert np.max(np.abs(equalize(ofdm_demod(_y2, 10), _h2)[1:] - _X[1:])) > 0.1, "An echo longer than the prefix leaks between symbols, and the one-tap equalizer can't undo it."
```

::: right
Right. Your OFDM link turns an echo shorter than the prefix into one gain per subcarrier and removes it exactly, and you've seen what a longer echo does.
:::
:::

::: check
given: s = 5 | 10 | 20; N = 64 | 256 | 1024
answer: s*1000/N
unit: kHz
tolerance: 0.5%

## An OFDM system samples at {s} MHz with a {N}-point FFT. What's its subcarrier spacing?

::: right
Right. $f_s/N$ = {answer} kHz.
:::

::: misses
- [any] Not yet. The sample rate shared among N subcarriers.
:::
:::

::: check
given: N = 64 | 256; c = 8 | 16 | 32 | 64
answer: 100*c/(N + c)
tolerance: 0.5%

## An OFDM symbol has {N} samples plus a {c}-sample cyclic prefix. What percentage of the airtime does the prefix use?

::: right
Right. $N_{cp}/(N + N_{cp})$ = {answer}%.
:::

::: misses
- [100*c/N] The prefix's share of the whole symbol, prefix included.
- [any] Not yet. Prefix over total.
:::
:::

::: check
given: b = 1 | 2 | 4 | 6; r = 0.5 | 0.75
answer: 48*b*r/4
unit: Mbit/s
tolerance: 0.5%

## A Wi-Fi symbol (4 µs) has 48 data subcarriers, each carrying {b} coded bits at code rate {r}. What's the data rate?

::: right
Right. 48 × {b} × {r}/4 µs = {answer} Mbit/s.
:::

::: misses
- [48*b/4] Only the code rate's share of the coded bits is data.
- [64*b*r/4] Only 48 of the 64 subcarriers carry data.
- [any] Not yet. Data bits per symbol over the symbol time.
:::
:::

::: check
given: e = 0.02 | 0.05 | 0.1 | 0.2
answer: 20*log(abs(sinc(1 - e)))
unit: dB
tolerance: 0.5%

## An OFDM receiver's frequency is {e} of a subcarrier spacing off. How strongly, relative to a full subcarrier, does each neighbor leak in?

::: right
Right. $20\log_{10}|\operatorname{sinc}(1 - \varepsilon)|$ = {answer} dB.
:::

::: misses
- [20*log(abs(sinc(e)))] That's the loss of the subcarrier's own signal.
- [any] Not yet. The neighbor's sinc, evaluated ε away from its zero.
:::
:::

::: check
kind: parts
given: fs = 9600 | 20000 | 48000; N = 64 | 256 | 1024; g = 16 | 64

## An OFDM modem samples at {fs} Hz with {N} subcarriers and a {g}-sample cyclic prefix.

::: part
answer: fs/N
unit: Hz
tolerance: 0.5%

### What is the subcarrier spacing?

::: misses
- [any] $f_s/N$.
:::
:::

::: part
answer: (N + g)/fs*1000
unit: ms
tolerance: 0.5%

### How long is each symbol, with its prefix?

::: misses
- [N/fs*1000] Add the prefix.
- [any] $(N + g)/f_s$.
:::
:::

::: part
answer: g/(N + g)*100
unit: %
tolerance: 0.5%

### What share of the time is the prefix?

::: misses
- [any] g ÷ (N + g).
:::
:::
:::

::: check
kind: parts
given: N = 64 | 256 | 1024

## OFDM uses {N} subcarriers of equal power.

::: part
answer: 10*log(N)
unit: dB
tolerance: 0.5%

### What is the worst-case peak-to-average power ratio?

::: misses
- [any] All in phase: N times the average.
:::
:::

::: part
answer: N
tolerance: 0.5%

### As a ratio?

::: misses
- [any] N.
:::
:::
:::

::: explain
## Why does a cyclic prefix let OFDM undo echoes with just one division per subcarrier?

::: model
An echo is a delayed copy of the signal, so without a prefix the start of each FFT window would contain the tail of the previous symbol's echo, mixing symbols together. With a prefix that's at least as long as the echo, that spillover falls entirely within the prefix, which the receiver throws away. Because the prefix is a copy of the symbol's own end, what remains in the window looks like the symbol shifted around circularly, and a circular shift of a whole number of cycles only changes each subcarrier's phase. Adding the direct path and its echoes therefore multiplies each subcarrier by a single complex number, the channel's frequency response at that subcarrier, and dividing by it restores the data.
:::
:::

::: practice

::: check
given: s = 1 | 2 | 50; N = 128 | 4096
answer: s*1000/N
unit: kHz
tolerance: 0.5%

## Subcarrier spacing: {s} MHz, {N}-point FFT?

::: misses
- [any] $f_s/N$.
:::
:::

::: check
given: N = 128 | 512 | 4096; c = 9 | 32 | 512
answer: 100*c/(N + c)
tolerance: 0.5%

## Prefix overhead: {N} plus {c}?

::: misses
- [any] $N_{cp}/(N + N_{cp})$.
:::
:::
:::
