Matched Filter Simulator — Pulse Detection in Noise
Visualize a matched filter pulling a known rectangular pulse out of white noise. Tune amplitude, pulse length and noise to see the output SNR jump by the pulse length L (processing gain).
Parameters
Signal amplitude A
—
Pulse length L
samples
Noise std. deviation σ
—
Random seed
—
The noise is generated by a deterministic LCG, so the same seed always reproduces the same waveform.
Convolving the received signal r[n] = s[n] + n[n] with the time-reversed copy of the known signal h[n] = s[L−1−n] makes the output peak at the arrival position. That is the matched filter.
Longer pulses yield a larger gain and allow detection at lower input SNR. This is the basis of radar pulse compression and matched reception in communications.
What is the Matched Filter Simulator
🙋
Radar textbooks talk about a "matched filter" all the time. Is it basically a tool that digs a signal out of a sea of noise?
🎓
Almost exactly that. Roughly: if you already know the shape of the waveform you are looking for, you can use it as a ruler — correlate it with the received signal and the strongest response shows you where the signal is. The recipe is to set the filter coefficients to $h[n] = s[L-1-n]$ (the time-reversed known signal) and convolve with the received $r[n]$. The output peaks at the arrival time. In the simulator above, compare the "received signal" with the "output y[n]". The raw received signal hides the pulse, but in the output the red line jumps up sharply near the middle.
🙋
It really does. Does it still work when SNR is much worse — when the noise is bigger?
🎓
That is exactly the magic. Push the noise sigma up to 3 or 4. The received signal is buried completely; you cannot see the pulse anymore. But the output still has a clean peak. The reason is that the output SNR improves by a factor of L — the pulse length — over the input SNR. At the default L = 20 that is a 13 dB improvement. At L = 100 it would be 20 dB.
🙋
So a longer pulse means more gain — can I just keep stretching it forever to detect anything?
🎓
In theory, yes; in practice, no. A long pulse hurts range resolution (in radar, you stop being able to tell where the target is exactly). Real systems use chirp signals (LFM) so that "long" and "high-resolution" can both be true — that is "pulse compression". The simulator uses a rectangular pulse, but the principle is identical: correlate with the known waveform and you get a gain equal to the pulse length.
🙋
When I move the "random seed" slider the peak value keeps shifting around. It never lands exactly on the theoretical 20…
🎓
Good catch. The theoretical peak $E_s = A^2 L$ assumes only the signal is there. In reality the noise term also lands on the peak position, with a standard deviation on the order of $\sigma\sqrt{L}\cdot A$. With L=20, A=1, sigma=1 that is about ±4.5. So the observed peak fluctuates roughly between 15 and 25 around 20. Changing the seed reveals different noise realizations — that variability is the basis of detection theory.
Frequently Asked Questions
No. The simple form $h[n] = s[L-1-n]$ is optimal only when the noise is white (flat spectrum). Against colored noise (with a non-flat spectrum) the optimum is the "whitening matched filter", which first whitens the received signal with the inverse of the noise spectrum $S_n(f)$ and then matches. In practice you estimate the noise spectrum and apply an inverse filter, or shape the matched filter to emphasize frequency bands with less noise.
The correlation $R_{sr}[\tau] = \sum_n s[n]\,r[n+\tau]$ and the convolution $y[\tau] = \sum_n h[n]\,r[\tau-n]$ are mathematically equivalent if you set $h[n] = s[L-1-n]$. Textbooks call the system a "correlator", but in implementations it is more common to flip the coefficients and use a convolution. The simulator builds the filter that way too. Physically you can read it as "compute the overlap between the known waveform and the received signal at every shift".
Yes. Every digital communications receiver uses a filter matched to the transmitted symbol pulse (such as a root-raised-cosine). The transmitter's root-RRC combined with the receiver's root-RRC gives an overall raised-cosine response that satisfies the Nyquist condition (zero inter-symbol interference) and simultaneously maximizes the SNR per symbol. Over an AWGN channel this is the BER-minimum optimal receiver.
Mainly two things. First, time resolution: a longer pulse increases the gain but also broadens the output peak, making nearby targets harder to separate. Radars solve this with pulse compression (LFM, phase codes) to get "long and sharp" outputs. Second, robustness: a matched filter is hard-wired to a specific $s[n]$, so any mismatch (Doppler shift, code error) quickly reduces the gain. Real systems are designed with these mismatches in mind.
Real-World Applications
Radar pulse compression: Radar is the matched filter's main stage. The transmitted pulse is encoded with an LFM (linear frequency modulation, chirp) or a phase code (Barker code), and the receiver correlates with that waveform to get the energy of a long pulse (range) together with the resolution of a short one. Weather radars, air traffic control, defense, satellite SAR — almost every modern radar runs on this principle.
Matched reception in digital communications: From 4G/5G OFDM to satellite links, Wi-Fi and Bluetooth, every receiver contains a filter matched to the transmitted symbol pulse. It is the BER-minimum optimum receiver over an AWGN channel — the implementation closest to the Shannon limit — and works as part of the baseband demodulator chain.
Sonar and seismic exploration: Submarine active sonar, multibeam bathymetry and seismic refraction surveys all standardize on correlating the received signal with a known transmitted waveform. In low-SNR environments (water and ground), long range and high resolution cannot coexist without pulse compression. Vibroseis (vibrating truck) surveys correlate with continuous sweep waveforms as a matter of course.
Gravitational-wave detection (LIGO): The first direct detection of gravitational waves in 2015 (GW150914) also used matched filtering against a library of black-hole binary merger templates. Millions of templates are run in parallel and the largest correlation is declared a detection. Digging an extremely faint signal out of overwhelming noise — that is the principle taken to its limit.
Common Misconceptions and Cautions
The most common misconception is to think that "the matched filter amplifies the signal itself". In reality the signal energy is merely concentrated in time: $E_s = A^2 L$ of energy appears as a peak value of $A^2 L$ with a width of roughly one sample, but no extra energy is created. Changing the pulse length L in the simulator shows the output peak growing in direct proportion to L. "Signal concentrates in time, noise does not" — that is the real source of the SNR improvement.
The next common error is to assume that "doubling the pulse length doubles the gain (3 dB more SNR)". The matched filter alone does give G = L (so +3 dB for doubling), but real radars and communications systems usually operate under an "average power constraint". If you stretch a pulse at fixed average power the amplitude A drops, and $E_s = A^2 L$ does not scale linearly with L. The simulator lets you change A and L independently, which is useful for disentangling these two roles.
Finally, watch out for the expectation that the observed peak should hit the theoretical value exactly. The theoretical peak $E_s = A^2 L$ neglects noise; in reality a term $\sum h[k] n[\text{peak}-k]$ with zero mean and standard deviation about $\sigma\sqrt{L}\cdot A$ is added at the peak position. At the defaults (A=1, L=20, sigma=1) this gives about ±4.5 of spread around the theoretical 20. Move the "random seed" slider in the simulator and the peak value fluctuates — detection is a random variable, not a deterministic one. Real systems use this variance to set a detection threshold and compute the "false alarm" and "detection" probabilities.