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.
  • 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.

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]

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.1.0.tar.gz (265.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.1.0-py3-none-any.whl (90.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for commpy-1.1.0.tar.gz
Algorithm Hash digest
SHA256 c61a5a14ddc11698904cd04657fcf4322147d126585b931dc3b8e809b845b023
MD5 bd7df4bf8f21ee67a35af16befd298c2
BLAKE2b-256 c98adb0db9dec19b7053c8b3d916739aed12dd892adde665052f393a1c4bda39

See more details on using hashes here.

Provenance

The following attestation bundles were made for commpy-1.1.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.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for commpy-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e585f60c07df2bd6951c70ef4da4f76759f7f6684b585931ccc4ef40e3ffb68e
MD5 ce4c95ca4f3abd7add1494c8ecc8592a
BLAKE2b-256 6dd15cc859855cd7efa1dca6efbe530302f792678134e914207baa2a42e44815

See more details on using hashes here.

Provenance

The following attestation bundles were made for commpy-1.1.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

1.2.0

2 files

This release

1.1.0 This release

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