Skip to content
Tutorials Center
My learning

Topics

Lesson 41 of 46 ยท Projects and Practice

Project: A Bit Error Rate Simulator

Build a Monte Carlo simulator for BPSK, QPSK and 16-QAM over AWGN, check it against theory, then extend it to phase errors to see why dense constellations are fragile.

Formulas tell you what should happen. A simulator shows you that it does, and lets you explore cases that have no formula. Every communications engineer builds one early on, because trusting a result you can verify two ways is a big step up from trusting one you cannot.

In this project you will write a small, vectorized Monte Carlo simulator in Python for BPSK, QPSK and 16-QAM over an AWGN channel, validate it against the theory of chapter 6, and then extend it with a carrier phase error.

A five-step pipeline: random bits, map to plus or minus one, add Gaussian noise, decide by sign, count errors. Below, theory BER curve with simulated dots on it and a checklist.
Monte Carlo against the formula: the dots should land on the line.

What you will learn

  • Structure a simulation as generate, modulate, add noise, demodulate, compare.
  • Set the noise level from Eb/N0 correctly for each modulation.
  • Decide how many bits are needed for a trustworthy BER.
  • Validate against theory and extend the model.

Key terms

  • Monte Carlo simulation: estimate a probability by counting outcomes over many random trials.
  • Confidence: with E observed errors the relative uncertainty is about 1/โˆšE; use at least 100 errors per point.
  • Reproducibility: a fixed random seed gives the same results every run.
  • Es and Eb: symbol and bit energy; set N0 = Eb / (Eb/N0).
  • Phase offset: a rotation of the received constellation.

The recipe

  1. Fix the energy. Scale each constellation to unit average symbol energy Es = 1. Then Eb = Es / k with k bits per symbol: Eb = 1 for BPSK, 0.5 for QPSK and 0.25 for 16-QAM.
  2. Set the noise. For a target Eb/N0 (linear ฮณ), N0 = Eb / ฮณ. The noise on each real dimension has variance N0 / 2.
  3. Generate bits and map them. Use Gray mapping so neighbors differ in one bit.
  4. Add noise, decide, compare. Decide on the nearest constellation point, map back to bits and count differences.
  5. Check it. At each point the simulated value should be within about 1/โˆšE (relative) of the formula. If it is consistently off by a factor of two, suspect the noise scaling; if it is off by a few dB, suspect Es versus Eb.

Number of bits

If you simulate N bits and see E errors, the BER estimate is E/N with a relative standard error of about 1/โˆšE. Hence to see a BER of 10โปโต with 10 % accuracy you need around 100 errors, which means 10โท bits. Vectorized NumPy handles millions of bits per second; for very low BERs use importance sampling or switch to analysis.

Common misconceptions

  • "If the simulation shows zero errors, the BER is zero." It only shows that the BER is below about 1/N.
  • "The seed does not matter." It matters for reproducibility; use several seeds to see the spread.
  • "SNR and Eb/N0 can be mixed freely in code." Mixing them is the commonest cause of a curve that is wrong by exactly 10ยทlog10(k) dB.
  • "A simulation proves the formula." It supports it within statistical error and under the model's assumptions.

Try it

The complete simulator is below. It runs the three schemes at several Eb/N0 values, prints a comparison table and plots dots (simulation) on lines (theory). Points with fewer than 20 observed errors are left out.

Python BER simulator: BPSK, QPSK, 16-QAM

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Now the extension. A carrier phase offset rotates the received constellation. BPSK only loses a factor cos ฯ† of its amplitude, but 16-QAM has points whose decision boundaries are close, so rotation pushes points toward neighboring regions. The experiment applies a fixed rotation (no correction) at Eb/N0 = 12 dB.

Python Extension: phase error hurts dense constellations

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Ideas to extend it

  • Add the Hamming (7,4) code from chapter 7 and compare coded and uncoded curves.
  • Replace AWGN by Rayleigh fading with a known channel gain, then add diversity (average two fades).
  • Add a raised-cosine pulse and matched filter from chapter 5 and verify there is no loss.
  • Produce a table of the Eb/N0 needed for BER 10โปยณ for each scheme by bisection.
  • Increase the constellation to 64-QAM and measure how much phase error it tolerates.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A simulation of 10โถ bits shows 25 errors. About how accurate is the estimated BER?

    The relative standard error is about 1/โˆš25 = 20 %.
  2. 2. For QPSK with unit average symbol energy, what is Eb?

    Eb = Es/k = 1/2 with k = 2 bits per symbol.
  3. 3. A simulated BER curve is shifted right of the theory by about 3 dB. A likely cause is:

    A factor 2 in noise variance is exactly 3 dB.
  4. 4. Why is 16-QAM more sensitive to a carrier phase error than BPSK?

    Dense constellations have little angular and amplitude room before a point crosses a boundary.

Summary

  • A BER simulation is generate, map, add noise, decide, compare, with noise set from Eb/N0 and unit Es.
  • Use enough bits for at least 100 errors per point; zero errors only bounds the BER.
  • Validate against the formula; a constant dB offset usually means an Es/Eb or variance mistake.
  • Extensions such as phase errors show why dense constellations demand accurate synchronization.

Next: Project: a link budget calculator