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
python -m pip install --upgrade pip
python -m pip install -r requirements.txtpython python/bpsk_py.py --snr-start -4 --snr-stop 10 --snr-step 2 --num-bits 1000000 --plotThe script prints simulated BER values and saves bpsk_awgn_ber.png.
mkdir build
cd build
cmake ..
cmake --build . --config ReleaseRun 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 --plotIf 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 --plotAfter building the pybind11 module, run:
python python/bpsk_py.py --benchmark --benchmark-snr 0 --benchmark-num-bits 1000000 --benchmark-runs 3This prints average timings for the pure Python backend and the C++ backend, plus matching BER results.
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.pngThis generates a comparison plot with:
- theoretical BER curve
- Python simulation curve
- C++ simulation curve
On Windows, you can build with the provided helper:
.\build.ps1 -ReleaseIf 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"./bpsk_sim_exe 0 1000000- The Python prototype is the first validation step.
- After building the C++ module, the
--use-cpppath will call the same algorithm from Python. - The theoretical BER for BPSK over AWGN is computed with the Q-function.
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.