- class galois.BCH
A general
code over .A
code is a linear block code with codeword size , message size , minimum distance , and symbols taken from an alphabet of size .Shortened codes
To create the shortened
code, construct the full-sized code and then pass symbols intoencode()
and symbols intodecode()
. Shortened codes are only applicable for systematic codes.A BCH code is a cyclic code over
with generator polynomial . The generator polynomial is over and has roots when evaluated in . The element is a primitive -th root of unity in .Examples¶
Construct a binary
code.In [1]: bch = galois.BCH(15, 7); bch Out[1]: <BCH Code: [15, 7, 5] over GF(2)> In [2]: GF = bch.field; GF Out[2]: <class 'galois.GF(2)'>
Encode a message.
In [3]: m = GF.Random(bch.k); m Out[3]: GF([0, 0, 1, 1, 1, 1, 1], order=2) In [4]: c = bch.encode(m); c Out[4]: GF([0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1], order=2)
Corrupt the codeword and decode the message.
# Corrupt the first symbol in the codeword In [5]: c[0] ^= 1; c Out[5]: GF([1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1], order=2) In [6]: dec_m = bch.decode(c); dec_m Out[6]: GF([0, 0, 1, 1, 1, 1, 1], order=2) In [7]: np.array_equal(dec_m, m) Out[7]: True
Instruct the decoder to return the number of corrected symbol errors.
In [8]: dec_m, N = bch.decode(c, errors=True); dec_m, N Out[8]: (GF([0, 0, 1, 1, 1, 1, 1], order=2), 1) In [9]: np.array_equal(dec_m, m) Out[9]: True
Constructors¶
String representation¶
Methods¶
- decode(codeword: ArrayLike, ...) FieldArray
- decode(codeword, ...) tuple[FieldArray, int | np.ndarray]
Decodes the codeword
into the message .
- encode(message: ArrayLike, ...) FieldArray
Encodes the message
into the codeword .
Properties¶
- property alpha : FieldArray
A primitive
-th root of unity in whose consecutive powers are roots of the generator polynomial in .
- property c : int
The first consecutive power
of that defines the roots of the generator polynomial .
- property extension_field : type[FieldArray]
The Galois field
that defines the BCH syndrome arithmetic.
- property field : type[FieldArray]
The Galois field
that defines the codeword alphabet.
- property G : FieldArray
The generator matrix
with shape .
- property generator_poly : Poly
The generator polynomial
over .
- property H : FieldArray
The parity-check matrix
with shape .
- property is_narrow_sense : bool
Indicates if the BCH code is narrow-sense, meaning the roots of the generator polynomial are consecutive powers of
starting at 1, that is .
- property is_primitive : bool
Indicates if the BCH code is primitive, meaning
.
- property is_systematic : bool
Indicates if the code is systematic, meaning the codewords have parity appended to the message.
- property parity_check_poly : Poly
The parity-check polynomial
.
- property roots : FieldArray
The
roots of the generator polynomial .
- property t : int
The error-correcting capability
of the code. The code can correct symbol errors in a codeword.