(Binary) Linear Codes#

load_parity_check_examples(pcm_id[, verbose])

Loads parity-check matrices of built-in example codes.

alist2mat(alist[, verbose])

Converts an alist [MacKay] code definition to a NumPy parity-check matrix.

load_alist(path)

Reads an alist file and returns a nested list describing a code's parity-check matrix.

generate_reg_ldpc(v, c, n[, allow_flex_len, ...])

Generates a random regular (v, c) LDPC code.

make_systematic(mat[, is_pcm])

Converts a binary matrix to its systematic form.

gm2pcm(gm[, verify_results])

Generates the parity-check matrix for a given generator matrix.

pcm2gm(pcm[, verify_results])

Generates the generator matrix for a given parity-check matrix.

verify_gm_pcm(gm, pcm)

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)