CRCEncoder#

class sionna.phy.fec.crc.CRCEncoder(crc_degree: str, *, k: int | None = None, precision: str | None = None, device: str | None = None, **kwargs)[source]#

Bases: sionna.phy.block.Block

Adds a Cyclic Redundancy Check (CRC) to the input sequence.

The CRC polynomials from Sec. 5.1 in [3GPPTS38212] are available: {CRC24A, CRC24B, CRC24C, CRC16, CRC11, CRC6}.

Parameters:
  • crc_degree (str) – Defines the CRC polynomial to be used. Can be any value from {CRC24A, CRC24B, CRC24C, CRC16, CRC11, CRC6}.

  • k (int | None) – Optional number of input bits. If specified, the generator matrix is pre-built during initialization, which is required for torch.compile compatibility. If not specified, the matrix is built lazily on first call.

  • 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 of arbitrary shape where the last dimension is […, k].

Outputs:

x_crc – […, k + crc_length], torch.float. Binary tensor containing CRC-encoded bits of the same shape as bits except the last dimension changes to […, k + crc_length].

Notes

For performance enhancements, a generator-matrix-based implementation is used for fixed k instead of the more common shift register-based operations. Thus, the encoder must trigger an (internal) rebuild if k changes.

Examples

import torch
from sionna.phy.fec.crc import CRCEncoder

encoder = CRCEncoder("CRC24A")
bits = torch.randint(0, 2, (10, 100), dtype=torch.float32)
encoded = encoder(bits)
print(encoded.shape)
# torch.Size([10, 124])

Attributes

property crc_degree: str#

CRC degree as string.

property crc_length: int#

Length of CRC. Equals number of CRC parity bits.

property crc_pol: numpy.ndarray#

CRC polynomial in binary representation.

property k: int | None#

Number of information bits per codeword.

property n: int | None#

Number of codeword bits after CRC encoding.

Methods

build(input_shape: Tuple[int, ...]) None[source]#

Build the generator matrix.

The CRC is always added to the last dimension of the input.

Note: For torch.compile compatibility, use the k parameter in __init__ to pre-build the generator matrix.

Parameters:

input_shape (Tuple[int, ...])