comnum.CcsdsRs#

class comnum.CcsdsRs(e=16, depth=1, fill=0)#

The interleaved Reed–Solomon codeblock of CCSDS 131.0-B-5, Sec. 4: the RS(255, 255 − 2E) code over the field of x^8 + x^7 + x^2 + x + 1 with the roots α^(11 j), j = 128 − E, …, 127 + E, its symbols in the dual basis of Annex F, depth codewords interleaved symbol by symbol, shortened by a virtual fill of fill symbols per codeword.

The code works on octets (encode_bytes, decode_bytes, dual-basis octets as they are transmitted) and on bits, eight per octet, the most significant first (encode, decode with hard decisions of the LLRs): k and n count bits.

Parameters:
  • e (int) – symbol errors corrected per codeword, 8 or 16.

  • depth (int) – the interleaving depth I, 1, 2, 3, 4, 5 or 8.

  • fill (int) – the virtual fill q of every codeword (0: full length).

Raises:

ValueError – for another E or I, or a fill that leaves no information.

Examples

The codeblock of E = 16 and I = 5 (Sec. 4.3.8): 1115 octets of frame, 160 check octets, 10 200 bits; 16 octets in error in each codeword are corrected.

>>> import comnum, numpy as np
>>> rs = comnum.CcsdsRs(16, 5)
>>> (rs.frame_len, rs.codeblock_len, rs.n, rs.k)
(1115, 1275, 10200, 8920)
>>> frame = np.arange(1115) % 256
>>> block = rs.encode_bytes(frame)
>>> block[:80] ^= 0xFF  # 80 consecutive octets: 16 in each codeword
>>> decoded, corrected = rs.decode_bytes(block)
>>> bool(np.array_equal(decoded, frame)), corrected
(True, 80)
decode(llr)#

Decode whole codeblocks of LLRs (hard decisions, then the algebraic decoder).

Parameters:

llr (array_like) – a multiple of n LLRs (positive for a 0).

Returns:

k bits per codeblock (uint8).

Return type:

numpy.ndarray

Raises:

ValueError – for an input that is not an array of numbers of the expected shape.

decode_bytes(block)#

Decode a received codeblock.

Parameters:

block (array_like) – codeblock_len octets.

Returns:

the frame and the number of corrected octets (None if a codeword could not be decoded: its octets are then those received).

Return type:

tuple[numpy.ndarray, int | None]

Raises:

ValueError – for a codeblock of another length or a value above 255.

encode(bits)#

Encode whole codeblocks of bits.

Parameters:

bits (array_like) – a multiple of k bits.

Returns:

n bits per codeblock (uint8).

Return type:

numpy.ndarray

Raises:

ValueError – for an input that is not an array of bits of the expected shape.

encode_bytes(frame)#

The codeblock of a frame: the frame, then the 2 E I check octets.

Parameters:

frame (array_like) – frame_len octets (dual basis).

Returns:

codeblock_len octets (uint8).

Return type:

numpy.ndarray

Raises:

ValueError – for a frame of another length or a value above 255.

codeblock_len#

Octets of a codeblock, (255 − q) I.

Type:

int

depth#

The interleaving depth I.

Type:

int

e#

Symbol errors corrected per codeword E.

Type:

int

fill#

The virtual fill q of a codeword.

Type:

int

frame_len#

Octets of a frame, (255 − 2E − q) I.

Type:

int

k#

Information bits per codeblock, 8 frame_len.

Type:

int

n#

Coded bits per codeblock, 8 codeblock_len.

Type:

int