LDPC5GEncoder#

class sionna.phy.fec.ldpc.LDPC5GEncoder(k: int, n: int, num_bits_per_symbol: int | None = None, bg: str | None = None, precision: str | None = None, device: str | None = None, **kwargs)[source]#

Bases: sionna.phy.block.Block

5G NR LDPC Encoder following the 3GPP 38.212 including rate-matching.

The implementation follows the 3GPP NR Initiative [3GPPTS38212].

Parameters:
  • k (int) – Number of information bits per codeword.

  • n (int) – Desired codeword length.

  • num_bits_per_symbol (int | None) – Number of bits per QAM symbol. If provided, the codeword will be interleaved after rate-matching as specified in Sec. 5.4.2.2 in [3GPPTS38212].

  • bg (str | None) – Basegraph to be used for the code construction. If None, the encoder will automatically select the basegraph according to [3GPPTS38212].

  • precision (str | None) – Precision used for internal calculations and outputs. If None, precision is used.

  • device (str | None) – Device for computation (e.g., ‘cpu’, ‘cuda:0’). If None, device is used.

Inputs:

bits – […, k], torch.float. Binary tensor containing the information bits to be encoded.

Outputs:

cw – […, n], torch.float. Binary tensor of same shape as inputs besides last dimension has changed to n containing the encoded codeword bits.

Notes

As specified in [3GPPTS38212], the encoder also performs rate-matching (puncturing and shortening). Thus, the corresponding decoder needs to invert these operations, i.e., must be compatible with the 5G encoding scheme.

Examples

import torch
from sionna.phy.fec.ldpc import LDPC5GEncoder

# Create encoder for k=100 information bits and n=200 codeword bits
encoder = LDPC5GEncoder(k=100, n=200)

# Generate random information bits
u = torch.randint(0, 2, (10, 100), dtype=torch.float32)
c = encoder(u)
print(c.shape)
# torch.Size([10, 200])

Attributes

property k: int#

Number of input information bits.

property n: int#

Number of output codeword bits.

property coderate: float#

Coderate of the LDPC code after rate-matching.

property k_ldpc: int#

Number of LDPC information bits after rate-matching.

property n_ldpc: int#

Number of LDPC codeword bits before rate-matching.

property pcm: scipy.sparse._csr.csr_matrix#

Parity-check matrix for given code parameters.

property z: int#

Lifting factor of the basegraph.

property num_bits_per_symbol: int | None#

Modulation order used for the rate-matching output interleaver.

property out_int: torch.Tensor#

Output interleaver sequence as defined in 5.4.2.2.

property out_int_inv: torch.Tensor#

Inverse output interleaver sequence as defined in 5.4.2.2.

Methods

generate_out_int(n: int, num_bits_per_symbol: int) Tuple[numpy.ndarray, numpy.ndarray][source]#

Generates LDPC output interleaver sequence as defined in Sec 5.4.2.2 in [3GPPTS38212].

Parameters:
  • n (int) – Desired output sequence length.

  • num_bits_per_symbol (int) – Number of bits per QAM symbol, i.e., the modulation order.

Notes

The interleaver pattern depends on the modulation order and helps to reduce dependencies in bit-interleaved coded modulation (BICM) schemes combined with higher order modulation.

build(input_shape: tuple) None[source]#

Build block and check for valid input shapes.

Parameters:

input_shape (tuple)