Cyclic Redundancy Check (CRC)#
A cyclic redundancy check adds parity bits to detect transmission errors.
|
Adds a Cyclic Redundancy Check (CRC) to the input sequence. |
|
Allows Cyclic Redundancy Check (CRC) verification and removes parity bits. |
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)