# Repetition Coding#

Repetition codes are among the most basic channel coding schemes. The achieve redundancy by repeating all bits within a block during encoding.

class RepetitionEncoder(bit_block_size=32, repetitions=3)#

A channel coding scheme based on block-wise repetition of bits.

During encoding, the repetition encoder repeats a block of $$K_n$$ bit_block_size() bits $$\tilde{M}$$ repetitions() times, leading to a code_block_size() of

$L_n = \tilde{M} \cdot K_n$

bits and a coding rate of

$R_n = \frac{K_n}{L_n} = \frac{1}{\tilde{M}} \mathrm{.}$

Let

$\mathbf{x} = \left[ x_1, x_2, \dots, x_{K_n} \right]^\intercal \in \left\lbrace 0, 1 \right\rbrace^{K_n}$

be the vector of input bits and

$\mathbf{y} = \left[ y_1, y_2, \dots, y_{K_n} \right]^\intercal \in \left\lbrace 0, 1 \right\rbrace^{L_n}$

be the vector of repeated output bits. The implemented block repetition scheme can be described by

$y_k = x_{k \mod{K_n}} \mathrm{,}$

assigning input bits to output bits by index.

Parameters:
• bit_block_size (int, optional) – The number of input bits per data block.

• repetitions (int, optional) – The number of times the input bit block is repeated.

Raises:

ValueError – If bit_block_size times repetitions is smaller than code_block_size.

yaml_tag: Optional[str] = 'Repetition'#

YAML serialization tag.

encode(bits)#

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().

decode(encoded_bits)#

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().

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$$.

Return type:

int

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$$.

Return type:

int

property repetitions: int#

Number of times the bit block is repeated during encoding.

Returns:

Number of repetitions $$\tilde{M}$$.

Return type:

int

Raises:
• ValueError – If repetitions is smaller than one.

• ValueError – If repetitions is even.