-
galois.ReedSolomon.encode(message: ArrayLike, parity_only: bool =
False
) FieldArray Encodes the message \(\mathbf{m}\) into the Reed-Solomon codeword \(\mathbf{c}\).
- Parameters¶
- message: ArrayLike¶
The message as either a \(k\)-length vector or \((N, k)\) matrix, where \(N\) is the number of messages. For systematic codes, message lengths less than \(k\) 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 \(n\)-length vector or \((N, n)\) matrix. If
parity_only=True
, the parity symbols are returned as either a \(n - k\)-length vector or \((N, n-k)\) matrix.
Notes¶
The message vector \(\mathbf{m}\) is defined as \(\mathbf{m} = [m_{k-1}, \dots, m_1, m_0] \in \mathrm{GF}(q)^k\), which corresponds to the message polynomial \(m(x) = m_{k-1} x^{k-1} + \dots + m_1 x + m_0\). The codeword vector \(\mathbf{c}\) is defined as \(\mathbf{c} = [c_{n-1}, \dots, c_1, c_0] \in \mathrm{GF}(q)^n\), which corresponds to the codeword polynomial \(c(x) = c_{n-1} x^{n-1} + \dots + c_1 x + c_0\).
The codeword vector is computed from the message vector by \(\mathbf{c} = \mathbf{m}\mathbf{G}\), where \(\mathbf{G}\) is the generator matrix. The equivalent polynomial operation is \(c(x) = m(x)g(x)\). For systematic codes, \(\mathbf{G} = [\mathbf{I}\ |\ \mathbf{P}]\) such that \(\mathbf{c} = [\mathbf{m}\ |\ \mathbf{p}]\). And in polynomial form, \(p(x) = -(m(x) x^{n-k}\ \textrm{mod}\ g(x))\) with \(c(x) = m(x)x^{n-k} + p(x)\). For systematic and non-systematic codes, each codeword is a multiple of the generator polynomial, i.e. \(g(x)\ |\ c(x)\).
For the shortened \(\textrm{RS}(n-s, k-s)\) code (only applicable for systematic codes), pass \(k-s\) symbols into
encode()
to return the \(n-s\)-symbol codeword.Examples¶
Encode a single message using the \(\textrm{RS}(15, 9)\) code.
In [1]: rs = galois.ReedSolomon(15, 9) In [2]: GF = rs.field In [3]: m = GF.Random(rs.k); m Out[3]: GF([15, 9, 15, 13, 10, 8, 13, 2, 14], order=2^4) In [4]: c = rs.encode(m); c Out[4]: GF([15, 9, 15, 13, 10, 8, 13, 2, 14, 14, 14, 10, 8, 5, 0], order=2^4)
Compute the parity symbols only.
In [5]: p = rs.encode(m, parity_only=True); p Out[5]: GF([14, 14, 10, 8, 5, 0], order=2^4)
Encode a single message using the shortened \(\textrm{RS}(11, 5)\) 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([0, 3, 9, 3, 3], order=2^4) In [9]: c = rs.encode(m); c Out[9]: GF([ 0, 3, 9, 3, 3, 5, 2, 12, 9, 10, 11], order=2^4)
Compute the parity symbols only.
In [10]: p = rs.encode(m, parity_only=True); p Out[10]: GF([ 5, 2, 12, 9, 10, 11], order=2^4)
Encode a matrix of three messages using the \(\textrm{RS}(15, 9)\) 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([[ 7, 1, 10, 4, 4, 13, 6, 0, 7], [ 7, 11, 14, 1, 8, 13, 0, 10, 10], [15, 7, 5, 7, 15, 15, 11, 2, 4]], order=2^4) In [14]: c = rs.encode(m); c Out[14]: GF([[ 7, 1, 10, 4, 4, 13, 6, 0, 7, 8, 15, 1, 13, 6, 15], [ 7, 11, 14, 1, 8, 13, 0, 10, 10, 3, 1, 12, 15, 6, 4], [15, 7, 5, 7, 15, 15, 11, 2, 4, 12, 15, 1, 3, 7, 1]], order=2^4)
Compute the parity symbols only.
In [15]: p = rs.encode(m, parity_only=True); p Out[15]: GF([[ 8, 15, 1, 13, 6, 15], [ 3, 1, 12, 15, 6, 4], [12, 15, 1, 3, 7, 1]], order=2^4)
Encode a matrix of three messages using the shortened \(\textrm{RS}(11, 5)\) 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([[ 9, 9, 5, 0, 3], [ 3, 2, 0, 4, 4], [13, 10, 6, 10, 14]], order=2^4) In [19]: c = rs.encode(m); c Out[19]: GF([[ 9, 9, 5, 0, 3, 0, 0, 13, 7, 14, 8], [ 3, 2, 0, 4, 4, 9, 8, 4, 3, 8, 0], [13, 10, 6, 10, 14, 12, 4, 13, 6, 3, 11]], order=2^4)
Compute the parity symbols only.
In [20]: p = rs.encode(m, parity_only=True); p Out[20]: GF([[ 0, 0, 13, 7, 14, 8], [ 9, 8, 4, 3, 8, 0], [12, 4, 13, 6, 3, 11]], order=2^4)