---
title: "The channel: noise, echoes and frequency offset"
heading: What happens to a signal between transmitter and receiver, additive noise and SNR, echoes from multipath and the notches they cut in the spectrum, delay spread against symbol time, frequency offset and Doppler, and measuring each of them from a known preamble
eyebrow: D12 · Lesson 10 · The channel
xp: 40
---

::: hook
Between the speaker and the microphone, the modem's sound picks up room noise, bounces off walls, desk and ceiling so that delayed copies pile onto the direct sound, and shifts slightly in frequency if either device moves. Radio channels do the same things at much higher frequencies. A receiver can only undo what it can measure, so practical links start every packet with a known preamble and use it to estimate the noise level, when the signal arrived, how it echoes and how far its frequency has moved.
:::

::: play
- The frequency response of a channel with a direct path and one echo of relative gain a, arriving τ milliseconds later: $|1 + a\,e^{-j2\pi f\tau}|$ in dB.
- The echo adds in phase at some frequencies and cancels at others, cutting notches spaced 1/τ apart. A 1 ms echo puts notches every 1000 Hz, right across the modem's band.
- As a approaches 1 the notches become deep holes where a tone simply vanishes. That's frequency-selective fading.
:::

```sim plot
view: graph
x: f = 0..4800
y: H = -30..10
slider: a = 0..0.95 step 0.05 = 0.6
slider: tau = 0.1..5 step 0.1 = 1
plot: 10*log(1 + 2*a*cos(2*pi*f*tau/1000) + a^2) | samples: 1200 | label: channel response, dB (f in Hz)
readout: notch spacing, Hz = 1000/tau | digits: 4
readout: notch depth, dB = 20*log(1 - a + 1e-9) | digits: 3
readout: peak, dB = 20*log(1 + a) | digits: 3
```

::: predict
## A wall behind the microphone sends back an echo that travels 3.4 m farther than the direct sound. How many 1200 baud symbols later does it arrive?

- [ ] Less than one
- [ ] About 2
- [x] About 12
- [ ] About 120

::: reveal
3.4 m/343 m/s = 9.9 ms, and a symbol lasts 0.83 ms, so the echo lands about 12 symbols late. Each received symbol is mixed with an echo of one sent 12 symbols earlier: intersymbol interference far longer than any pulse shaping can prevent. Sound is slow, so even a small room makes a harsh channel.
:::
:::

::: nameit
## Noise

**Additive** noise from the room, the microphone and its preamplifier sets the SNR, the ratio of mean signal power to mean noise power. For a known signal, subtract it and measure what's left.

## Multipath

Each path k adds a copy with gain $a_k$ and delay $\tau_k$:

$$y(t) = \sum_k a_kx(t - \tau_k), \qquad H(f) = \sum_k a_ke^{-j2\pi f\tau_k}$$

A two-path channel $1 + a e^{-j2\pi f\tau}$ has power gain $1 + 2a\cos(2\pi f\tau) + a^2$: peaks of $(1 + a)^2$, notches of $(1 - a)^2$, spaced 1/τ. The **delay spread** is how long the echoes last. If it's much shorter than a symbol, the channel just scales the signal (flat fading); if it's longer, as in rooms, symbols smear into each other and need an equalizer (lesson 11) or OFDM's cyclic prefix (lesson 13). A known preamble's arrival time is found by cross-correlation, which peaks where the received copy lines up with it.

## Frequency offset and Doppler

Mismatched clocks shift the carrier by (ppm × $f_c$). Motion shifts it by the **Doppler** factor $vf/c$ for a speed v along the path. With sound, c is only 343 m/s, so walking at 1 m/s moves an 1800 Hz tone by 5.2 Hz, far more than a radio sees at the same speed relative to its wavelength. The offset shows as a steady rotation of a known complex tone, so averaging the phase step between samples measures it. Comparing samples L apart turns the same rotation into an L times bigger angle, so noise matters L times less, but the angle wraps once the offset passes $f_s/2L$: a fine estimate over a small range.
:::

::: example
## A 1200 baud acoustic modem's echo arrives with half the direct path's amplitude, 1 ms late. Where are the notches in its band, and how deep?

::: solution
1. **Where the notches fall.** The echo cancels the direct path where
   $$2\pi f\tau = \pi, 3\pi, \ldots$$
   which puts the notches at 500, 1500, 2500 Hz and so on, 1000 Hz apart.
2. **Notch depth.**
   $$20\log_{10}(1 - 0.5) = -6.0\ \text{dB}$$
3. **Peaks between.**
   $$20\log_{10}1.5 = +3.5\ \text{dB}$$
4. **The mark tone at 1200 Hz.** It sits between a notch and a peak:
   $$\begin{aligned} G &= 10\log_{10}(1 + 0.25 \\ &\qquad + 2 \times 0.5 \times \cos 0.4\pi) \\ &= +1.9\ \text{dB} \end{aligned}$$

**Answer:** notches 6.0 dB deep at 500, 1500, 2500 Hz and so on, with peaks of +3.5 dB between; the mark tone gets +1.9 dB.
:::
:::

::: example
## A phone carried at 1 m/s receives the 1200 and 2200 Hz tones. How far do they shift?

::: solution
1. **Doppler shift.** A tone shifts by $vf/c$.
2. **The 1200 Hz tone.**
   $$\begin{aligned} \Delta f &= \frac{1 \times 1200}{343} \\ &= 3.5\ \text{Hz} \end{aligned}$$
3. **The 2200 Hz tone.**
   $$\begin{aligned} \Delta f &= \frac{1 \times 2200}{343} \\ &= 6.4\ \text{Hz} \end{aligned}$$
4. **Who notices.** A noncoherent FSK receiver doesn't care, since its correlators' main lobes are 1200 Hz wide (lesson 4), but a coherent receiver's PLL has to follow it.

**Answer:** 3.5 Hz for the 1200 Hz tone and 6.4 Hz for the 2200 Hz tone.
:::
:::

::: example
## What path difference makes an echo arrive 1 ms late in air, and how does a room's half-second reverberation compare with a 1200 baud symbol?

::: solution
1. **Path difference.** The distance sound covers in 1 ms:
   $$\begin{aligned} d &= 343 \times 0.001\ \text{m} \\ &= 34.3\ \text{cm} \end{aligned}$$
2. **Symbol length.** A symbol lasts 0.83 ms.
3. **Compare with the reverberation.** A reverberation of 0.5 s smears each symbol over hundreds of later ones, so acoustic modems must either equalize or use slow symbols with long guard times.

**Answer:** 34.3 cm of extra path, and the reverberation spans hundreds of 0.83 ms symbols.
:::
:::

::: check
kind: python

## Model a channel and measure it: noise, echoes, arrival time and frequency offset.

```python starter
import numpy as np

def add_noise(x, snr_db, rng):
    # Add Gaussian noise whose power is the signal's mean power divided by 10**(snr_db/10).
    return np.array(x, dtype=float)

def multipath(x, taps):
    # taps maps a delay in samples to a gain, e.g. {0: 1.0, 96: 0.5}: y[n] = sum of g*x[n - d].
    # The output has the same length as x.
    return np.array(x, dtype=float)

def find_delay(rx, ref):
    # The shift d (0 or more) at which rx[d:d + len(ref)] best matches ref: the largest
    # correlation sum(rx[d:d + len(ref)]*ref).
    return 0

def freq_offset(z, fs, lag=1):
    # z is a complex tone exp(j*2*pi*f*n/fs) plus noise. Estimate f in Hz from the average phase
    # step between samples lag apart: the angle of sum(z[lag:]*conj(z[:-lag])), times
    # fs/(2*pi*lag).
    return 0.0
```

```python solution
import numpy as np

def add_noise(x, snr_db, rng):
    x = np.asarray(x, dtype=float)
    p = np.mean(x**2)/10**(snr_db/10)
    return x + np.sqrt(p)*rng.standard_normal(len(x))

def multipath(x, taps):
    x = np.asarray(x, dtype=float)
    y = np.zeros(len(x))
    for d, g in taps.items():
        y[d:] += g*x[:len(x) - d]
    return y

def find_delay(rx, ref):
    n = len(ref)
    scores = [np.dot(rx[d:d + n], ref) for d in range(len(rx) - n + 1)]
    return int(np.argmax(scores))

def freq_offset(z, fs, lag=1):
    return np.angle(np.sum(z[lag:]*np.conj(z[:-lag])))*fs/(2*np.pi*lag)
```

```python tests
_rng = np.random.default_rng(10)
_x = np.sin(2*np.pi*1800*np.arange(96000)/9600)
_y = add_noise(_x, 10, _rng)
_snr = 10*np.log10(np.mean(_x**2)/np.mean((_y - _x)**2))
assert abs(_snr - 10) < 0.2, f"The noise should leave an SNR of 10 dB; measured {_snr:.2f} dB."
_imp = np.zeros(200); _imp[0] = 1
_h = multipath(_imp, {0: 1.0, 96: 0.5, 150: -0.25})
assert _h[0] == 1 and _h[96] == 0.5 and _h[150] == -0.25 and np.count_nonzero(_h) == 3, "An impulse through the channel shows its taps."
_pre = _rng.choice([-1.0, 1.0], 255)
_rx = np.r_[np.zeros(1234), _pre, np.zeros(500)]
_rx = add_noise(multipath(_rx, {0: 1.0, 40: 0.6}), 0, _rng)
assert find_delay(_rx, _pre) == 1234, f"The preamble starts at sample 1234, echo and noise notwithstanding; got {find_delay(_rx, _pre)}."
_n = np.arange(4800)
_z = np.exp(2j*np.pi*3.7*_n/9600 + 0.4j) + 0.3*(_rng.standard_normal(4800) + 1j*_rng.standard_normal(4800))
assert abs(freq_offset(_z, 9600, 100) - 3.7) < 0.2, f"The tone is 3.7 Hz; comparing samples 100 apart, estimated {freq_offset(_z, 9600, 100):.3f} Hz."
_t = np.exp(2j*np.pi*1000*_n/9600)
assert abs(freq_offset(_t, 9600) - 1000) < 1e-6, "Neighboring samples measure a 1000 Hz offset exactly."
assert abs(freq_offset(_t, 9600, 100) - 1000) > 10, "A 100-sample lag can't see 1000 Hz: the phase wraps beyond 9600/200 = 48 Hz."
```

::: right
Right. Your channel model adds noise at the asked SNR and echoes at their delays, your correlator finds a buried preamble, and a 100-sample lag pins down a 3.7 Hz offset.
:::
:::

::: check
given: d = 1 | 3.4 | 7.5 | 20; s = 8000 | 9600 | 48000
answer: d*s/343
tolerance: 0.5%

## An echo travels {d} m farther than the direct sound. How many samples later does it arrive at {s} samples per second?

::: right
Right. {d}/343 s × {s} = {answer} samples.
:::

::: misses
- [d*s/300000000] Sound travels at 343 m/s.
- [any] Not yet. Delay in seconds times the sample rate.
:::
:::

::: check
given: a = 0.3 | 0.5 | 0.7 | 0.9
answer: 20*log(1 - a)
unit: dB
tolerance: 0.5%

## An echo of relative amplitude {a} arrives with the direct signal. How deep are the notches it cuts?

::: right
Right. $20\log_{10}(1 - a)$ = {answer} dB.
:::

::: misses
- [10*log(1 - a)] Amplitudes cancel: use 20 log.
- [20*log(1 + a)] That's the peaks, where the two add.
- [any] Not yet. The direct path minus the echo.
:::
:::

::: check
given: v = 0.5 | 1 | 2 | 5; f = 1200 | 1800 | 2200
answer: v*f/343
unit: Hz
tolerance: 0.5%

## A microphone moves toward a speaker at {v} m/s. How far does a {f} Hz tone shift?

::: right
Right. $vf/c$ = {answer} Hz.
:::

::: misses
- [2*v*f/343] One way only: the radar's factor of 2 comes from its round trip.
- [any] Not yet. The Doppler shift with the speed of sound.
:::
:::

::: check
given: s = 9600 | 48000; L = 10 | 50 | 100
answer: s/(2*L)
unit: Hz
tolerance: 0.5%

## A receiver estimates frequency offset by comparing samples {L} apart at {s} samples per second. What's the largest offset it can measure without the phase wrapping?

::: right
Right. $f_s/2L$ = {answer} Hz.
:::

::: misses
- [s/L] The phase step must stay within ±π: half a turn per lag.
- [any] Not yet. Half a turn of phase over L samples.
:::
:::

::: check
kind: parts
given: a = 0.3 | 0.5 | 0.8; t = 0.5 | 1 | 2

## An echo of amplitude {a} arrives {t} ms after the direct sound.

::: part
answer: 1/(t/1000)
unit: Hz
tolerance: 0.5%

### How far apart are the notches?

::: misses
- [any] $1/\tau$.
:::
:::

::: part
answer: 20*log(1 - a)
unit: dB
tolerance: 0.5%

### How deep are they?

::: misses
- [any] $20\log_{10}(1 - a)$.
:::
:::

::: part
answer: 343*t/1000*100
unit: cm
tolerance: 0.5%

### What extra path length causes it?

::: misses
- [any] 343 m/s × delay.
:::
:::
:::

::: check
kind: parts
given: v = 0.5 | 1 | 2; f = 1200 | 2200 | 18000

## A phone moves at {v} m/s while receiving a {f} Hz tone.

::: part
answer: v*f/343
unit: Hz
tolerance: 0.5%

### How far does the tone shift?

::: misses
- [any] $vf/c$.
:::
:::

::: part
answer: v*f/343/f*1e6
unit: ppm
tolerance: 0.5%

### What fractional shift is that?

::: misses
- [any] v/c in ppm.
:::
:::
:::

::: explain
## Why do echoes that are much shorter than a symbol cause less trouble than echoes that are longer?

::: model
If every echo arrives within a small fraction of a symbol after the direct path, each received symbol is just a slightly smeared, rescaled copy of itself, so the receiver sees the same symbol with a different gain and phase and can correct that with a single multiplier. When the echoes are delayed by a symbol or more, each received symbol also contains delayed copies of earlier symbols carrying different data. That intersymbol interference can't be removed by one gain; the receiver needs an equalizer that knows the echo pattern, or a scheme like OFDM that makes its symbols much longer than the echoes and adds a guard interval to absorb them.
:::
:::

::: practice

::: check
given: t = 0.2 | 0.5 | 2 | 8
answer: 1000/t
unit: Hz
tolerance: 0.5%

## Notch spacing for an echo {t} ms late?

::: misses
- [any] $1/\tau$.
:::
:::

::: check
given: v = 0.2 | 10; f = 500 | 4000
answer: v*f/343
unit: Hz
tolerance: 0.5%

## Doppler: {v} m/s, {f} Hz tone, sound?

::: misses
- [any] $vf/c$.
:::
:::
:::
