Top level block encoder. This function makes use of the lower level functions such as
bchenco. The message to code is pass in msg, the codeword length is n and the message length is k. This function is used to encode messages using either:
- A [n,k] linear block code defined by a generator matrix
- A [n,k] cyclic code defined by a generator polynomial
- A [n,k] Hamming code defined by a primitive polynomial
- A [n,k] BCH code code defined by a generator polynomial
The type of coding to use is defined by the variable typ. This variable is a string taking one of the values
- A linear block code is assumed with the coded message code being in a binary format. In this case the argument opt is the generator matrix, and is required.
- A cyclic code is assumed with the coded message code being in a binary format. The generator polynomial to use can be defined in opt. The default generator polynomial to use will be
- A Hamming code is assumed with the coded message code being in a binary format. In this case n must be of an integer of the form
-1, where m is an integer. In addition k must be n
-m. The primitive polynomial to use can be defined in opt. The default primitive polynomial to use is the same as defined by
- A BCH code is assumed with the coded message code being in a binary format. The generator polynomial to use can be defined in opt. The default generator polynomial to use will be
In addition the argument "binary" above can be replaced with "decimal", in which case the message is assumed to be a decimal vector, with each value representing a symbol to be coded. The binary format can be in two forms
- Each row of this matrix represents a symbol to be coded
- The symbols are created from groups of k elements of this vector. If the vector length is not divisible by k, then zeros are added and the number of zeros added is returned in added.
It should be noted that all internal calculations are performed in the binary format. Therefore for large values of n, it is preferable to use the binary format to pass the messages to avoid possible rounding errors. Additionally, if repeated calls to
encodewill be performed, it is often faster to create a generator matrix externally with the functions
cyclgen, rather than let
encoderecalculate this matrix at each iteration. In this case typ should be "linear". The exception to this case is BCH codes, whose encoder is implemented directly from the polynomial and is significantly faster.
See also: decode, cyclgen, cyclpoly, hammgen, bchenco, bchpoly.