Skip to main content

License: MIT Build Status - GitHub codecov Sourcery

LDPC

My implementation of LDPC codes. My notes regarding theory and implementation appears on GitHub Pages: https://yairmz.github.io/LDPC/
To install:

pip install sim-ldpc

To run tests simply clone, cd into the cloned repo, and run:

python -m pytest

or

python -m pytest --cov-report=html

to run also coverage tests, or

python -m pytest  -n auto --cov-report=html

to run tests in parallel (with number of CPU's dictated by machine) to speed up tests.

Verify static typing with

mypy --strict --config-file .mypy.ini .

Included modules

  • Utilities: implementing various utility operations to assist with encoding, decoding and simulations.
  • Encoder: implementing a generator based encoder, and encoders for IEEE802.11 (WiFi) LDPC codes.
  • Decoder: implementing several decoders
    • Log-SPA based BP decoder
    • MS decodcer
    • Gallager bit filpping decoder
    • Weighted bit flipping decoders, several variants
    • Parallel probabilistic bit flipping decoder (PPBF)

Basic Example

import numpy as np
from bitstring import BitArray, Bits
from ldpc.decoder import DecoderWiFi, bsc_llr
from ldpc.encoder import EncoderWiFi
from ldpc.wifi_spec_codes import WiFiSpecCode
from ldpc.utils import QCFile

# create information bearing bits
rng = np.random.default_rng()
info_bits = np.array(Bits(bytes=rng.bytes(41))[:648//2], dtype=np.int_)
# create encoder with frame of 648 bits, and rate 1/2. Possible rates and frame sizes are per the ieee802.11n spec.
enc = EncoderWiFi(WiFiSpecCode.N648_R12)
# encode bits
encoded = enc.encode(info_bits)

# verify validity of codeword
h = enc.h
np.dot(h, np.array(encoded)) % 2  # creates an all zero vector as required.

# create a decoder which assumes a probability of p=0.05 for bit flips by the channel
# allow up to 20 iterations for the bp decoder.
p = 0.05
decoder = DecoderWiFi(spec=WiFiSpecCode.N648_R12, max_iter=20, channel_model=bsc_llr(p=p))

# create a corrupted version of encoded codeword with error rate p
corrupted = BitArray(encoded)
no_errors = int(len(corrupted)*p)
error_idx = rng.choice(len(corrupted), size=no_errors, replace=False)
for idx in error_idx:
    corrupted[idx] = not corrupted[idx]
decoded, llr, decode_success, num_of_iterations, syndrome, vnode_validity  = decoder.decode(corrupted)
# Verify correct decoding
print(Bits(decoded) == Bits(encoded))  # true
info = decoder.info_bits(decoded)

# a decoder can also be instantiated without a channel model, in which case llr is expected to be sent for decoding instead of
# hard channel outputs.
channel = bsc_llr(p=p)
channel_llr = channel(np.array(corrupted, dtype=np.int_))
decoder = DecoderWiFi(spec=WiFiSpecCode.N648_R12, max_iter=20)
decoded, llr2, decode_success, num_of_iterations, syndrome, vnode_validity  = decoder.decode(channel_llr)
print(Bits(decoded) == Bits(encoded))  # true
info = decoder.info_bits(decoded)

The example is also included as a jupyter notebook. Note however, that you need to launch the notebook from the correct path for it to be able to access installed packages. To run the notebook:

  1. create a new virtualenv
python3 -m venv ~/.virtualenv/LDPC_env
  1. activate it and install sim-ldpc, and notebook:
source ~/.virtualenv/LDPC_env/bin/activate
pip install sim-ldpc
pip install notebook
  1. run jupyter from within the virtual env for it to have access to all requirements:
~/.virtualenv/LDPC_env/bin/jupyter-notebook
  1. run the notebook

Sources

Release files for sim-ldpc 0.3.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sim-ldpc 0.3.5
File Size Uploaded
sim-ldpc-0.3.5.tar.gz 2.1 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for sim-ldpc 0.3.5
File Interpreter ABI Platform
sim_ldpc-0.3.5-py3-none-any.whl Python 3 none any Details

Total release size: 4.4 MB

Release files / sim-ldpc-0.3.5.tar.gz

Download URL sim-ldpc-0.3.5.tar.gz
Size 2.1 MB
Tags Source
SHA-256 checksum
How to use checksums
1fbe2fb6ec3fedd696f78c962ef1be4305d3d4e7e4fa040a31cd1bc6284f87db
BLAKE2b-256 checksum
How to use checksums
55769ecd17f85274d5673bf44cc4ad47f3da59c3a8af8887fd5edfdaabfc98a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release files / sim_ldpc-0.3.5-py3-none-any.whl

Download URL sim_ldpc-0.3.5-py3-none-any.whl
Size 2.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
4748cf93674d4ffc080bae71ee40cfa3721cf4cba742b38cb68d1bbab2704af0
BLAKE2b-256 checksum
How to use checksums
2fd172fcb034b0c268ac70da221b82d10933d9a9fb08ec33189592e215e2878c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release history Release notifications | RSS feed

This release

0.3.5 This release

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release 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