Cyclic Redundancy Checks#

Cyclic Redundancy Check (CRC) channel coding schemes introduce redundancy in order to detect the occurrence of errors within a block of coded bits after reception. CRC codings usually only detect errors, they do not correct them.

class CyclicRedundancyCheck(bit_block_size, check_block_size)[source]#

Bases: Encoder, RandomNode, Serializable

Cyclic Redundancy Check Mock.

This channel coding step mocks CRC algorithms by appending a random checksum of \(Q\) check_block_size() bits to data bit blocks of size \(K_n\) bit_block_size(). The achieved coding rate is therefore

\[R_{n} = \frac{K_n}{K_n + Q} \mathrm{.}\]
Parameters:
  • bit_block_size (int) – Number of bits per encoded block.

  • check_block_size (int) – Number of bits appended to bit blocks.

decode(code)[source]#

Decodes a single block of bits.

Bit decoding routine during data reception, decoding a block of \(L_n\) code bits into a block of \(K_n\) data bits.

Parameters:

encoded_bits (np.ndarray) – A numpy vector of \(L_n\) code bits, representing a single code block to be decoded.

Returns:

A numpy vector of \(K_n\) bits, representing a single data block.

Return type:

np.ndarray

Raises:

ValueError – If the length of encoded_bits does not equal code_block_size().

encode(data)[source]#

Encodes a single block of bits.

Bit encoding routine during data transmission, encoding a block of \(K_n\) input bits into a block of \(L_n\) code bits.

Parameters:

bits (np.ndarray) – A numpy vector of \(K_n\) bits, representing a single bit block to be encoded.

Returns:

A numpy vector of \(L_n\) bits, representing a single code block.

Return type:

np.ndarray

Raises:

ValueError – If the length of bits does not equal bit_block_size().

property bit_block_size: int#

Data bit block size of a single coding operation.

In other words, the number of input bits within a single code block during transmit encoding, or the number of output bits during receive decoding. Referred to as \(K_n\) within the respective equations.

Returns: Number of bits \(K_n\).

property check_block_size: int#

Number of appended check bits per bit block.

Returns:

Number of check bits \(Q\).

Return type:

int

Raises:

ValueError – If check_block_size is smaller than zero.

property code_block_size: int#

Code bit block size of a single coding operation.

In other words, the number of input bits within a single code block during receive decoding, or the number of output bits during transmit encoding. Referred to as \(L_n\) within the respective equations.

Returns: Number of bits \(L_n\).

yaml_tag: Optional[str] = 'CRC'#

YAML serialization tag.