GithubHelp home page GithubHelp logo

hichamjanati / pyldpc Goto Github PK

View Code? Open in Web Editor NEW
119.0 3.0 32.0 1.95 MB

Creation of LDPC codes & simulation of coding and decoding binary data. Applications to sound and image files.

License: BSD 3-Clause "New" or "Revised" License

Python 96.88% Makefile 3.12%

pyldpc's Introduction

Travis AppVeyor Codecov

Simulation of LDPC Codes & Applications

version 0.7.9

Description:

  • Simulation of regular LDPC codes.
  • Probabilistic decoding: Belief Propagation algorithm for gaussian white noise transmission.
  • Simulation application to image and audio data.

Image coding-decoding example:

https://media.giphy.com/media/l0COHC49bK6g7yIPm/giphy.gif

An example of coding-decoding is available at the pyldpc webpage.

Installation

If you already have a working Python environment (Anaconda for e.g):

pip install --upgrade pyldpc

Otherwise, we recommend creating this minimal conda env

conda env create --file environment.yml
conda activate pyldpc-env
pip install -U pyldpc

Example

>>> import numpy as np
>>> from pyldpc import make_ldpc, encode, decode, get_message
>>> n = 15
>>> d_v = 4
>>> d_c = 5
>>> snr = 20
>>> H, G = make_ldpc(n, d_v, d_c, systematic=True, sparse=True)
>>> k = G.shape[1]
>>> v = np.random.randint(2, size=k)
>>> y = encode(G, v, snr)
>>> d = decode(H, y, snr)
>>> x = get_message(G, d)
>>> assert abs(x - v).sum() == 0

Documentation

For more examples, see the pyldpc webpage.

pyldpc's People

Contributors

lingr7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pyldpc's Issues

Square image, problem in decoding process

image

Hi! Thanks for creating this library!

I've got this error when decoding one 128x128 RGB image after encoding/transmission.
Code rate (R) = 1/3
n = 9213 (= 3 * (width_RGB * 24bits) - 3 = 3*(128*24) - 3 = 9213
k = 3072
d_v = 2
d_c = 3
seed = 42
systematic=True and sparse=True

Could anyone please help me with this error?
Thanks in advance!

Missing function to encode without noise

The function to encode a given message WITHOUT adding noise seems to be missing. How can I encode a message that is meant to be transmitted over a real medium? The medium itself will add plenty of noise, I don't need any extra added.

possible speedup?

Have you considered this modified method to compute Lr in decoder?
It may offer some speedup, although I haven't tested it.

def phi0(x):
    x = abs(x)
    if (x < 9.08e-5 ):
        return( 10 );
    else:
        return -log (tanh (x/2))

def G(Lq):
    X = sum (phi0(e) for e in Lq)
    s = np.prod(np.sign(Lq))
    return s * phi0(X)

Support CuPy arrays?

Hi, thank you for creating this library.

Would LDPC encoding-decoding benefit from GPU acceleration (for large batches of messages)?

Unable to decode message even with just 1 bit flip in encoded msg

Hello

I am using dv = 4, dc = 5, n = 20, which gives k = 7.
I generate a message of length 7, encode them using ldpc encode, with snr=100000 [since I don't want to add noise]. I then simulate errors in communication by randomly flipping 1 bit of the encoded message.
But, I am unable to decode this message correctly!

Here's the code:
`seed = np.random.RandomState(42)

H, G = make_ldpc(n, d_v, d_c, systematic=True, sparse=True)

input_msg = np.random.randint(2, size=k)

enc_msg = encode(G, input_msg, snr, seed=seed)

dec_msg = get_message(G, decode(H, enc_msg, snr)) # works correctly

flip_ind = np.random.randint(0, len(enc_msg) - 1 )

enc_msg[flip_ind] = -1.0 * enc_msg[flip_ind] # change 1 to -1 and vice versa, to simulate bit flip due to communication errors

flipped_dec_msg = get_message(G, decode(H, enc_msg, snr)) # this is wrong
`

what is the mean of function parity_check_matrix?

Did the funcition builds a regular Parity-Check Matrix H?
But why the Matrix i get is not a Parity-Check Matrix,such as
[1 0 1 0 0 0 0 1 1 1 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 1 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 1 0 0 0 1 0 0 1 0 0 1 0 0 1]
[0 0 0 0 0 0 0 0 0 1 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 1 1 0 0 1 0 0 0 1 1]
[0 0 0 0 0 0 0 0 1 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 1 0 0 0 1 1 0 1 0 0 0 1 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 1 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]

Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated.

python3-numpy-1.21.5-1.fc35.x86_64

When running I get:

/home/nbecker/.local/lib/python3.10/site-packages/pyldpc/utils.py:151: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
  bits = np.array(bits)
/home/nbecker/.local/lib/python3.10/site-packages/pyldpc/utils.py:152: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.

Parity Check and Generator Matrices with ambiguous shapes

The parity check matrix has to be of shape (n-k), where n is the LDPC block length and k is the information codeword length.
However, the code generates different shapes if I am not wrong.
Setting n to 20, d_v to 4, and d_c to 5 yields H of shape (ceil(n*d_v/d_c), n) which is (16, 20), and G with shape (20, 7)!?
Do not forget that for each generator matrix G of shape (k,n) there exist parity check matrix H of shape ((n-k),n).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.