---
title: "An FSK receiver: correlators and filter banks"
heading: Deciding which tone each bit holds by correlating the samples with each tone, why taking the magnitude makes the receiver ignore the unknown phase, the correlator as a filter whose response falls to nulls a bit rate apart, how much one tone leaks into the other's detector, and the error rate in noise
eyebrow: D12 · Lesson 4 · An FSK receiver
xp: 40
---

::: hook
To decide whether a bit was sent as the 1200 Hz tone or the 2200 Hz one, the receiver asks of each bit's 8 samples: how much do they look like 1200 Hz, and how much like 2200 Hz? Multiplying the samples by a probe tone and adding them up, a **correlation**, answers exactly that, and it's the same arithmetic as one bin of a DFT (D5). Using a complex probe and taking the magnitude makes the answer independent of the tone's phase, which the receiver doesn't know. Two such correlators, one per tone, make a complete noncoherent FSK detector.
:::

::: play
- The response of each correlator over one bit (8 samples) to a tone of frequency f, normalized to 1 at its own frequency: a Dirichlet shape (D5), $\left|\sin(8\pi\Delta/f_s)/(8\sin(\pi\Delta/f_s))\right|^2$ with Δ the offset.
- Each correlator responds strongly to its own tone and weakly to the other: the 1200 Hz correlator sees a 2200 Hz tone at −14.2 dB. The detector picks whichever correlator responds more.
- Nulls fall every 1200 Hz from each center: a bit time's correlator is a filter whose width is set by the bit rate.
:::

```sim plot
view: graph
x: f = 0..4000
y: E = 0..1.05
slider: g = 500..3500 step 50 = 2200
plot: (sin(8*pi*(f - 1200)/9600)/(8*sin(pi*(f - 1200)/9600 + 1e-12)))^2 | samples: 800 | label: 1200 Hz correlator (f in Hz)
plot: (sin(8*pi*(f - 2200)/9600)/(8*sin(pi*(f - 2200)/9600 + 1e-12)))^2 | samples: 800 | color: ch3 | label: 2200 Hz correlator
marker: x = g | label: incoming tone
readout: 1200 Hz correlator, dB = 10*log((sin(8*pi*(g - 1200)/9600)/(8*sin(pi*(g - 1200)/9600 + 1e-12)))^2 + 1e-12) | digits: 3
readout: 2200 Hz correlator, dB = 10*log((sin(8*pi*(g - 2200)/9600)/(8*sin(pi*(g - 2200)/9600 + 1e-12)))^2 + 1e-12) | digits: 3
```

::: predict
## A unit-amplitude 1200 Hz cosine fills one 8-sample bit. What does its correlation with a complex 1200 Hz probe come to, in magnitude squared?

- [ ] 1
- [ ] 8
- [x] 16
- [ ] 64

::: reveal
A cosine is half a positive-frequency exponential and half a negative one. Against the matching complex probe the positive half adds up to 8 × ½ = 4, and the negative half cancels over the whole cycle, so the magnitude is 4 and its square 16, whatever the cosine's phase. The other correlator gets only 16 × 0.038, the −14 dB leakage.
:::
:::

::: nameit
## Correlation detection

For each bit's samples $x[n]$, n = 0 to N − 1, compute

$$E_f = \left|\sum_n x[n]e^{-j2\pi fn/f_s}\right|^2$$

for f = mark and f = space, and decide 1 if $E_\text{mark} > E_\text{space}$. The magnitude discards the phase, so this **noncoherent** detector needs no carrier recovery. Each $E_f$ is one DFT-like bin, so a bank of them is a **filter bank**.

## The correlator as a filter

Summing N samples against a probe has the frequency response of a length-N moving average shifted to f: a main lobe with nulls at $\pm f_s/N$ = ±(bit rate) and sidelobes beyond. Tones exactly a bit rate apart fall on each other's nulls: they're **orthogonal** over a bit. The 1200 and 2200 Hz tones are 1000 Hz apart, so each leaks into the other's correlator at −14.2 dB, costing some noise margin.

## Errors

Noise adds random vectors to both correlations, and an error happens when the wrong one wins. For orthogonal tones the error rate is $\frac{1}{2}e^{-E_b/2N_0}$ (D4); the leakage here makes it somewhat worse.
:::

::: example
## How strongly does a 2200 Hz tone register in the 1200 Hz correlator over one bit?

::: solution
1. **Leakage amplitude.** The tones are $\Delta$ = 1000 Hz apart:
   $$\begin{aligned} A &= \frac{\sin(8\pi \times 1000/9600)}{8\sin(\pi \times 1000/9600)} \\ &= \frac{0.5}{2.572} \\ &= 0.194 \end{aligned}$$
2. **Power and decibels.**
   $$\begin{aligned} A^2 &= 0.0378 \\ 10\log_{10}A^2 &= -14.2\ \text{dB} \end{aligned}$$
3. **A tone 1200 Hz away.** It would give exactly zero.

**Answer:** the 2200 Hz tone registers at 0.194 of full amplitude, 0.0378 in power, or −14.2 dB.
:::
:::

::: example
## What tone spacing makes the two correlators completely blind to each other's tone over one 1200 baud bit?

::: solution
1. **When tones are orthogonal.** Over a bit of length T, tones whose frequencies differ by a multiple of 1/T are orthogonal: each correlator sees exactly zero of the other.
2. **At 1200 baud.**
   $$\frac{1}{T} = 1200\ \text{Hz}$$
3. **Bell 202.** Its 1000 Hz spacing isn't quite a multiple, which is the 0.194 leakage found above.

**Answer:** a spacing of 1200 Hz, or any multiple of it.
:::
:::

::: example
## What bit error rate does noncoherent FSK reach at $E_b/N_0$ = 12 dB?

::: solution
1. **Convert 12 dB to a ratio.**
   $$\begin{aligned} \frac{E_b}{N_0} &= 10^{12/10} \\ &= 15.85 \end{aligned}$$
2. **Bit error rate.**
   $$\begin{aligned} P_b &= \tfrac12 e^{-E_b/2N_0} \\ &= 0.5\,e^{-15.85/2} \\ &= 1.8 \times 10^{-4} \end{aligned}$$
   That's about one error in 5500 bits.
3. **Compare with BPSK.** Coherent BPSK would need about 4 dB less for the same rate; FSK's simplicity costs signal.

**Answer:** about $1.8 \times 10^{-4}$, one error in 5500 bits.
:::
:::

::: check
kind: python

## Write a noncoherent FSK demodulator.

```python starter
import numpy as np

FS, BAUD, F_MARK, F_SPACE = 9600, 1200, 1200.0, 2200.0
SPS = FS//BAUD

def fsk_modulate(bits):
    # From lesson 3.
    freqs = np.repeat([F_MARK if b else F_SPACE for b in bits], SPS)
    phase = np.concatenate(([0.0], np.cumsum(2*np.pi*freqs/FS)[:-1]))
    return np.cos(phase)

def tone_energy(block, f):
    # |sum over n of block[n]*exp(-2j*pi*f*n/FS)|^2: how much of frequency f the block holds,
    # whatever its phase.
    return 0.0

def fsk_demod(x):
    # Cut x into bits of SPS samples and decide each one: 1 if the block holds more mark-tone
    # energy than space-tone energy, else 0. Return a list of bits.
    return []
```

```python solution
import numpy as np

FS, BAUD, F_MARK, F_SPACE = 9600, 1200, 1200.0, 2200.0
SPS = FS//BAUD

def fsk_modulate(bits):
    # From lesson 3.
    freqs = np.repeat([F_MARK if b else F_SPACE for b in bits], SPS)
    phase = np.concatenate(([0.0], np.cumsum(2*np.pi*freqs/FS)[:-1]))
    return np.cos(phase)

def tone_energy(block, f):
    n = np.arange(len(block))
    return abs(np.sum(block*np.exp(-2j*np.pi*f*n/FS)))**2

def fsk_demod(x):
    out = []
    for i in range(0, len(x) - SPS + 1, SPS):
        b = x[i:i + SPS]
        out.append(1 if tone_energy(b, F_MARK) > tone_energy(b, F_SPACE) else 0)
    return out
```

```python tests
_n = np.arange(SPS)
assert abs(tone_energy(np.cos(2*np.pi*1200*_n/FS), 1200) - 16) < 1e-9, "A unit cosine at 1200 Hz over 8 samples correlates to |8/2|^2 = 16 with the 1200 Hz probe."
_rng = np.random.default_rng(7)
_bits = list(_rng.integers(0, 2, 200))
assert fsk_demod(fsk_modulate(_bits)) == _bits, "Without noise, every bit should come back."
_big = list(_rng.integers(0, 2, 4000))
_y = fsk_modulate(_big) + 0.5*_rng.standard_normal(len(_big)*SPS)
_ber = np.mean(np.array(fsk_demod(_y)) != np.array(_big))
assert 0.002 < _ber < 0.03, f"With noise of standard deviation 0.5 per sample, a few bits in a hundred or fewer should flip; measured {_ber:.4f}."
```

::: right
Right. Your demodulator recovers every bit without noise and keeps the error rate low with it.
:::
:::

::: check
given: N = 8 | 16 | 32; s = 9600 | 48000
answer: s/N
unit: Hz
tolerance: 0.5%

## A correlator sums {N} samples taken at {s} Hz. How far from its center frequency is its first null?

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

::: misses
- [s/(2*N)] The null is a full bin away: $f_s/N$.
- [any] Not yet. One cycle more or less over the N samples.
:::
:::

::: check
given: d = 500 | 1000 | 1500; N = 8 | 16
answer: 10*log((sin(N*pi*d/9600)/(N*sin(pi*d/9600)))^2)
unit: dB
tolerance: 1%

## A correlator sums {N} samples at 9600 Hz. What's its response to a tone {d} Hz off center, in dB relative to its peak?

::: right
Right. $10\log_{10}|\sin(N\pi\Delta/f_s)/(N\sin(\pi\Delta/f_s))|^2$ = {answer} dB.
:::

::: misses
- [any] Not yet. The Dirichlet response.
:::
:::

::: check
given: A = 0.5 | 1 | 2; N = 8 | 16 | 32
answer: (A*N/2)^2
tolerance: 0.5%

## A cosine of amplitude {A} fills {N} samples exactly at a correlator's frequency (a whole number of cycles). What's the correlation's magnitude squared?

::: right
Right. $(AN/2)^2$ = {answer}.
:::

::: misses
- [(A*N)^2] Only half of the cosine, its positive-frequency part, matches the complex probe.
- [any] Not yet. Half the amplitude, N times.
:::
:::

::: check
kind: parts
given: E = 8 | 10 | 12 | 14

## A noncoherent FSK link runs at $E_b/N_0$ = {E} dB.

::: part
answer: 0.5*exp(-10^(E/10)/2)
tolerance: 1%

### What is its bit error rate?

::: misses
- [any] $\tfrac12 e^{-E_b/2N_0}$.
:::
:::

::: part
answer: 1/(0.5*exp(-10^(E/10)/2))
tolerance: 1%

### About how many bits between errors?

::: misses
- [any] The reciprocal.
:::
:::
:::

::: check
kind: parts
given: R = 300 | 1200 | 2400; k = 1 | 2

## Orthogonal noncoherent FSK runs at {R} baud.

::: part
answer: k*R
unit: Hz
tolerance: 0.5%

### What tone spacing, {k} times the minimum, keeps the tones orthogonal over a bit?

::: misses
- [any] Multiples of 1/T = R.
:::
:::

::: part
answer: k*R + 2*R
unit: Hz
tolerance: 0.5%

### About what bandwidth does that take?

::: misses
- [any] Spacing + 2R.
:::
:::
:::

::: explain
## Why does a noncoherent FSK receiver take the magnitude of each correlation?

::: model
The receiver doesn't know the phase of the incoming tone: it depends on the transmitter's oscillator, the path delay and everything that came before. Correlating with only a cosine probe would give a large result when the phases line up and nearly nothing when they're a quarter cycle apart, so the decision would depend on an accident of timing. Correlating with a complex exponential, effectively a cosine and a sine probe together, captures the tone's energy at any phase, and the magnitude combines the two parts into a number that depends only on how much of that frequency is present. That lets the receiver compare the two tones fairly without first recovering the carrier's phase.
:::
:::

::: practice

::: check
given: N = 4 | 8 | 16 | 32 | 64; s = 8000 | 96000
answer: s/N
unit: Hz
tolerance: 0.5%

## First null: {N} samples at {s} Hz?

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

::: check
given: A = 0.1 | 5; N = 4 | 8 | 16 | 64
answer: (A*N/2)^2
tolerance: 0.5%

## |correlation|² for amplitude {A} over {N} samples?

::: misses
- [any] $(AN/2)^2$.
:::
:::
:::
