Two standalone MATLAB testbeds for channel coding, built as supporting toolkits during wireless-security research at UC Riverside:
mqam-viterbi-ber/— parameter-swept BER characterization of Gray-coded M-QAM over AWGN, uncoded vs. rate-1/2 convolutional coding with Viterbi decoding (hard and soft decision, traceback depth 32/48).wtc-ldpc-secrecy/— Monte-Carlo simulation of Wyner wiretap-channel secrecy coding on the 5G NR LDPC chain, showing a secret message that the legitimate receiver recovers reliably while an eavesdropper on a worse channel cannot.
Author: Ahmed Maksud — ahmedmaksud.github.io
A scenario-driven sweep harness characterizes bit-error rate over an AWGN channel for every combination of:
| Dimension | Values |
|---|---|
| Modulation | 4-QAM, 16-QAM (Gray-mapped, unit average power) |
| Coding | uncoded · rate-1/2 convolutional, poly2trellis(7, [171 133]) |
| Viterbi traceback depth | 32 · 48 (continuous mode) |
| Decision type | hard, soft (approximate LLR demodulation with per-SNR noise variance) |
| SNR | 0–26 dB in 1 dB steps |
Each BER point averages 10,000 frames × 1000 symbols; bit-error counting compensates for the Viterbi traceback delay. The SNR loop is parallelized with parfor (runs serially without the Parallel Computing Toolbox).
ECC_sweep.m— defines the six scenarios, runs them all, and saves a consolidated timestamped.matECC_single.m— the simulation engine for one configuration (called by the sweep; usable standalone)ECC_plot.m— loads the newestecc_sweep_results_*.matand renders both panels into a single figure at 300 dpi
The curves reproduce the textbook behavior end to end: soft-decision Viterbi buys roughly 2 dB over hard decision at equal traceback depth; deepening traceback from 32 to 48 adds only a marginal gain at these block sizes; and at low SNR the hard-decision rate-1/2 code is worse than uncoded transmission.
cd mqam-viterbi-ber
ECC_sweep % runs all six scenarios, saves ecc_sweep_results_<timestamp>.mat
ECC_plot % regenerates BER-Combined.png from the newest .matECC_plot saves BER-Combined.png in the folder (both panels in one figure). Requires the Communications Toolbox; Parallel Computing Toolbox optional (speeds up the SNR sweep).
A Monte-Carlo model of Wyner's wiretap setting over a pair of binary symmetric channels: Alice's codeword reaches Bob through BSC(p = 0.05) and the eavesdropper Eve through the noisier BSC(q = 0.15). Because Eve's channel is worse, there is a capacity gap for a secret message.
The transmitted message is the concatenation [secret bits ; randomization bits]. The randomization bits soak up the code rate that lies above the secrecy rate, leaving the secret bits carried by the systematic part of a single LDPC codeword. Rates follow the wiretap framework:
- main-channel capacity
C_p = 1 − h(p), eavesdropper capacityC_q = 1 − h(q), secrecy capacityC_s = C_p − C_q - code rate
R = α·C_p(reliability factor α), secret rateR_s = β·C_s(secrecy factor β) - block length
N = 2¹³, secret/random splitk_s / k_rderived from the rates
For the committed run (p = 0.05, q = 0.15, α = 0.97, β = 1): C_p = 0.714, C_q = 0.390, R = 0.692, and of the k_c = 5670 transmitted message bits, k_s = 2649 are secret and k_r = 3021 are randomization.
The physical layer is the 5G NR LDPC chain from the 5G Toolbox: nrCRCEncode('24A') → nrCodeBlockSegmentLDPC → nrLDPCEncode → nrRateMatchLDPC on the way in, exact BSC log-likelihood ratios log((1−p)/p)·(1−2y) into nrRateRecoverLDPC → nrLDPCDecode (25 iterations) → nrCodeBlockDesegmentLDPC on the way out. Each of the 10⁵ Monte-Carlo trials records secret-bit BER and BLER for both Bob and Eve; main.m reports summary statistics and kernel-density estimates of the two BER distributions.
main.m— configuration, Monte-Carlo driver (parfor), statistics, and the PDF figureWTC.m— one end-to-end trial: message assembly → CRC/LDPC encode + rate-match → BSC pair → LLR decode → secret-bit errorsbinaryEntropy.m— binary entropy helper
With the code rate set just below Bob's capacity (α = 0.97) but above Eve's, the two secret-bit BER distributions separate cleanly: Bob sits at a mean BER ≈ 0.037 — a small, honest finite-blocklength floor from operating near capacity — while Eve sits at ≈ 0.216, roughly one secret bit in five wrong, her decoder unable to resolve the message on the noisier channel. The secret survives at the legitimate receiver and is largely lost at the eavesdropper.
This is a reliability-gap demonstration, not a formally secure coset code.
cd wtc-ldpc-secrecy
main % 1e5 trials (parfor); prints statistics, saves BER_PDF_Bob_Eve.png/.figRequires the 5G Toolbox (NR LDPC functions) and the Statistics and Machine Learning Toolbox (ksdensity); Parallel Computing Toolbox optional (the trial loop is a parfor). Raise max_iter toward 10⁶ for a publication-smooth PDF.
mqam-viterbi-ber/
├── ECC_sweep.m / ECC_single.m / ECC_plot.m
├── ecc_sweep_results_<timestamp>.mat # consolidated sweep output (all six scenarios)
└── BER-Combined.png # committed figure
wtc-ldpc-secrecy/
├── main.m / WTC.m / binaryEntropy.m
└── BER_PDF_Bob_Eve.png / .fig # committed figure
- CEF-ECC-Reconciliation — Reed-Solomon key reconciliation for secret-key generation (a different use of coding: agreeing on keys, not protecting messages)
- SKC-for-MIMO--MilCom23-WCL24 — the information-theoretic side: closed-form secret-key capacity bounds
- MC-STEEP — secrecy-rate optimization for OFDM links

