galois.BCH(n: int, k: = None, d: = None, field: = None, extension_field: = None, alpha: = 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: = 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: = 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: = 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: = 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: = 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 : galois.BCH(15, 7)
Out: <BCH Code: [15, 7, 5] over GF(2)>

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

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


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

In : GF = galois.GF(3)

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

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

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


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

In : GF = galois.GF(3)

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

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

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


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

In : GF = galois.GF(5)

In : n = 5**2 - 1

In : 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)>