Navigation

Operators and Keywords

Function List:

C++ API

Function File: code = encode (msg, n, k)

Function File: code = encode (msg, n, k, typ)

Function File: code = encode (msg, n, k, typ, opt)

Function File: [code, added] = encode (...)

Top level block encoder. This function makes use of the lower level functions such as cyclpoly, cyclgen, hammgen, and 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

"linear"
"linear/binary"
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.
"cyclic"
"cyclic/binary"
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 cyclpoly (n, k)
"hamming"
"hamming/binary"
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 2^m-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 hammgen.
"bch"
"bch/binary"
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 bchpoly (n, k)

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-k matrix
Each row of this matrix represents a symbol to be coded
A vector
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 encode will be performed, it is often faster to create a generator matrix externally with the functions hammgen or cyclgen, rather than let encode recalculate 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.

Package: communications