S8 · Lesson 24 · Detection lab
Monte Carlo bit and symbol error rates for BPSK, 16-QAM and 8-PSK against their formulas, the MAP threshold for unequal priors, and how many bits a measurement needs
Every error-rate formula in lessons 12 to 20 rests on assumptions: Gaussian noise, perfect timing, a known channel, the right threshold. A simulation checks them all at once. You generate random symbols, add noise of exactly the right variance, decide, and count mistakes; if the count lands on the formula, the formula and the simulation agree about every scale factor. In this lab you'll build the simulations engineers use to check receivers, and learn how many bits it takes before a simulated error rate means anything.
- The curves are BPSK's bit error probability on an AWGN channel, , and on a Rayleigh-fading channel, .
- Measuring a rate of p to ±10% takes about 100 errors, so about 100/p bits: a million for 10⁻⁴, a hundred million for 10⁻⁶.
- That cost is why simulations stop around 10⁻⁶ and why low error rates are extrapolated from formulas or measured with special techniques.
Predict
A simulation of a link whose true bit error rate is 10⁻⁵ should report that rate within about ±10%. How many bits must it send?
Errors arrive almost as a Poisson process, so k counted errors have a standard deviation of about : a relative error of . ±10% needs about 100 errors, and at 10⁻⁵ that takes 10⁷ bits. Halving the uncertainty takes four times as many.
Name it
What the lab computes
- Noise scaling. For symbols of average energy carrying bits, , and each real noise dimension has variance . With unit-energy BPSK, .
- Square QAM. With levels ±1 and ±3 per axis (average = 10), each axis errs with , and the symbol error rate is .
- M-PSK. At high SNR, .
- MAP threshold. For ±A with prior on +A and noise σ, the threshold that minimizes errors is , with error probability .
- Confidence. n trials with true rate p give an estimate with standard deviation ; a relative uncertainty r needs .
Check
Write ber_bpsk(EbN0_db, n, seed): send n random bits as ±1 through AWGN at the given Eb/N0, decide by sign, and return the fraction of errors. Use random.Random(seed).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write ser_qam16(EbN0_db, n, seed): send n random 16-QAM symbols with levels ±1, ±3 per axis (Es = 10), add complex AWGN at the given Eb/N0, decide each axis by the nearest level, and return the symbol error rate.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write map_threshold(A, sigma, p1) and error_prob(A, sigma, p1, t) for antipodal ±A with prior p1 on +A, noise σ and threshold t.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write ser_mpsk(M, EsN0_db, n, seed): simulate n M-PSK symbols on the unit circle in complex AWGN at the given Es/N0, decide by the nearest phase, and return the symbol error rate; and bits_needed(p, rel): how many trials measure a rate p with relative standard deviation rel.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why is a simulated error rate that matches its formula good evidence that a receiver model is right, and what can such a match fail to reveal?
An error rate depends steeply on the signal-to-noise ratio, so a mistake in any scale factor, the symbol energy, the noise variance per dimension, the bits per symbol or a filter's gain, shifts the simulated curve by decibels and makes it miss the formula by a large factor. Matching across several SNRs therefore confirms that all those factors are consistent. What it can't reveal is anything the formula and the simulation share: if both assume perfect timing, a known channel or Gaussian noise, the agreement says nothing about how the real receiver behaves when those assumptions fail, so impairments have to be added to the simulation deliberately.