- galois.BCH.detect(codeword: ArrayLike) bool | ndarray
Detects if errors are present in the codeword \(\mathbf{c}\).
- Parameters:¶
- Returns:¶
A boolean scalar or \(N\)-length array indicating if errors were detected in the corresponding codeword.
Examples¶
Encode a single message using the \(\textrm{BCH}(15, 7)\) code.
In [1]: bch = galois.BCH(15, 7) In [2]: GF = bch.field In [3]: m = GF.Random(bch.k); m Out[3]: GF([0, 1, 0, 0, 1, 0, 1], order=2) In [4]: c = bch.encode(m); c Out[4]: GF([0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1], order=2)
Detect no errors in the valid codeword.
In [5]: bch.detect(c) Out[5]: False
Detect \(d_{min}-1\) errors in the codeword.
In [6]: bch.d Out[6]: 5 In [7]: c[0:bch.d - 1] ^= 1; c Out[7]: GF([1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1], order=2) In [8]: bch.detect(c) Out[8]: True
Encode a single message using the shortened \(\textrm{BCH}(12, 4)\) code.
In [9]: bch = galois.BCH(15, 7) In [10]: GF = bch.field In [11]: m = GF.Random(bch.k - 3); m Out[11]: GF([1, 0, 1, 0], order=2) In [12]: c = bch.encode(m); c Out[12]: GF([1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0], order=2)
Detect no errors in the valid codeword.
In [13]: bch.detect(c) Out[13]: False
Detect \(d_{min}-1\) errors in the codeword.
In [14]: bch.d Out[14]: 5 In [15]: c[0:bch.d - 1] ^= 1; c Out[15]: GF([0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0], order=2) In [16]: bch.detect(c) Out[16]: True
Encode a matrix of three messages using the \(\textrm{BCH}(15, 7)\) code.
In [17]: bch = galois.BCH(15, 7) In [18]: GF = bch.field In [19]: m = GF.Random((3, bch.k)); m Out[19]: GF([[1, 0, 0, 0, 0, 1, 0], [1, 0, 0, 0, 1, 1, 1], [0, 1, 0, 1, 1, 1, 1]], order=2) In [20]: c = bch.encode(m); c Out[20]: GF([[1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0], [0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1]], order=2)
Detect no errors in the valid codewords.
In [21]: bch.detect(c) Out[21]: array([False, False, False])
Detect one, two, and \(d_{min}-1\) errors in the codewords.
In [22]: bch.d Out[22]: 5 In [23]: c[0, 0:1] ^= 1 In [24]: c[1, 0:2] ^= 1 In [25]: c[2, 0:bch.d - 1] ^= 1 In [26]: c Out[26]: GF([[0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0], [1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1]], order=2) In [27]: bch.detect(c) Out[27]: array([ True, True, True])
Encode a matrix of three messages using the shortened \(\textrm{BCH}(12, 4)\) code.
In [28]: bch = galois.BCH(15, 7) In [29]: GF = bch.field In [30]: m = GF.Random((3, bch.k - 3)); m Out[30]: GF([[1, 0, 1, 1], [1, 1, 0, 0], [1, 0, 0, 0]], order=2) In [31]: c = bch.encode(m); c Out[31]: GF([[1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1], [1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1], [1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1]], order=2)
Detect no errors in the valid codewords.
In [32]: bch.detect(c) Out[32]: array([False, False, False])
Detect one, two, and \(d_{min}-1\) errors in the codewords.
In [33]: bch.d Out[33]: 5 In [34]: c[0, 0:1] ^= 1 In [35]: c[1, 0:2] ^= 1 In [36]: c[2, 0:bch.d - 1] ^= 1 In [37]: c Out[37]: GF([[0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1]], order=2) In [38]: bch.detect(c) Out[38]: array([ True, True, True])