Skip to content

Repository files navigation

BPSK over AWGN BER Simulator

A minimal BPSK bit-error rate simulator using:

  • pure Python prototype with NumPy and Matplotlib
  • C++ engine and pybind11 bindings
  • CMake build configuration for the Python extension and standalone binary

Setup

python -m pip install --upgrade pip
python -m pip install -r requirements.txt

Run the Python prototype

python python/bpsk_py.py --snr-start -4 --snr-stop 10 --snr-step 2 --num-bits 1000000 --plot

The script prints simulated BER values and saves bpsk_awgn_ber.png.

Build the C++ engine and pybind11 module

mkdir build
cd build
cmake ..
cmake --build . --config Release

Use the C++ binding from Python

Run this command from the project root directory:

python python/bpsk_py.py --use-cpp --snr-start -4 --snr-stop 10 --snr-step 2 --num-bits 1000000 --plot

If you are already inside build, use a path back to the repo root:

python ..\python\bpsk_py.py --use-cpp --snr-start -4 --snr-stop 10 --snr-step 2 --num-bits 1000000 --plot

Benchmark Python vs C++

After building the pybind11 module, run:

python python/bpsk_py.py --benchmark --benchmark-snr 0 --benchmark-num-bits 1000000 --benchmark-runs 3

This prints average timings for the pure Python backend and the C++ backend, plus matching BER results.

Compare Python and C++ plots

After building the module, run:

python python/bpsk_py.py --compare-backends --snr-start -4 --snr-stop 10 --snr-step 2 --num-bits 1000000 --plot --save-plot compare_bpsk_awgn_ber.png

This generates a comparison plot with:

  • theoretical BER curve
  • Python simulation curve
  • C++ simulation curve

Build helper script

On Windows, you can build with the provided helper:

.\build.ps1 -Release

If you need an explicit pybind11 package path, pass it:

.\build.ps1 -Release -Pybind11Path "C:\Users\swath\.pyenv\pyenv-win\versions\3.11.9\Lib\site-packages\pybind11\share\cmake\pybind11"

Run the standalone C++ executable

./bpsk_sim_exe 0 1000000

Notes

  • The Python prototype is the first validation step.
  • After building the C++ module, the --use-cpp path will call the same algorithm from Python.
  • The theoretical BER for BPSK over AWGN is computed with the Q-function.

Observed performance

A quick benchmark at SNR=0 dB with 100000 bits shows:

  • Python backend: ~0.0083 s per run
  • C++ backend: ~0.0074 s per run

The timings are close for this simple single-threaded implementation, while the C++ backend is already slightly faster and can scale better with larger bit counts.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages