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.Block5G 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,
precisionis used.device (str | None) – Device for computation (e.g., ‘cpu’, ‘cuda:0’). If None,
deviceis used.
- Inputs:
bits – […, k], torch.float. Binary tensor containing the information bits to be encoded.
rv – None | list of int. List of redundancy version indices (0–3) for HARQ-IR rate-matching per TS 38.212 Table 5.4.2.1-2. If None (default), standard RV 0 encoding is used and the output shape is
[..., n]. When provided, each RV produces an independent rate-matched codeword and the output shape becomes[..., len(rv), n].
- Outputs:
cw – […, n] or […, len(rv), n], torch.float. Encoded codeword bits. Same shape as the input with the last dimension replaced by
n. Whenrvis provided, an additional dimension of sizelen(rv)is inserted before the codeword dimension.
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) # [10, 200] # HARQ: produce two redundancy versions c_harq = encoder(u, rv=[0, 2]) print(c_harq.shape) # [10, 2, 200]
Attributes
- property pcm: scipy.sparse._csr.csr_matrix#
Parity-check matrix for given code parameters.
- property num_bits_per_symbol: int | None#
Modulation order used for the rate-matching output interleaver.
- property rv_starts: List[int]#
RV start positions
k0from TS 38.212 Table 5.4.2.1-2.Returns a list of length 4 indexed by
rv_id. Values are in spec buffer space (after the first 2Z punctured positions, before filler removal).\[k_0 = \left\lfloor \frac{\text{coeff} \cdot N_{cb}} {N_{\text{cols}} \cdot Z_c} \right\rfloor \cdot Z_c\]where \(N_{\text{cols}}\) is 66 (BG1) or 50 (BG2). Currently assumes
I_LBRM=0, i.e.,N_cb = N.
- 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
- get_start_positions_comp(rv_list: List[int]) List[int][source]#
Return compressed-buffer start positions for a list of RV indices.
- 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:
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.