- class galois.BCH
A primitive, narrow-sense binary
code.A
code is a linear block code with codeword size , message size , minimum distance , and symbols taken from an alphabet of size 2.To create the shortened
code, construct the full-sized code and then pass bits intoencode()
and bits intodecode()
. Shortened codes are only applicable for systematic codes.Examples¶
Construct the BCH code.
In [1]: galois.bch_valid_codes(15) Out[1]: [(15, 11, 1), (15, 7, 2), (15, 5, 3), (15, 1, 7)] In [2]: bch = galois.BCH(15, 7); bch Out[2]: <BCH Code: [15, 7, 5] over GF(2)>
Encode a message.
In [3]: m = galois.GF2.Random(bch.k); m Out[3]: GF([0, 1, 0, 1, 0, 1, 1], order=2) In [4]: c = bch.encode(m); c Out[4]: GF([0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1], order=2)
Corrupt the codeword and decode the message.
# Corrupt the first bit in the codeword In [5]: c[0] ^= 1 In [6]: dec_m = bch.decode(c); dec_m Out[6]: GF([0, 1, 0, 1, 0, 1, 1], order=2) In [7]: np.array_equal(dec_m, m) Out[7]: True
# Instruct the decoder to return the number of corrected bit errors In [8]: dec_m, N = bch.decode(c, errors=True); dec_m, N Out[8]: (GF([0, 1, 0, 1, 0, 1, 1], order=2), 1) In [9]: np.array_equal(dec_m, m) Out[9]: True
Constructors¶
-
BCH(n: int, k: int, primitive_poly: PolyLike | None =
None
, ...) Constructs a primitive, narrow-sense binary
code.
String representation¶
Methods¶
-
decode(codeword: ArrayLike, errors: False =
False
) GF2 - decode(codeword: ArrayLike, errors) Tuple[GF2, integer | ndarray]
Decodes the BCH codeword
into the message .
-
encode(message: ArrayLike, parity_only: bool =
False
) GF2 Encodes the message
into the BCH codeword .
Properties¶
- property d : int
The design distance
of the code. The minimum distance of a BCH code may be greater than the design distance, .
- property field : Type[FieldArray]
The
FieldArray
subclass for the field that defines the BCH code.
- property generator_poly : Poly
The generator polynomial
whose roots areroots
.
- 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, i.e. .
- property is_primitive : bool
Indicates if the BCH code is primitive, meaning
.
- property is_systematic : bool
Indicates if the code is configured to return codewords in systematic form.
- property roots : FieldArray
The
roots of the generator polynomial. These are consecutive powers of , specifically .
- property t : int
The error-correcting capability of the code. The code can correct
bit errors in a codeword.
-
BCH(n: int, k: int, primitive_poly: PolyLike | None =