galois.BCH(n: int, k: int | None = None, d: int | None = None, field: type[FieldArray] | None = None, extension_field: type[FieldArray] | None = None, alpha: ElementLike | None = None, c: int = 1, systematic: bool = True)

Constructs a general \(\textrm{BCH}(n, k)\) code over \(\mathrm{GF}(q)\).

Parameters:
n: int

The codeword size \(n\). If \(n = q^m - 1\), the BCH code is primitive.

k: int | None = None

The message size \(k\).

Important

Either k or d must be provided to define the code. Both may be provided as long as they are consistent.

d: int | None = None

The design distance \(d\). This defines the number of roots \(d - 1\) in the generator polynomial \(g(x)\) over \(\mathrm{GF}(q^m)\).

field: type[FieldArray] | None = None

The Galois field \(\mathrm{GF}(q)\) that defines the alphabet of the codeword symbols. The default is None which corresponds to \(\mathrm{GF}(2)\).

extension_field: type[FieldArray] | None = None

The Galois field \(\mathrm{GF}(q^m)\) that defines the syndrome arithmetic. The default is None which corresponds to \(\mathrm{GF}(q^m)\) where \(q^{m - 1} \le n < q^m\). The default extension field will use matlab_primitive_poly(q, m) for the irreducible polynomial.

alpha: ElementLike | None = None

A primitive \(n\)-th root of unity \(\alpha\) in \(\mathrm{GF}(q^m)\) that defines the \(\alpha^c, \dots, \alpha^{c+d-2}\) roots of the generator polynomial \(g(x)\).

c: int = 1

The first consecutive power \(c\) of \(\alpha\) that defines the \(\alpha^c, \dots, \alpha^{c+d-2}\) roots of the generator polynomial \(g(x)\). The default is 1. If \(c = 1\), the BCH code is narrow-sense.

systematic: bool = True

Indicates if the encoding should be systematic, meaning the codeword is the message with parity appended. The default is True.

Examples

Construct a binary primitive, narrow-sense \(\textrm{BCH}(15, 7)\) code.

In [1]: galois.BCH(15, 7)
Out[1]: <BCH Code: [15, 7, 5] over GF(2)>

In [2]: galois.BCH(15, d=5)
Out[2]: <BCH Code: [15, 7, 5] over GF(2)>

In [3]: galois.BCH(15, 7, 5)
Out[3]: <BCH Code: [15, 7, 5] over GF(2)>

Construct a primitive, narrow-sense \(\textrm{BCH}(26, 17)\) code over \(\mathrm{GF}(3)\).

In [4]: GF = galois.GF(3)

In [5]: galois.BCH(26, 17, field=GF)
Out[5]: <BCH Code: [26, 17, 5] over GF(3)>

In [6]: galois.BCH(26, d=5, field=GF)
Out[6]: <BCH Code: [26, 17, 5] over GF(3)>

In [7]: galois.BCH(26, 17, 5, field=GF)
Out[7]: <BCH Code: [26, 17, 5] over GF(3)>

Construct a non-primitive, narrow-sense \(\textrm{BCH}(13, 4)\) code over \(\mathrm{GF}(3)\).

In [8]: GF = galois.GF(3)

In [9]: galois.BCH(13, 4, field=GF)
Out[9]: <BCH Code: [13, 4, 7] over GF(3)>

In [10]: galois.BCH(13, d=7, field=GF)
Out[10]: <BCH Code: [13, 4, 7] over GF(3)>

In [11]: galois.BCH(13, 4, 7, field=GF)
Out[11]: <BCH Code: [13, 4, 7] over GF(3)>

Discover primitive BCH codes over \(\mathrm{GF}(5)\) by looping over the design distance.

In [12]: GF = galois.GF(5)

In [13]: n = 5**2 - 1

In [14]: for d in range(2, 11):
   ....:     bch = galois.BCH(n, d=d, field=GF)
   ....:     print(repr(bch))
   ....: 
<BCH Code: [24, 22, 2] over GF(5)>
<BCH Code: [24, 20, 3] over GF(5)>
<BCH Code: [24, 18, 4] over GF(5)>
<BCH Code: [24, 16, 5] over GF(5)>
<BCH Code: [24, 16, 6] over GF(5)>
<BCH Code: [24, 15, 7] over GF(5)>
<BCH Code: [24, 13, 8] over GF(5)>
<BCH Code: [24, 11, 9] over GF(5)>
<BCH Code: [24, 9, 10] over GF(5)>