comnum.NrLdpc#

class comnum.NrLdpc(k, e, *, base_graph=None, rv=0, qm=1, rule=Ellipsis, alpha=Ellipsis, max_iterations=Ellipsis, layered=Ellipsis)#

The LDPC code of the data channels of 5G NR (3GPP TS 38.212, Sec. 5.3.2, 5.4.2): one code block of k information bits rate-matched to n bits; base graph 1 or 2 chosen as the shared channels do (or forced), the smallest lifting size Z with K_b Z ≥ k, filler bits, the first 2Z bits punctured, the circular buffer read from the start of redundancy version rv, the bit interleaver of qm bits per symbol; decoded by belief propagation.

Parameters:
  • k (int) – information bits per block (at most 8448 for base graph 1, 3840 for 2).

  • e (int) – transmitted bits per block E (the rate-matched length).

  • base_graph (int, optional) – 1 or 2 (default: the rule of Sec. 7.2.2).

  • rv (int) – the redundancy version, 0 to 3.

  • qm (int) – bits per modulation symbol of the bit interleaver (1: none).

  • rule (str) – the check-node rule (as LdpcCode.set_decoder).

  • alpha (float) – the scale or the offset of the min-sum rules.

  • max_iterations (int) – the maximum number of iterations.

  • layered (bool) – the layered schedule (default), or flooding (False); both stop early on a codeword.

Raises:

ValueError – for an invalid parameter (the message names it).

Examples

>>> import comnum, numpy as np
>>> code = comnum.NrLdpc(100, 300)
>>> code.base_graph, code.lifting_size
(2, 18)
>>> b = comnum.bits(100, comnum.Rng(1))
>>> bool(np.array_equal(code.decode(4.0 - 8.0 * code.encode(b)), b))
True
decode(llr)#

Decode whole blocks of LLRs.

Parameters:

llr (array_like) – a multiple of n LLRs (positive for a 0).

Returns:

k bits per block (uint8).

Return type:

numpy.ndarray

Raises:

ValueError – for an input that is not an array of numbers of the expected shape.

encode(bits)#

Encode whole blocks.

Parameters:

bits (array_like) – a multiple of k bits.

Returns:

n bits per block (uint8).

Return type:

numpy.ndarray

Raises:

ValueError – for an input that is not an array of numbers of the expected shape.

base_graph#

The base graph, 1 or 2.

Type:

int

k#

Information bits per block.

Type:

int

lifting_size#

The lifting size Z.

Type:

int

n#

Transmitted bits per block.

Type:

int

rate#

Code rate k / n.

Type:

float