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 sequenceand how to verify that the check is valid.

First, we need to create instances ofCRCEncoder andCRCDecoder:

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)
classsionna.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 toNone,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 asinputs except the last dimension changes to[…,k+crc_degree].

Note

For performance enhancements, a generator-matrix-basedimplementation is used for fixedk instead of the more common shiftregister-based operations. Thus, the encoder must trigger an(internal) rebuild ifk changes.

propertycrc_degree

CRC degree as string

propertycrc_length

Length of CRC. Equals number of CRC parity bits.

propertycrc_pol

CRC polynomial in binary representation

propertyk

Number of information bits per codeword

propertyn

Number of codeword bits after CRC encoding.

classsionna.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 ofCRCEncoder associated withthe CRCDecoder.

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

Input:

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

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

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

propertycrc_degree

CRC degree as string.

propertyencoder

CRC Encoder used for internal validation.

References:
[3GPPTS38212_CRC](1,2)

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