Skip to main content

PyPI version Python versions License: Apache 2.0 CI PyPI Downloads Open in Colab

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_ber for any soft-input code) with Wilson-score confidence intervals and waterfall-curve plotting.
  • AI-for-wireless (optional, commpy[ml]): a PyTorch layer under commpy.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]): a commpy-mcp Model 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_toeplitz for MMSE equalization); the one inherently sequential hot loop (Viterbi decoding) gets optional Numba JIT acceleration via pip 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

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

commpy-1.2.0.tar.gz (88.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

commpy-1.2.0-py3-none-any.whl (108.1 kB view details)

Uploaded Python 3

File details

Details for the file commpy-1.2.0.tar.gz.

File metadata

  • Download URL: commpy-1.2.0.tar.gz
  • Upload date:
  • Size: 88.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for commpy-1.2.0.tar.gz
Algorithm Hash digest
SHA256 4ba40044fd09f20ea172e00b4f9fd143ac9cacd9264b870fe1d7ce1621760e9c
MD5 172b873fea8f15e93ddab8eb5a7e01cd
BLAKE2b-256 4f0128b47a89066d5899ed9fc5c02cedfea9cf93642888310fb1119e57da1de1

See more details on using hashes here.

Provenance

The following attestation bundles were made for commpy-1.2.0.tar.gz:

Publisher: publish.yml on MarvinElling/CommPy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file commpy-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: commpy-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 108.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for commpy-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 88c4d4ed3351acc1f01a20ea198343bf8da0d5c822306c43fbdc6c09b1480b63
MD5 d9cf311a741d32cb8424774a33a9c5ad
BLAKE2b-256 179993d8de5a90765148950f7ba510e99c7d81ebb939b5e38e7573bff5d056fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for commpy-1.2.0-py3-none-any.whl:

Publisher: publish.yml on MarvinElling/CommPy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 files

1.1.0

2 files

1.0.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page