code = encode(msg,n,k)
encodes message, msg, using the Hamming encoding method with codeword
length, n, and message length, k. The value of
n must be calculated for an integer, m, such that
m ≥ 2. The values of n and k
are calculated as 2^{m}–1 and
n–m, respectively.

code = encode(msg,n,k,codingMethod,prim_poly)
encodes msg using codingMethod as the Hamming
encoding method, and prim_poly as the primitive polynomial. The value
of n must be calculated for an integer, m≥2.

code = encode(msg,n,k,codingMethod,genmat)
encodes msg using codingMethod as the linear block
encoding method and genmat as the generator matrix. The value of
n must be calculated for an integer, m≥2.

code = encode(msg,n,k,codingMethod,genpoly)
encodes msg using codingMethod as the systematic
cyclic code and genpoly, as the generator polynomial. The value of
n must be calculated for an integer, m≥2.

[code,added] = encode(___)
returns the additional variable added. added
denotes the number of zeros appended at the end of the message matrix before encoding. You
can specify any of the input argument combinations from the previous syntaxes.

Generator polynomial, specified as a polynomial character vector or a
row vector that gives the coefficients in order of ascending powers of the binary
generator polynomial. The value of genpoly for an
[n, k] cyclic code must have degree
n–k and divide
x^{n}-1, where x is an
identifier.

code — Output code binary column or row vector | binary matrix with n columns | column or row vector of integers in the range [0,
2^{n}–1].

Output code, returned as one of the
options in this table. The value and dimension of code depends on
the value and dimension of the msg and the input message format
according to this table:

Column or row vector of integers in the range [0,
2^{k}–1]

decimal

Column or row vector of integers in the range [0,
2^{n}–1]

added — Additional variable nonnegative integer

Additional variable, returned as the number of zeros that were appended at the end
of the message matrix before encoding for the matrix to have the appropriate size. The
size of the message matrix depends on the n,
k, and msg and the encoding method.

Algorithms

Depending on the error-correction coding method, the encode function
relies on lower-level functions such as hammgen and cyclgen.

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.