CommPy
CommPy is a general-purpose Python library for communications engineering (Nachrichtentechnik): channel coding, digital modulation, OFDM, information theory, queuing theory, and link-level simulation, built on NumPy/SciPy with an optional Numba-accelerated fast path.
Overview
CommPy covers the classic communications-engineering stack, end to end:
- Channel coding (FEC): CRC (8/16/32), Hamming, generic cyclic codes, BCH, Reed-Solomon (error + erasure decoding), convolutional codes with hard/soft-decision Viterbi decoding, LDPC codes (belief-propagation decoding; Gallager and quasi-cyclic constructions), polar codes (successive-cancellation and CRC-aided list decoding), turbo codes (parallel-concatenated RSC with iterative log-MAP/BCJR decoding), block and convolutional interleaving.
- Digital modulation: a generic, Gray-coded M-PSK/M-QAM/M-PAM engine with soft-decision (LLR) demodulation, plus the original per-scheme classes (OOK, BPSK, ASK-2/4, QPSK, 8-PSK) kept for backward compatibility.
- Physical layer: raised-cosine/root-raised-cosine pulse shaping, ZF/MMSE linear equalization, symbol-timing and carrier-frequency/-phase synchronization (Gardner TED, M-th-power CFO estimation, a Costas loop).
- OFDM: modulator/demodulator with configurable active subcarriers and cyclic prefix, PAPR/PAPR-CCDF analysis.
- MIMO: i.i.d. Rayleigh channel model, Alamouti space-time block coding (transmit diversity), spatial-multiplexing detectors (zero-forcing, MMSE, maximum-likelihood, K-best sphere), and deterministic/ergodic MIMO capacity.
- Channel models: BSC, BEC, AWGN, Rayleigh/Rician fading, Z-channel, Gilbert-Elliott bursty channel, uniform quantization.
- Information theory: Shannon/binary entropy, mutual information, channel capacity (closed-form BSC/AWGN and Blahut-Arimoto for general DMCs), Huffman and arithmetic source coding, binary rate-distortion.
- Queuing theory: M/M/1, M/M/1/K, M/M/c closed-form performance models.
- Finite-field arithmetic: prime fields GF(p) and binary extension fields GF(2^m), the algebraic foundation for BCH/Reed-Solomon.
- Waveform synthesis: pulse-shaped, optionally up-converted IQ waveforms with eye-diagram/spectrum plotting.
- SDR interoperability: read/write raw complex IQ recordings (GNU Radio-compatible) and SigMF (
.sigmf-data/.sigmf-meta) recordings. - Link-level simulation: early-stopping Monte-Carlo BER/FER sweeps (uncoded, plus
simulate_coded_berfor any soft-input code) with Wilson-score confidence intervals and waterfall-curve plotting. - AI-for-wireless (optional,
commpy[ml]): a PyTorch layer undercommpy.ml— a differentiable AWGN channel, an end-to-end learned autoencoder, a neural soft demapper, and a neural (trainable min-sum) LDPC decoder. Not imported by default, so the base install stays NumPy/SciPy-only. - MCP server (optional,
commpy[mcp]): acommpy-mcpModel Context Protocol server exposing CommPy to AI agents — capability listing, channel capacity, and uncoded/coded BER sweeps.
Features
- Modular by design — each topic (coding, modulation, OFDM, info theory, queuing) is an independent subpackage; shared abstractions (
Modulator,FiniteField) mean adding a new scheme reuses existing, tested machinery instead of duplicating it. - Resource-efficient — vectorized NumPy throughout; SciPy where it's a genuine win (FFT for OFDM,
solve_toeplitzfor MMSE equalization); the one inherently sequential hot loop (Viterbi decoding) gets optional Numba JIT acceleration viapip install commpy[fast], with a correctness-preserving pure-Python fallback when it's not installed. - Rigorously tested — 390+ tests, including exhaustive brute-force cross-validation for algebraic decoders (BCH, Reed-Solomon), Viterbi and polar list decoding against maximum-likelihood search, and statistical BER-vs-SNR checks (coded and uncoded) against theoretical curves.
- Fully typed — complete type hints throughout, checked with
mypy --strict.
Installation
pip install commpy
With optional JIT acceleration for Viterbi decoding:
pip install commpy[fast]
With the optional AI-for-wireless layer (PyTorch, commpy.ml):
pip install commpy[ml]
With the optional MCP server (commpy-mcp, for AI agents):
pip install commpy[mcp]
Or install from source:
git clone https://github.com/MarvinElling/CommPy.git
cd CommPy
pip install -e ".[dev]"
Quick Start
Channel coding: Reed-Solomon
from commpy import ReedSolomonCode
import numpy as np
code = ReedSolomonCode(m=8, k=223) # RS(255, 223), the classic CCSDS code
message = np.arange(223) % code.field.order
codeword = code.encode(message)
corrupted = codeword.copy()
corrupted[[10, 50, 100]] ^= 1 # 3 symbol errors, well within t=16
decoded, _, n_errors = code.decode(corrupted)
assert np.array_equal(decoded, message)
Digital modulation with soft-decision demodulation
from commpy import MQAMModulator, Channels
import numpy as np
mod = MQAMModulator(16) # 16-QAM, Gray-coded, unit average energy
bits = np.random.randint(0, 2, mod.bits_per_symbol * 1000)
symbols = mod.modulate(bits)
received = Channels.awgn(symbols, snr_db=15)
llrs = mod.soft_demodulate(received, noise_var=1.0) # feed straight into a Viterbi decoder
hard_bits = mod.demodulate(received)
Convolutional coding + Viterbi decoding
from commpy import Trellis, ConvolutionalEncoder, viterbi_decode
import numpy as np
trellis = Trellis(constraint_length=7, generators=(0o171, 0o133)) # the classic Voyager code
encoder = ConvolutionalEncoder(trellis)
message = np.random.randint(0, 2, 100)
codeword, _ = encoder.encode(message, terminate=True)
decoded = viterbi_decode(trellis, codeword, mode='hard', terminated=True)
assert np.array_equal(decoded, message)
OFDM
from commpy import OFDMModulator, OFDMDemodulator, MQAMModulator, papr_db
import numpy as np
mod, demod = OFDMModulator(n_fft=64, cp_len=16), OFDMDemodulator(n_fft=64, cp_len=16)
qam = MQAMModulator(4)
bits = np.random.randint(0, 2, 64 * qam.bits_per_symbol * 10)
symbols = qam.modulate(bits)
tx = mod.modulate(symbols)
print(f"PAPR: {papr_db(tx[:64]):.1f} dB")
rx_symbols = demod.demodulate(tx)
assert np.allclose(rx_symbols, symbols)
Information theory
from commpy import channel_capacity_awgn, huffman_codes, huffman_encode
capacity = channel_capacity_awgn(snr_linear=10) # bits/channel use
codes = huffman_codes({'a': 0.5, 'b': 0.25, 'c': 0.25})
encoded = huffman_encode(['a', 'a', 'b', 'c'], codes)
Monte-Carlo BER simulation & SigMF file I/O
from commpy import Channels, MQAMModulator, plot_waterfall, simulate_ber, write_sigmf
mod = MQAMModulator(16)
result = simulate_ber(mod, Channels.awgn, snr_db_range=[6, 8, 10, 12], target_errors=200)
print(result.error_rate, result.ci_lower, result.ci_upper) # early-stopped, with 95% CIs
plot_waterfall(result)
write_sigmf('capture', mod.modulate([0, 1] * 1000), sample_rate=1e6, center_freq=915e6)
More end-to-end examples, including a full transmit chain composing several of these pieces, live in examples/ — or try examples/quickstart.ipynb straight in your browser via the Colab badge above.
Module Structure
commpy/
├── _channelCoding/
│ ├── block/ # CRC, Hamming, cyclic, BCH, Reed-Solomon
│ ├── convolutional/ # Trellis, encoder, Viterbi (hard/soft)
│ └── interleaving/ # Block and convolutional interleavers
├── _channels/ # Channel impairment models (BSC, BEC, AWGN, fading, ...)
├── _fields/ # GF(p) and GF(2^m) arithmetic, polynomials
├── _informationTheory/ # Entropy, capacity, source coding, rate-distortion
├── _modulation/ # Generic M-PSK/M-QAM/M-PAM engine, legacy classes,
│ # pulse shaping, equalization, synchronization
├── _networking/ # M/M/1-family queuing models
├── _ofdm/ # OFDM modulator/demodulator, PAPR analysis
├── _sdr/ # Raw IQ and SigMF file I/O
├── _simulation/ # Monte-Carlo BER/FER simulation, waterfall plotting
├── _utils/ # Math helpers, optional-Numba shim
├── _waves/ # IQ waveform synthesis and plotting
└── __init__.py # Public API (flat re-export; everything else is private)
Only names exported from commpy/__init__.py are public API; submodules (anything starting with _) may be reorganized without notice.
Documentation
docs/GETTING_STARTED.md— tutorials, one per major feature area.docs/API.md— full API reference.docs/USER_GUIDE.md— theory background and best practices.docs/QUICK_REFERENCE.md— cheat sheet.docs/FAQ.md,docs/CHANGELOG.md.examples/— runnable scripts, one per major feature plus a full-chain capstone.
Requirements
- Python ≥ 3.10
- NumPy, SciPy, Matplotlib
- Optional: Numba (
pip install commpy[fast]), for JIT-accelerated Viterbi decoding
License
Licensed under the Apache License 2.0. See LICENSE file for details.
Author
Marvin Elling
Contributing
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests. See CONTRIBUTING.md.
Metadata
Release files for commpy 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| commpy-1.2.0.tar.gz | 88.7 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| commpy-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 196.8 kB
Release files / commpy-1.2.0.tar.gz
| Download URL | commpy-1.2.0.tar.gz |
|---|---|
| Size | 88.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4ba40044fd09f20ea172e00b4f9fd143ac9cacd9264b870fe1d7ce1621760e9c
|
|
BLAKE2b-256 checksum How to use checksums |
4f0128b47a89066d5899ed9fc5c02cedfea9cf93642888310fb1119e57da1de1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / commpy-1.2.0-py3-none-any.whl
| Download URL | commpy-1.2.0-py3-none-any.whl |
|---|---|
| Size | 108.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
88c4d4ed3351acc1f01a20ea198343bf8da0d5c822306c43fbdc6c09b1480b63
|
|
BLAKE2b-256 checksum How to use checksums |
179993d8de5a90765148950f7ba510e99c7d81ebb939b5e38e7573bff5d056fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logSecurity for commpy 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for commpy-1.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.