class galois.ReedSolomon

A general \(\textrm{RS}(n, k)\) code.

A \(\textrm{RS}(n, k)\) code is a \([n, k, d]_q\) linear block code with codeword size \(n\), message size \(k\), minimum distance \(d\), and symbols taken from an alphabet of size \(q\) (a prime power).

To create the shortened \(\textrm{RS}(n-s, k-s)\) code, construct the full-sized \(\textrm{RS}(n, k)\) code and then pass \(k-s\) symbols into encode() and \(n-s\) symbols into decode(). Shortened codes are only applicable for systematic codes.

Examples

Construct the Reed-Solomon code.

In [1]: rs = galois.ReedSolomon(15, 9)

In [2]: GF = rs.field

Encode a message.

In [3]: m = GF.Random(rs.k); m
Out[3]: GF([14,  9,  7,  1, 11, 11, 13, 10, 11], order=2^4)

In [4]: c = rs.encode(m); c
Out[4]: GF([14,  9,  7,  1, 11, 11, 13, 10, 11,  1, 10,  2,  8,  6, 10], order=2^4)

Corrupt the codeword and decode the message.

# Corrupt the first symbol in the codeword
In [5]: c[0] ^= 13

In [6]: dec_m = rs.decode(c); dec_m
Out[6]: GF([14,  9,  7,  1, 11, 11, 13, 10, 11], order=2^4)

In [7]: np.array_equal(dec_m, m)
Out[7]: True
# Instruct the decoder to return the number of corrected symbol errors
In [8]: dec_m, N = rs.decode(c, errors=True); dec_m, N
Out[8]: (GF([14,  9,  7,  1, 11, 11, 13, 10, 11], order=2^4), 1)

In [9]: np.array_equal(dec_m, m)
Out[9]: True

Constructors

ReedSolomon(n: int, k: int, c: int = 1, ...)

Constructs a general \(\textrm{RS}(n, k)\) code.

String representation

__repr__() str

A terse representation of the Reed-Solomon code.

__str__() str

A formatted string with relevant properties of the Reed-Solomon code.

Methods

decode(codeword: ndarray | FieldArray, ...) ndarray | FieldArray
decode(...) Tuple[ndarray | FieldArray, integer | ndarray]

Decodes the Reed-Solomon codeword \(\mathbf{c}\) into the message \(\mathbf{m}\).

detect(codeword: ndarray | FieldArray) bool_ | ndarray

Detects if errors are present in the Reed-Solomon codeword \(\mathbf{c}\).

encode(message: ndarray | FieldArray, ...) ndarray | FieldArray

Encodes the message \(\mathbf{m}\) into the Reed-Solomon codeword \(\mathbf{c}\).

Properties

property c : int

The degree of the first consecutive root.

property d : int

The design distance \(d\) of the \([n, k, d]_q\) code. The minimum distance of a Reed-Solomon code is exactly equal to the design distance, \(d_{min} = d\).

property field : Type[FieldArray]

The FieldArray subclass for the \(\mathrm{GF}(q)\) field that defines the Reed-Solomon code.

property G : FieldArray

The generator matrix \(\mathbf{G}\) with shape \((k, n)\).

property generator_poly : Poly

The generator polynomial \(g(x)\) whose roots are roots.

property H : FieldArray

The parity-check matrix \(\mathbf{H}\) with shape \((2t, n)\).

property is_narrow_sense : bool

Indicates if the Reed-Solomon code is narrow sense, meaning the roots of the generator polynomial are consecutive powers of \(\alpha\) starting at 1, i.e. \(\alpha, \alpha^2, \dots, \alpha^{2t - 1}\).

property is_systematic : bool

Indicates if the code is configured to return codewords in systematic form.

property k : int

The message size \(k\) of the \([n, k, d]_q\) code.

property n : int

The codeword size \(n\) of the \([n, k, d]_q\) code.

property roots : FieldArray

The \(2t\) roots of the generator polynomial. These are consecutive powers of \(\alpha\), specifically \(\alpha^c, \alpha^{c+1}, \dots, \alpha^{c+2t-1}\).

property t : int

The error-correcting capability of the code. The code can correct \(t\) symbol errors in a codeword.


Last update: Jul 24, 2022