Python Library for Communication Engineering.
Project description
CommPy
CommPy is a general-purpose Python library for communications engineering (Nachrichtentechnik): channel coding, digital modulation, OFDM, information theory, and queuing theory, 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, 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.
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 — 300+ tests, including exhaustive brute-force cross-validation for algebraic decoders (BCH, Reed-Solomon) and Viterbi against maximum-likelihood search, and statistical BER-vs-SNR checks 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 <repository-url>
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)
More end-to-end examples, including a full transmit chain composing several of these pieces, live in examples/.
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
├── _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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file commpy-1.0.0.tar.gz.
File metadata
- Download URL: commpy-1.0.0.tar.gz
- Upload date:
- Size: 121.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d56ccf58cd9764c91d29796c0b1dfd7b286c18b4c190175998eae9ec866738e1
|
|
| MD5 |
7e488bd91d1382dc951953fe649d0858
|
|
| BLAKE2b-256 |
2b8109b16906a1113a0336e7ba7f6341008bad2a6026b97d999d77044370bdc1
|
Provenance
The following attestation bundles were made for commpy-1.0.0.tar.gz:
Publisher:
publish.yml on MarvinElling/CommPy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
commpy-1.0.0.tar.gz -
Subject digest:
d56ccf58cd9764c91d29796c0b1dfd7b286c18b4c190175998eae9ec866738e1 - Sigstore transparency entry: 2212585223
- Sigstore integration time:
-
Permalink:
MarvinElling/CommPy@54f45da2adfc08aa47230786ede846eecd27b757 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/MarvinElling
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@54f45da2adfc08aa47230786ede846eecd27b757 -
Trigger Event:
release
-
Statement type:
File details
Details for the file commpy-1.0.0-py3-none-any.whl.
File metadata
- Download URL: commpy-1.0.0-py3-none-any.whl
- Upload date:
- Size: 61.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb424bdc99e950665b62b6842d2024950dec597af210b58709fe9ddbe7f53571
|
|
| MD5 |
5bdc238215f2754099f61a1060952673
|
|
| BLAKE2b-256 |
e9e361a5150ed707c3b721b318bee7c36c8c4bc12f4bded254db964c20dfb425
|
Provenance
The following attestation bundles were made for commpy-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on MarvinElling/CommPy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
commpy-1.0.0-py3-none-any.whl -
Subject digest:
eb424bdc99e950665b62b6842d2024950dec597af210b58709fe9ddbe7f53571 - Sigstore transparency entry: 2212585251
- Sigstore integration time:
-
Permalink:
MarvinElling/CommPy@54f45da2adfc08aa47230786ede846eecd27b757 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/MarvinElling
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@54f45da2adfc08aa47230786ede846eecd27b757 -
Trigger Event:
release
-
Statement type: