Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

decode

Syntax

msg = decode(code,n,k,'hamming/fmt',prim_poly)
msg = decode(code,n,k,'linear/fmt',genmat,trt)
msg = decode(code,n,k,'cyclic/fmt',genpoly,trt)
msg = decode(code,n,k)
[msg,err] = decode(...)
[msg,err,ccode] = decode(...)
[msg,err,ccode,cerr] = decode(...)

Optional Inputs

InputDefault Value
fmtbinary
prim_polygfprimdf(m) where n = 2^m-1
genpolycyclpoly(n,k)
trt Uses syndtable to create the syndrome decoding table associated with the method's parity-check matrix

Description

For All Syntaxes

The decode function aims to recover messages that were encoded using an error-correction coding technique. The technique and the defining parameters must match those that were used to encode the original signal.

The For All Syntaxes section on the encode reference page explains the meanings of n and k, the possible values of fmt, and the possible formats for code and msg. You should be familiar with the conventions described there before reading the rest of this section. Using the decode function with an input argument code that was not created by the encode function might cause errors.

For Specific Syntaxes

msg = decode(code,n,k,'hamming/fmt',prim_poly) decodes code using the Hamming method. For this syntax, n must have the form 2m-1 for some integer m greater than or equal to 3, and k must equal n-m. prim_poly is a polynomial character vector or a row vector that gives the binary coefficients, in order of ascending powers, of the primitive polynomial for GF(2m) that is used in the encoding process. The default value of prim_poly is gfprimdf(m). The decoding table that the function uses to correct a single error in each codeword is syndtable(hammgen(m)).

msg = decode(code,n,k,'linear/fmt',genmat,trt) decodes code, which is a linear block code determined by the k-by-n generator matrix genmat. genmat is required as input. decode tries to correct errors using the decoding table trt, where trt is a 2^(n-k)-by-n matrix.

msg = decode(code,n,k,'cyclic/fmt',genpoly,trt) decodes the cyclic code code and tries to correct errors using the decoding table trt, where trt is a 2^(n-k)-by-n matrix. genpoly is a polynomial character vector or a row vector that gives the coefficients, in order of ascending powers, of the binary generator polynomial of the code. The default value of genpoly is cyclpoly(n,k). By definition, the generator polynomial for an [n, k] cyclic code must have degree n-k and must divide xn-1.

msg = decode(code,n,k) is the same as msg = decode(code,n,k,'hamming/binary').

[msg,err] = decode(...) returns a column vector err that gives information about error correction. If the code is a convolutional code, err contains the metric calculations used in the decoding decision process. For other types of codes, a nonnegative integer in the rth row of err indicates the number of errors corrected in the rth message word; a negative integer indicates that there are more errors in the rth word than can be corrected.

[msg,err,ccode] = decode(...) returns the corrected code in ccode.

[msg,err,ccode,cerr] = decode(...) returns a column vector cerr whose meaning depends on the format of code:

  • If code is a binary vector, a nonnegative integer in the rth row of vec2matcerr indicates the number of errors corrected in the rth codeword; a negative integer indicates that there are more errors in the rth codeword than can be corrected.

  • If code is not a binary vector, cerr = err.

Examples

collapse all

Encode and decode corrupted data using three types of linear block codes.

Hamming Code

Set the code parameters.

n = 15;                % Code length
k = 11;                % Message length

Create a binary message having length k.

data = randi([0 1],k,1);

Encode the message.

encData = encode(data,n,k,'hamming/binary');

Introduce an error in the 4th bit of the encoded sequence.

encData(4) = ~encData(4);

Decode the corrupted sequence. Observe that the decoder has correctly recovered the message.

decData = decode(encData,n,k,'hamming/binary');

numerr = biterr(data,decData)
numerr =

     0

Linear Block Code

Set the code parameters.

n = 7;                % Code length
k = 3;                % Message length

Create a binary message having length k.

data = randi([0 1],k,1);

Create a cyclic generator polynomial. Then, create a parity-check matrix and convert it into a generator matrix.

pol = cyclpoly(n,k);
parmat = cyclgen(n,pol);
genmat = gen2par(parmat);

Encode the message sequence by using the generator matrix.

encData = encode(data,n,k,'linear/binary',genmat);

Introduce an error in the 3rd bit of the encoded sequence.

encData(3) = ~encData(3);

Decode the corrupted sequence. Observe that the decoder has correctly recovered the message.

decData = decode(encData,n,k,'linear/binary',genmat);

numerr = biterr(data,decData)
Single-error patterns loaded in decoding table.  8 rows remaining.
2-error patterns loaded.  1 rows remaining.
3-error patterns loaded.  0 rows remaining.

numerr =

     0

Cyclic Code

Set the code parameters.

n = 15;                % Code length
k = 5;                 % Message length

Create a binary message having length k.

data = randi([0 1],k,1);

Create a generator polynomial for a cyclic code. Create a parity-check matrix by using the generator polynomial.

gpol = cyclpoly(n,k);
parmat = cyclgen(n,gpol);

Create a syndrome decoding tabled by using the parity-check matrix.

trt = syndtable(parmat);
Single-error patterns loaded in decoding table.  1008 rows remaining.
2-error patterns loaded.  918 rows remaining.
3-error patterns loaded.  648 rows remaining.
4-error patterns loaded.  243 rows remaining.
5-error patterns loaded.  0 rows remaining.

Encode the data by using the generator polynomial.

encData = encode(data,n,k,'cyclic/binary',gpol);

Introduce errors in the 4th and 7th bits of the encoded sequence.

encData(4) = ~encData(4);
encData(7) = ~encData(7);

Decode the corrupted sequence. Observe that the decoder has correctly recovered the message.

decData = decode(encData,n,k,'cyclic/binary',gpol,trt);

numerr = biterr(data,decData)
numerr =

     0

More About

collapse all

Algorithms

Depending on the decoding method, decode relies on such lower-level functions as hammgen, syndtable, and cyclgen.

Introduced before R2006a

Was this topic helpful?