Package: sim-ldpc
LDPCMy implementation of LDPC codes.
My notes regarding theory and implementation appears on GitHub Pages:https://yairmz.github.io/LDPC/To install:pipinstallsim-ldpcTo run tests simply clone, cd into the cloned repo, and run:python-mpytestorpython-mpytest--cov-report=htmlto run also coverage tests, orpython-mpytest-nauto--cov-report=htmlto run tests in parallel (with number of CPU's dictated by machine) to speed up tests.Verify static typing withmypy--strict--config-file.mypy.ini.Included modulesUtilities: 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 decodersLog-SPA based BP decoderMS decodcerGallager bit filpping decoderWeighted bit flipping decoders, several variantsParallel probabilistic bit flipping decoder (PPBF)Basic ExampleimportnumpyasnpfrombitstringimportBitArray,Bitsfromldpc.decoderimportDecoderWiFi,bsc_llrfromldpc.encoderimportEncoderWiFifromldpc.wifi_spec_codesimportWiFiSpecCodefromldpc.utilsimportQCFile# create information bearing bitsrng=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 bitsencoded=enc.encode(info_bits)# verify validity of codewordh=enc.hnp.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.05decoder=DecoderWiFi(spec=WiFiSpecCode.N648_R12,max_iter=20,channel_model=bsc_llr(p=p))# create a corrupted version of encoded codeword with error rate pcorrupted=BitArray(encoded)no_errors=int(len(corrupted)*p)error_idx=rng.choice(len(corrupted),size=no_errors,replace=False)foridxinerror_idx:corrupted[idx]=notcorrupted[idx]decoded,llr,decode_success,num_of_iterations,syndrome,vnode_validity=decoder.decode(corrupted)# Verify correct decodingprint(Bits(decoded)==Bits(encoded))# trueinfo=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))# trueinfo=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:create a new virtualenvpython3-mvenv~/.virtualenv/LDPC_envactivate it and installsim-ldpc, andnotebook:source~/.virtualenv/LDPC_env/bin/activate
pipinstallsim-ldpc
pipinstallnotebookrun jupyter from within the virtual env for it to have access to all requirements:~/.virtualenv/LDPC_env/bin/jupyter-notebookrun the notebookSourcesCai Z., Hao J., Tan P.H., Sun S., Chin P.S., Efficient encoding of IEEE 802.11n LDPC codes. Electronics Letters 25,
1471--1472 (2006).IEEE802.11 encoder tested against the implementation inhttps://github.com/tavildar/LDPCChannel codes : classical and modernby William E. Ryan, 2009.