# Demo — Spread-Spectrum Playground

Spread spectrum is how a link survives a jammer that is far stronger than the signal. Spreading the bits across a wide band and despreading at the receiver gathers the wanted signal into a spike while smearing the jammer thin. This demo lets you set the processing gain and the jamming, then watch the despread do its work.

## Processing gain

$$
G_p = 10\log_{10}(\text{chips per bit}) \ \text{dB}.
$$

After despreading, the effective jam-to-signal ratio is reduced by $G_p$: the link closes when $\text{J/S} - G_p$ falls below what the modulation can tolerate.

## Interactive demo

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

<div class="demo-wrap">
<iframe src="../_static/demos/SpreadSpectrumPlayground.html"
        title="Interactive spread-spectrum processing-gain demo"
        width="100%"
        loading="lazy">
</iframe>
</div>

## Walkthrough

1. **Start narrowband.** With little processing gain, raise J/S above 0 dB and the link dies — a conventional link has no defense against a stronger jammer.
2. **Add chips.** Increase the DSSS chips per bit and watch $G_p$ climb in dB. The post-despread J/S drops below the threshold and the link recovers.
3. **Read the two spectra.** Before despread, the jammer towers over the spread signal; after despread, the signal collapses to a tall baseband spike while the jammer is spread into a low floor.
4. **Toggle FHSS.** Switch to frequency hopping and vary the hop count — the same $10\log_{10}$ gain law, achieved by dodging in time rather than spreading in code.

## Key observations

- **Processing gain is the whole game.** Survival is a contest between $G_p$ and the J/S deficit.
- **Encryption is not jam resistance.** Encryption hides the *content*; only spreading defeats the *power*.
- **L15's frequency agility was the radar-side preview** of the same idea — spread or hop to deny the jammer a fixed target.

## Source

<a class="matlab-link" href="../_static/downloads/ECE%20495%20EW%20%E2%80%93%20Code.zip#code/L16_DSSSProcessingGain.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/L16_DSSSProcessingGain.m</span><span class="ml-arrow">↓</span></a>

The in-class script spreads a bit stream, adds a jammer at a chosen J/S, despreads, and shows the spectrum before and after along with the resulting bit-error performance.
