Cyclic Redundancy Check (CRC)

A cyclic redundancy check adds parity bits to detect transmission errors. The following code snippets show how to add CRC parity bits to a bit sequence and how to verify that the check is valid.

First, we need to create instances of CRCEncoder and CRCDecoder:

encoder = CRCEncoder(crc_degree="CRC24A") # the crc_degree denotes the number of added parity bits and is taken from the 3GPP 5G NR standard.

decoder = CRCDecoder(crc_encoder=encoder) # the decoder must be associated to a specific encoder

We can now run the CRC encoder and test if the CRC holds:

# u contains the information bits to be encoded and has shape [...,k].
# c contains u and the CRC parity bits. It has shape [...,k+k_crc].
c = encoder(u)

# u_hat contains the information bits without parity bits and has shape [...,k].
# crc_valid contains a boolean per codeword that indicates if the CRC validation was successful.
# It has shape [...,1].
u_hat, crc_valid = decoder(c)
class sionna.phy.fec.crc.CRCEncoder(crc_degree, *, precision=None, **kwargs)[source]

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

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

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

  • precision (None (default) | ‘single’ | ‘double’) – Precision used for internal calculations and outputs. If set to None, precision is used.

Input:

bits ([…,k], tf.float) – Binary tensor of arbitrary shape where the last dimension is […,k].

Output:

x_crc ([…,k+crc_degree], tf.float) – Binary tensor containing CRC-encoded bits of the same shape as inputs except the last dimension changes to […,k+crc_degree].

Note

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.

property crc_degree

CRC degree as string

property crc_length

Length of CRC. Equals number of CRC parity bits.

property crc_pol

CRC polynomial in binary representation

property k

Number of information bits per codeword

property n

Number of codeword bits after CRC encoding.

class sionna.phy.fec.crc.CRCDecoder(crc_encoder, *, precision=None, **kwargs)[source]

Allows Cyclic Redundancy Check (CRC) verification and removes parity bits.

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

Parameters:
  • crc_encoder (CRCEncoder) – An instance of CRCEncoder associated with the CRCDecoder.

  • precision (None (default) | ‘single’ | ‘double’) – Precision used for internal calculations and outputs. If set to None, precision is used.

Input:

x_crc ([…,k+crc_degree], tf.float) – Binary tensor containing the CRC-encoded bits (the last crc_degree bits are parity bits).

Output:
  • bits ([…,k], tf.float) – Binary tensor containing the information bit sequence without CRC parity bits.

  • crc_valid ([…,1], tf.bool) – Boolean tensor containing the result of the CRC check per codeword.

property crc_degree

CRC degree as string.

property encoder

CRC Encoder used for internal validation.

References:
[3GPPTS38212_CRC] (1,2)

ETSI 3GPP TS 38.212 “5G NR Multiplexing and channel coding”, v.16.5.0, 2021-03.