comnum.NrTransportBlock#

class comnum.NrTransportBlock(tbs, rate)#

A transport block of the PDSCH and its segmentation (TS 38.212 Sec. 7.2): TB CRC, code blocks with their CRC24B, LDPC and rate matching.

Parameters:
  • tbs (int) – the transport block size (bits).

  • rate (float) – the target code rate R (it selects the base graph).

Raises:

ValueError – for an empty block or a rate outside (0, 1).

Examples

>>> import comnum, numpy as np
>>> tb = comnum.NrTransportBlock(480, 308 / 1024)
>>> tb.code_blocks, tb.base_graph, tb.encode(np.zeros(480, np.uint8), 1584, 2).shape
(1, 2, (1584,))
encode(bits, g, qm, layers=1, rv=0)#

The g channel bits of the transport block (before scrambling).

Parameters:
  • bits (array_like) – the tbs bits.

  • g (int) – the channel bits.

  • qm (int) – the bits per symbol (the bit interleaver).

  • layers (int) – the layers.

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

Returns:

the bits (uint8).

Return type:

numpy.ndarray

Raises:

ValueError – for a block of another size or an invalid g.

rate_matched_lengths(g, qm, layers=1)#

The rate-matched length E_r of every code block (TS 38.212 Sec. 5.4.2.1).

Parameters:
  • g (int) – the channel bits of the transport block.

  • qm (int) – the bits per symbol.

  • layers (int) – the layers.

Returns:

the lengths.

Return type:

list[int]

Raises:

ValueError – unless g is a positive multiple of qm * layers.

base_graph#

The LDPC base graph, 1 or 2.

Type:

int

code_block_bits#

The bits per code block K', its CRC included.

Type:

int

code_blocks#

The code blocks C.

Type:

int

tbs#

The transport block size.

Type:

int