-
galois.ReedSolomon.encode(message: ArrayLike, output: 'codeword' | 'parity' =
'codeword'
) FieldArray Encodes the message
into the codeword .Shortened codes
For the shortened
code (only applicable for systematic codes), pass symbols intoencode()
to return the -symbol message.- Parameters:¶
- message: ArrayLike¶
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.- output: 'codeword' | 'parity' =
'codeword'
¶ Specify whether to return the codeword or parity symbols only. The default is
"codeword"
.
- Returns:¶
If
output="codeword"
, the codeword as either a -length vector or matrix. Ifoutput="parity"
, the parity symbols as either a -length vector or matrix.
Notes¶
The message vector
is a member of . The corresponding message polynomial is a degree- polynomial over .The codeword vector
is a member of . The corresponding codeword polynomial is a degree- polynomial over .The codeword vector is computed by matrix multiplication of the message vector with the generator matrix. The equivalent polynomial operation is multiplication of the message polynomial with the generator polynomial.
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([ 8, 9, 13, 5, 1, 5, 14, 5, 2], order=2^4) In [4]: c = rs.encode(m); c Out[4]: GF([ 8, 9, 13, 5, 1, 5, 14, 5, 2, 14, 7, 13, 15, 12, 14], order=2^4)
Compute the parity symbols only.
In [5]: p = rs.encode(m, output="parity"); p Out[5]: GF([14, 7, 13, 15, 12, 14], 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([12, 0, 7, 13, 3], order=2^4) In [9]: c = rs.encode(m); c Out[9]: GF([12, 0, 7, 13, 3, 7, 2, 11, 13, 14, 5], order=2^4)
Compute the parity symbols only.
In [10]: p = rs.encode(m, output="parity"); p Out[10]: GF([ 7, 2, 11, 13, 14, 5], 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([[ 8, 12, 11, 1, 10, 0, 2, 13, 10], [ 8, 5, 10, 10, 13, 8, 0, 9, 12], [11, 2, 3, 1, 7, 5, 14, 8, 2]], order=2^4) In [14]: c = rs.encode(m); c Out[14]: GF([[ 8, 12, 11, 1, 10, 0, 2, 13, 10, 0, 11, 6, 2, 11, 2], [ 8, 5, 10, 10, 13, 8, 0, 9, 12, 0, 12, 11, 5, 5, 6], [11, 2, 3, 1, 7, 5, 14, 8, 2, 9, 15, 7, 13, 8, 10]], order=2^4)
Compute the parity symbols only.
In [15]: p = rs.encode(m, output="parity"); p Out[15]: GF([[ 0, 11, 6, 2, 11, 2], [ 0, 12, 11, 5, 5, 6], [ 9, 15, 7, 13, 8, 10]], 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([[ 1, 6, 0, 2, 9], [ 0, 10, 9, 7, 10], [ 3, 4, 8, 13, 7]], order=2^4) In [19]: c = rs.encode(m); c Out[19]: GF([[ 1, 6, 0, 2, 9, 9, 9, 14, 14, 3, 4], [ 0, 10, 9, 7, 10, 13, 1, 10, 2, 8, 9], [ 3, 4, 8, 13, 7, 0, 5, 3, 0, 6, 5]], order=2^4)
Compute the parity symbols only.
In [20]: p = rs.encode(m, output="parity"); p Out[20]: GF([[ 9, 9, 14, 14, 3, 4], [13, 1, 10, 2, 8, 9], [ 0, 5, 3, 0, 6, 5]], order=2^4)