(Binary) Linear Codes#
|
Loads parity-check matrices of built-in example codes. |
|
Converts an alist [MacKay] code definition to a NumPy parity-check matrix. |
|
Reads an alist file and returns a nested list describing a code's parity-check matrix. |
|
Generates a random regular (v, c) LDPC code. |
|
Converts a binary matrix to its systematic form. |
|
Generates the parity-check matrix for a given generator matrix. |
|
Generates the generator matrix for a given parity-check matrix. |
|
Verifies that the generator matrix and parity-check matrix are orthogonal in GF(2). |
Several functions are provided to convert parity-check matrices into generator matrices and vice versa. Please note that currently only binary codes are supported.
# load example parity-check matrix
pcm, k, n, coderate = load_parity_check_examples(pcm_id=3)
Note that many research projects provide their parity-check matrices in the alist format [MacKay] (e.g., see [UniKL]). The follwing code snippet provides an example of how to import an external LDPC parity-check matrix from an alist file and how to set-up an encoder/decoder.
# load external example parity-check matrix in alist format
al = load_alist(path=filename)
pcm, k, n, coderate = alist2mat(al)
# the linear encoder can be directly initialized with a parity-check matrix
encoder = LinearEncoder(pcm, is_pcm=True)
# initalize BP decoder for the given parity-check matrix
decoder = LDPCBPDecoder(pcm, num_iter=20)
# and run simulation with random information bits
no = 1.
batch_size = 10
num_bits_per_symbol = 2
source = BinarySource()
mapper = Mapper("qam", num_bits_per_symbol)
channel = AWGN()
demapper = Demapper("app", "qam", num_bits_per_symbol)
u = source([batch_size, k])
c = encoder(u)
x = mapper(c)
y = channel(x, no)
llr = demapper(y, no)
c_hat = decoder(llr)