- 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 intodecode()
. 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([ 5, 9, 2, 11, 11, 8, 4, 7, 10], order=2^4) In [4]: c = rs.encode(m); c Out[4]: GF([ 5, 9, 2, 11, 11, 8, 4, 7, 10, 1, 6, 11, 5, 15, 9], 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([ 5, 9, 2, 11, 11, 8, 4, 7, 10], 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([ 5, 9, 2, 11, 11, 8, 4, 7, 10], order=2^4), 1) In [9]: np.array_equal(dec_m, m) Out[9]: True
Constructors¶
String representation¶
Methods¶
-
decode(codeword: ArrayLike, errors: False =
False
) FieldArray - decode(codeword, ...) tuple[FieldArray, np.integer | np.ndarray]
Decodes the Reed-Solomon codeword \(\mathbf{c}\) into the message \(\mathbf{m}\).
- detect(codeword: ArrayLike) bool_ | ndarray
Detects if errors are present in the Reed-Solomon codeword \(\mathbf{c}\).
-
encode(message: ArrayLike, parity_only: bool =
False
) FieldArray Encodes the message \(\mathbf{m}\) into the Reed-Solomon codeword \(\mathbf{c}\).
Properties¶
- 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 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.
-
decode(codeword: ArrayLike, errors: False =