## Documentation Center |

`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(...)

Input | Default Value |
---|---|

fmt | binary |

prim_poly | gfprimdf(m) where n = 2^m-1 |

genpoly | cyclpoly(n,k) |

trt | Uses syndtable to
create the syndrome decoding table associated with the method's parity-check
matrix |

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

`msg = decode(code,n,k,'hamming/fmt',prim_poly)` decodes

`msg = decode(code,n,k,'linear/fmt',genmat,trt)` decodes

`msg = decode(code,n,k,'cyclic/fmt',genpoly,trt)` decodes
the cyclic code

`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`vec2mat``cerr`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`.

On the reference page for `encode`,
some of the example code illustrates the use of the `decode` function.

The
example below illustrates the use of `err` and `cerr` when
the coding method is not convolutional code and the code is a binary
vector. The script encodes two five-bit messages using a cyclic code.
Each codeword has 15 bits. Errors are added to the first two bits
of the first codeword and the first bit of the second codeword. Then `decode` is
used to recover the original message. As a result, the errors are
corrected. `err` reflects the fact that the first *message* was
recovered after correcting two errors, while the second message was
recovered after correcting one error. `cerr` reflects
the fact that the first *codeword* was decoded
after correcting two errors, while the second codeword was decoded
after correcting one error.

m = 4; n = 2^m-1; % Codeword length is 15. k = 5; % Message length msg = ones(10,1); % Two messages, five bits each code = encode(msg,n,k,'cyclic'); % Encode the message. % Now place two errors in first word and one error % in the second word. Create errors by reversing bits. noisycode = code; noisycode(1:2) = bitxor(noisycode(1:2),[1 1]'); noisycode(16) = bitxor(noisycode(16),1); % Decode and try to correct the errors. [newmsg,err,ccode,cerr] = decode(noisycode,n,k,'cyclic'); disp('Transpose of err is'); disp(err') disp('Transpose of cerr is'); disp(cerr')

The output is below.

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. Transpose of err is 2 1 Transpose of cerr is 2 1

Was this topic helpful?