C9 · Lesson 11 · Correlation and matched filtering
Finding a known pattern, and how late it arrived
A radar sends a pulse and listens for its echo, buried in noise and delayed by the trip to the target and back. A GPS receiver finds the code of each satellite and measures its delay to a few nanoseconds. A phone's two microphones find which way a voice comes from. All three slide a known pattern along a received signal and ask, at each shift, how well the two match. That operation, correlation, is convolution with one signal reversed, and the best possible detector of a known pulse in noise is built from it.
- The stems are a 7-sample pattern, a Barker code: + + + − − + −. The second set is the same pattern shifted by L samples.
- The readout multiplies the two sample by sample and adds: the correlation at lag L.
- Slide L. At L = 0 every product is +1 and the sum is 7. At every other lag the sum is 0 or −1: the pattern matches itself only when it's lined up.
Predict
A pulse of 7 samples, each +1, is correlated with itself. What is the largest correlation at any lag other than 0?
- Shifted by one sample, six of the seven samples still overlap, and all of them agree. A plain pulse's correlation falls off slowly, as a triangle, so its peak is hard to pin down in noise. The Barker code above has the same energy, but its correlation is never more than 1 away from 0 except at the true lag. Codes like it are how radars get sharp range readings from long pulses.
Name it
Correlation
The cross-correlation of x and y measures their match at each lag k:
It's a convolution with y reversed: . The autocorrelation is a signal correlated with itself. Its value at lag 0 is the signal's energy, and no other lag is larger:
Dividing by gives the correlation coefficient, between −1 and 1.
Finding a delay
If y is a copy of x delayed by D samples (plus noise), peaks at k = D. At a sample rate that's a time delay . Two microphones a distance d apart hear a source at angle θ from broadside with a delay .
The matched filter
To detect a known pulse s[n] in white noise of variance per sample, filter with its reversed copy, . The output at the end of the pulse is the pulse's energy E, while the noise there has variance . So the peak signal-to-noise ratio is
and no other linear filter does better. For N samples of amplitude A, E = NA², a gain of N over the per-sample SNR: dB. A longer pulse gives more energy at the same peak power, which is why radars and GPS use long coded pulses.
Worked example
Find the autocorrelation of x = [1, 2, 3].
Show the solution
- Lag 0. This is the energy:
- Lag ±1.
- Lag ±2.
- Collect. So r = [3, 8, 14, 8, 3] for lags −2 to 2: symmetric, as every autocorrelation is, and largest at 0.
Answer r = [3, 8, 14, 8, 3] for lags −2 to 2.
Worked example
Two microphones 0.5 m apart, sampling at 48 kHz, see a correlation peak at a lag of 20 samples. From what angle does the sound come?
Show the solution
- Delay.
- Path difference.
- Angle. measured from broadside.
- Resolution. One sample of lag is 0.71 cm of path, so the angle can be read to about a degree near broadside, which is why such arrays interpolate the peak between samples.
Answer the sound comes from 16.6° off broadside.
Worked example
A radar pulse is a 13-chip Barker code of amplitude 1, in noise of standard deviation 1 per sample. What does the matched filter do for the signal-to-noise ratio?
Show the solution
- SNR per sample. Per sample the SNR is 1, 0 dB, so a single sample tells almost nothing.
- Matched-filter peak. The pulse's energy is 13, so the matched filter's peak SNR is 13, a gain of 13:
- Side lobes. The code's correlation side lobes are at most 1, against a peak of 13: so a large target's side lobes don't hide a small one nearby.
Answer the matched filter raises the SNR from 1 (0 dB) per sample to 13 (11.1 dB) at its peak, a gain of 13, with side lobes 22.3 dB down.
Check
Find the autocorrelation of x = [2, 3, 4].
(a)
What is it at lag 0?
(b)
And at lag 1?
Check
Microphones 0.5 m apart, sampling at 16 kHz, see a correlation peak at 4 samples. Sound travels 343 m/s.
(a)
What is the delay?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
From what angle off broadside does the sound come?
Check
A known pulse of 13 samples arrives with a per-sample SNR of −10 dB.
(a)
What gain does the matched filter give?
(b)
What is the peak SNR at its output?
Check
Signals with energies = E and = F have correlation coefficient c at some lag.
Step 1
What is the correlation there?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
What is the largest it could possibly be?
Check
How is the cross-correlation related to convolution?
Check
A Barker code of length 11 has a correlation peak of 11 and side lobes no larger than 1.
(a)
How far below the peak are the side lobes?
(b)
For a plain pulse of 11 ones, how far below the peak is the correlation at lag 1?
Check
Write find_delay(x, y): the lag k (0 ≤ k < len(y)) at which y best matches x shifted, that is, where is largest.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why does a long coded pulse let a radar see small targets without a high peak power?
What decides whether a pulse can be detected in noise is its energy, not its peak power: the matched filter's output SNR is the pulse energy divided by the noise level. A long pulse delivers a lot of energy at a modest peak power, which transmitters handle easily. The catch is range resolution: a plain long pulse correlates with itself over its whole length, so the echo's peak is broad and two nearby targets blur together. A code such as a Barker sequence fixes that, because its autocorrelation is sharp: the full energy at the right lag and almost nothing elsewhere. The matched filter compresses the long pulse into a short peak, giving the energy of a long pulse with the resolution of a short one.
Practice
Keep practicing
7 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.