Top level block decoder. This function makes use of the lower level
functions such as cyclpoly
, cyclgen
, hammgen
, and
bchenco
. The coded message to decode is pass in code, the
codeword length is n and the message length is k. This
function is used to decode messages using either:
The type of coding to use is defined by the variable typ. This variable is a string taking one of the values
"linear"
"linear/binary"
A linear block code is assumed with the message msg being in a
binary format. In this case the argument opt1 is the generator
matrix, and is required. Additionally, opt2 containing the
syndrome lookup table (see syndtable
) can also be passed.
"cyclic"
"cyclic/binary"
A cyclic code is assumed with the message msg being in a binary
format. The generator polynomial to use can be defined in opt1.
The default generator polynomial to use will be
cyclpoly (n, k)
. Additionally, opt2 containing the
syndrome lookup table (see syndtable
) can also be passed.
"hamming"
"hamming/binary"
A Hamming code is assumed with the message msg being in a binary
format. In this case n must be of an integer of the form
2^m-1
, where m is an integer. In addition k
must be n-m
. The primitive polynomial to use can
be defined in opt1. The default primitive polynomial to use is
the same as defined by hammgen
. The variable opt2 should
not be defined.
"bch"
"bch/binary"
A BCH code is assumed with the message msg being in a binary format. The primitive polynomial to use can be defined in opt2. The error correction capability of the code can also be defined in opt1. Use the empty matrix [] to let the error correction capability take the default value.
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
An x-by-n matrix
Each row of this matrix represents a symbol to be decoded
A vector with length divisible by n
The coded symbols are created from groups of n elements of this vector
The decoded message is return in msg. The number of errors encountered is returned in err. If the coded message format is "decimal" or a "binary" matrix, then err is a column vector having a length equal to the number of decoded symbols. If code is a "binary" vector, then err is the same length as msg and indicated the number of errors in each symbol. If the value err is positive it indicates the number of errors corrected in the corresponding symbol. A negative value indicates an uncorrectable error. The corrected code is returned in ccode in a similar format to the coded message msg. The variable cerr contains similar data to err for ccode.
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 decode
will be performed,
it is often faster to create a generator matrix externally with the
functions hammgen
or cyclgen
, rather than let decode
recalculate this matrix at each iteration. In this case typ should
be "linear". The exception to this case is BCH codes, where the required
syndrome table is too large. The BCH decoder, decodes directly from the
polynomial never explicitly forming the syndrome table.
See also: encode, cyclgen, cyclpoly, hammgen, bchdeco, bchpoly, syndtable.
Package: communications