# Demo — ROC Explorer

This demo turns detection theory into a picture. The top plot is the receiver operating characteristic — $P_d$ against $P_{fa}$ — and it climbs toward the perfect-detector corner as SNR rises. The bottom panel shows *why*: two overlapping distributions, noise-only and signal-plus-noise, with a movable threshold whose tails are exactly $P_{fa}$ and $P_d$.

## The idea

Detection is a thresholded comparison of a decision statistic against noise. Raising the threshold lowers both $P_{fa}$ (the noise tail) and $P_d$ (the signal tail) — you cannot separate them without more SNR. Integration buys SNR: coherently at $+10\log_{10}N$ dB, non-coherently at about $+5\log_{10}N$ dB.

## Interactive demo

<a class="demo-fullscreen" href="../_static/demos/ROCExplorer.html" target="_blank" rel="noopener">Open in full screen</a>

<div class="demo-wrap">
<iframe src="../_static/demos/ROCExplorer.html"
        title="Interactive ROC explorer"
        width="100%"
        loading="lazy">
</iframe>
</div>

## Walkthrough

1. **Default settings** (SNR = 13 dB, N = 1). Slide the **threshold** and watch the operating point trace the ROC curve while the two PDF tails — $P_{fa}$ in blue, $P_d$ in red — grow and shrink.
2. **Drop SNR to 6 dB.** The two distributions overlap more, the ROC sags away from the corner, and $P_d$ collapses at the same $P_{fa}$. Detection is an SNR business.
3. **Integrate.** Set N = 64 and leave it **non-coherent**: the curve climbs back toward the corner ($+5\log_{10}64 \approx 9$ dB). Now switch to **coherent** and watch it climb further ($+10\log_{10}64 \approx 18$ dB).
4. **Find the rule of thumb.** Return to N = 1 and set the threshold for $P_{fa} = 10^{-6}$. The SNR that reaches $P_d \approx 0.9$ there is about **13 dB** — the steady-target operating point from the reading.

## Key observations

- **Higher SNR pushes the ROC to the top-left.** The whole game is separating the signal distribution from the noise distribution.
- **The threshold trades $P_d$ against $P_{fa}$** — moving it slides the operating point along a fixed-SNR curve; it cannot move you to a better curve.
- **Integration moves you to a better curve.** Coherent integration is twice as efficient in dB as non-coherent, which is why AESAs work hard to stay phase-coherent across the dwell.

## Source

<a class="matlab-link" href="../_static/downloads/ECE%20495%20EW%20%E2%80%93%20Code.zip#code/L8_PdPfaAndROC.m" download><svg viewBox="0 0 22 22" width="14" height="14" aria-hidden="true" style="vertical-align:-2px;margin-right:6px;"><rect width="22" height="22" rx="3" fill="#e87722"/><text x="11" y="15.5" text-anchor="middle" font-family="'Inter',sans-serif" font-size="9" font-weight="800" fill="#fff" letter-spacing="-0.04em">MAT</text></svg><span class="ml-text">MATLAB · code/L8_PdPfaAndROC.m</span><span class="ml-arrow">↓</span></a>

The in-class script generates Gaussian noise and a steady target return, sweeps the threshold to measure $P_d$ and $P_{fa}$ by Monte Carlo, plots ROC curves for SNR = 0, 6, and 13 dB, and applies non-coherent integration of 16 pulses to watch the curve shift. This page uses the equivalent analytical Gaussian-separation model so the curve updates instantly.
