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 + 1with the rootsα^(11 j),j = 128 − E, …, 127 + E, its symbols in the dual basis of Annex F,depthcodewords interleaved symbol by symbol, shortened by a virtual fill offillsymbols 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,decodewith hard decisions of the LLRs):kandncount bits.- Parameters:
- Raises:
ValueError – for another
EorI, or a fill that leaves no information.
Examples
The codeblock of
E = 16andI = 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
nLLRs (positive for a 0).- Returns:
kbits per codeblock (uint8).- Return type:
- 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_lenoctets.- Returns:
the frame and the number of corrected octets (
Noneif 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
kbits.- Returns:
nbits per codeblock (uint8).- Return type:
- 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 Icheck octets.- Parameters:
frame (array_like) –
frame_lenoctets (dual basis).- Returns:
codeblock_lenoctets (uint8).- Return type:
- Raises:
ValueError – for a frame of another length or a value above 255.