-
galois.ReedSolomon.encode(message: ndarray | FieldArray, parity_only: bool =
False
) ndarray | FieldArray Encodes the message
into the Reed-Solomon codeword .- Parameters¶
- message: ndarray | FieldArray¶
The message as either a
-length vector or matrix, where is the number of messages. For systematic codes, message lengths less than may be provided to produce shortened codewords.- parity_only: bool =
False
¶ Optionally specify whether to return only the parity symbols. This only applies to systematic codes. The default is
False
.
- Returns¶
The codeword as either a
-length vector or matrix. The return type matches the message type. Ifparity_only=True
, the parity symbols are returned as either a -length vector or matrix.
Notes¶
The message vector
is defined as , which corresponds to the message polynomial . The codeword vector is defined as , which corresponds to the codeword polynomial .The codeword vector is computed from the message vector by
, where is the generator matrix. The equivalent polynomial operation is . For systematic codes, such that . And in polynomial form, with . For systematic and non-systematic codes, each codeword is a multiple of the generator polynomial, i.e. .For the shortened
code (only applicable for systematic codes), pass symbols intoencode()
to return the -symbol codeword.Examples¶
Encode a single message using the
code.In [1]: rs = galois.ReedSolomon(15, 9) In [2]: GF = rs.field In [3]: m = GF.Random(rs.k); m Out[3]: GF([13, 10, 13, 6, 10, 6, 15, 1, 0], order=2^4) In [4]: c = rs.encode(m); c Out[4]: GF([13, 10, 13, 6, 10, 6, 15, 1, 0, 9, 9, 4, 11, 11, 4], order=2^4)
Compute the parity symbols only.
In [5]: p = rs.encode(m, parity_only=True); p Out[5]: GF([ 9, 9, 4, 11, 11, 4], order=2^4)
Encode a single message using the shortened
code.In [6]: rs = galois.ReedSolomon(15, 9) In [7]: GF = rs.field In [8]: m = GF.Random(rs.k - 4); m Out[8]: GF([7, 1, 6, 8, 5], order=2^4) In [9]: c = rs.encode(m); c Out[9]: GF([ 7, 1, 6, 8, 5, 9, 8, 10, 0, 3, 14], order=2^4)
Compute the parity symbols only.
In [10]: p = rs.encode(m, parity_only=True); p Out[10]: GF([ 9, 8, 10, 0, 3, 14], order=2^4)
Encode a matrix of three messages using the
code.In [11]: rs = galois.ReedSolomon(15, 9) In [12]: GF = rs.field In [13]: m = GF.Random((3, rs.k)); m Out[13]: GF([[ 4, 15, 12, 5, 12, 3, 10, 10, 3], [ 3, 5, 14, 0, 12, 0, 0, 5, 9], [ 2, 14, 14, 8, 12, 1, 14, 5, 7]], order=2^4) In [14]: c = rs.encode(m); c Out[14]: GF([[ 4, 15, 12, 5, 12, 3, 10, 10, 3, 12, 4, 7, 9, 9, 12], [ 3, 5, 14, 0, 12, 0, 0, 5, 9, 8, 15, 2, 11, 12, 1], [ 2, 14, 14, 8, 12, 1, 14, 5, 7, 12, 0, 12, 3, 8, 4]], order=2^4)
Compute the parity symbols only.
In [15]: p = rs.encode(m, parity_only=True); p Out[15]: GF([[12, 4, 7, 9, 9, 12], [ 8, 15, 2, 11, 12, 1], [12, 0, 12, 3, 8, 4]], order=2^4)
Encode a matrix of three messages using the shortened
code.In [16]: rs = galois.ReedSolomon(15, 9) In [17]: GF = rs.field In [18]: m = GF.Random((3, rs.k - 4)); m Out[18]: GF([[ 8, 3, 5, 11, 13], [ 4, 9, 3, 12, 12], [ 9, 0, 3, 1, 13]], order=2^4) In [19]: c = rs.encode(m); c Out[19]: GF([[ 8, 3, 5, 11, 13, 8, 3, 13, 6, 8, 2], [ 4, 9, 3, 12, 12, 11, 12, 4, 12, 15, 1], [ 9, 0, 3, 1, 13, 4, 13, 9, 1, 11, 7]], order=2^4)
Compute the parity symbols only.
In [20]: p = rs.encode(m, parity_only=True); p Out[20]: GF([[ 8, 3, 13, 6, 8, 2], [11, 12, 4, 12, 15, 1], [ 4, 13, 9, 1, 11, 7]], order=2^4)