-
galois.ReedSolomon.decode(codeword: ArrayLike, output: 'message' | 'codeword' =
'message'
, errors: False =False
) FieldArray -
galois.ReedSolomon.decode(codeword: ArrayLike, output: 'message' | 'codeword' =
'message'
, errors: True =True
) tuple[galois._fields._array.FieldArray, int | numpy.ndarray] Decodes the codeword
into the message .- Parameters:¶
- codeword: ArrayLike¶
The codeword as either a
-length vector or matrix, where is the number of codewords.Shortened codes
For the shortened
code (only applicable for systematic codes), pass symbols intodecode()
to return the -symbol message.- output: 'message' | 'codeword' =
'message'
¶ Specify whether to return the error-corrected message or entire codeword. The default is
"message"
.- errors: False =
False
¶ - errors: True =
True
Optionally specify whether to return the number of corrected errors. The default is
False
.
- Returns:¶
If
output="message"
, the error-corrected message as either a -length vector or matrix. Ifoutput="codeword"
, the error-corrected codeword as either a -length vector or matrix.If
errors=True
, returns the number of corrected symbol errors as either a scalar or -length array. Valid number of corrections are in . If a codeword has too many errors and cannot be corrected, -1 will be returned.
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 . Each codeword polynomial is divisible by the generator polynomial .In decoding, the syndrome vector
is computed by evaluating the received codeword at the roots of the generator polynomial . The equivalent polynomial operation computes the remainder of by .A syndrome of zeros indicates the received codeword is a valid codeword and there are no errors. If the syndrome is non-zero, the decoder will find an error-locator polynomial
and the corresponding error locations and values.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([ 7, 7, 5, 10, 10, 5, 11, 5, 12], order=2^4) In [4]: c = rs.encode(m); c Out[4]: GF([ 7, 7, 5, 10, 10, 5, 11, 5, 12, 10, 5, 6, 13, 0, 5], order=2^4)
Corrupt
symbols of the codeword.In [5]: e = GF.Random(rs.t, low=1); e Out[5]: GF([ 8, 13, 14], order=2^4) In [6]: c[0:rs.t] += e; c Out[6]: GF([15, 10, 11, 10, 10, 5, 11, 5, 12, 10, 5, 6, 13, 0, 5], order=2^4)
Decode the codeword and recover the message.
In [7]: d = rs.decode(c); d Out[7]: GF([ 7, 7, 5, 10, 10, 5, 11, 5, 12], order=2^4) In [8]: np.array_equal(d, m) Out[8]: True
Decode the codeword, specifying the number of corrected errors, and recover the message.
In [9]: d, e = rs.decode(c, errors=True); d, e Out[9]: (GF([ 7, 7, 5, 10, 10, 5, 11, 5, 12], order=2^4), 3) In [10]: np.array_equal(d, m) Out[10]: True
Encode a single message using the shortened
code.In [11]: rs = galois.ReedSolomon(15, 9) In [12]: GF = rs.field In [13]: m = GF.Random(rs.k - 4); m Out[13]: GF([13, 9, 12, 15, 11], order=2^4) In [14]: c = rs.encode(m); c Out[14]: GF([13, 9, 12, 15, 11, 10, 8, 11, 13, 5, 9], order=2^4)
Corrupt
symbols of the codeword.In [15]: e = GF.Random(rs.t, low=1); e Out[15]: GF([4, 1, 3], order=2^4) In [16]: c[0:rs.t] += e; c Out[16]: GF([ 9, 8, 15, 15, 11, 10, 8, 11, 13, 5, 9], order=2^4)
Decode the codeword and recover the message.
In [17]: d = rs.decode(c); d Out[17]: GF([13, 9, 12, 15, 11], order=2^4) In [18]: np.array_equal(d, m) Out[18]: True
Decode the codeword, specifying the number of corrected errors, and recover the message.
In [19]: d, e = rs.decode(c, errors=True); d, e Out[19]: (GF([13, 9, 12, 15, 11], order=2^4), 3) In [20]: np.array_equal(d, m) Out[20]: True
Encode a matrix of three messages using the
code.In [21]: rs = galois.ReedSolomon(15, 9) In [22]: GF = rs.field In [23]: m = GF.Random((3, rs.k)); m Out[23]: GF([[ 7, 11, 4, 10, 10, 5, 10, 3, 13], [13, 15, 14, 9, 1, 10, 8, 0, 2], [ 5, 4, 11, 8, 0, 15, 8, 3, 5]], order=2^4) In [24]: c = rs.encode(m); c Out[24]: GF([[ 7, 11, 4, 10, 10, 5, 10, 3, 13, 8, 3, 12, 2, 3, 9], [13, 15, 14, 9, 1, 10, 8, 0, 2, 11, 12, 0, 4, 2, 15], [ 5, 4, 11, 8, 0, 15, 8, 3, 5, 0, 6, 14, 8, 3, 6]], order=2^4)
Corrupt the codeword. Add one error to the first codeword, two to the second, and three to the third.
In [25]: c[0,0:1] += GF.Random(1, low=1) In [26]: c[1,0:2] += GF.Random(2, low=1) In [27]: c[2,0:3] += GF.Random(3, low=1) In [28]: c Out[28]: GF([[13, 11, 4, 10, 10, 5, 10, 3, 13, 8, 3, 12, 2, 3, 9], [ 2, 4, 14, 9, 1, 10, 8, 0, 2, 11, 12, 0, 4, 2, 15], [ 3, 11, 12, 8, 0, 15, 8, 3, 5, 0, 6, 14, 8, 3, 6]], order=2^4)
Decode the codeword and recover the message.
In [29]: d = rs.decode(c); d Out[29]: GF([[ 7, 11, 4, 10, 10, 5, 10, 3, 13], [13, 15, 14, 9, 1, 10, 8, 0, 2], [ 5, 4, 11, 8, 0, 15, 8, 3, 5]], order=2^4) In [30]: np.array_equal(d, m) Out[30]: True
Decode the codeword, specifying the number of corrected errors, and recover the message.
In [31]: d, e = rs.decode(c, errors=True); d, e Out[31]: (GF([[ 7, 11, 4, 10, 10, 5, 10, 3, 13], [13, 15, 14, 9, 1, 10, 8, 0, 2], [ 5, 4, 11, 8, 0, 15, 8, 3, 5]], order=2^4), array([1, 2, 3])) In [32]: np.array_equal(d, m) Out[32]: True
Encode a matrix of three messages using the shortened
code.In [33]: rs = galois.ReedSolomon(15, 9) In [34]: GF = rs.field In [35]: m = GF.Random((3, rs.k - 4)); m Out[35]: GF([[ 5, 12, 7, 9, 15], [14, 5, 0, 14, 7], [10, 8, 9, 7, 11]], order=2^4) In [36]: c = rs.encode(m); c Out[36]: GF([[ 5, 12, 7, 9, 15, 13, 14, 2, 14, 0, 2], [14, 5, 0, 14, 7, 0, 10, 9, 11, 5, 11], [10, 8, 9, 7, 11, 13, 5, 3, 13, 3, 5]], order=2^4)
Corrupt the codeword. Add one error to the first codeword, two to the second, and three to the third.
In [37]: c[0,0:1] += GF.Random(1, low=1) In [38]: c[1,0:2] += GF.Random(2, low=1) In [39]: c[2,0:3] += GF.Random(3, low=1) In [40]: c Out[40]: GF([[ 4, 12, 7, 9, 15, 13, 14, 2, 14, 0, 2], [ 1, 2, 0, 14, 7, 0, 10, 9, 11, 5, 11], [ 4, 0, 14, 7, 11, 13, 5, 3, 13, 3, 5]], order=2^4)
Decode the codeword and recover the message.
In [41]: d = rs.decode(c); d Out[41]: GF([[ 5, 12, 7, 9, 15], [14, 5, 0, 14, 7], [10, 8, 9, 7, 11]], order=2^4) In [42]: np.array_equal(d, m) Out[42]: True
Decode the codeword, specifying the number of corrected errors, and recover the message.
In [43]: d, e = rs.decode(c, errors=True); d, e Out[43]: (GF([[ 5, 12, 7, 9, 15], [14, 5, 0, 14, 7], [10, 8, 9, 7, 11]], order=2^4), array([1, 2, 3])) In [44]: np.array_equal(d, m) Out[44]: True