Block encoder

`code = encode(msg,n,k,'`

`linear/`

* fmt*',genmat)

code = encode(msg,n,k,'

`cyclic/`

`fmt`

`poly`

)code = encode(msg,n,k,'

`hamming/`

`fmt`

code = encode(msg,n,k)

[code,added] = encode(...)

The `encode`

function encodes messages using
one of the following error-correction coding methods:

Linear block

Cyclic

Hamming

For all of these methods, the codeword length is `n`

and
the message length is `k`

.

`msg`

, which represents the messages, can have
one of several formats. The table Information Formats below shows which formats are
allowed for `msg`

, how the argument * fmt* should
reflect the format of

`msg`

, and how the format of
the output `code`

depends on these choices. The examples
in the table are for `k = 4`

. If `fmt`

`binary`

format.
This is because the function uses a binary format internally, while
the roundoff error associated with converting many bits to large decimal
numbers and back might be substantial.`decimal` |

**Information Formats**

Dimension
of `msg` | Value of fmt Argument | Dimension of `code` |
---|---|---|

Binary column or row vector | `binary` | Binary column or row vector |

Example: ```
msg = [0 1 1
0, 0 1 0 1, 1 0 0 1].'
``` | ||

Binary matrix with `k` columns | `binary` | Binary matrix with `n` columns |

Example: ```
msg = [0 1 1
0; 0 1 0 1; 1 0 0 1]
``` | ||

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` ] |

Example: ```
msg = [6, 10,
9].'
``` |

`code = encode(msg,n,k,'`

encodes `linear/`

* fmt*',genmat)

`msg`

using `genmat`

as
the generator matrix for the linear block encoding method. `genmat`

,
a `k`

-by-`n`

matrix, is required
as input.`code = encode(msg,n,k,'`

encodes `cyclic/`

* fmt*',gen

`poly`

)`msg`

and
creates a systematic cyclic code. `genpoly`

is a polynomial
string or a row vector that gives the coefficients, in order
of ascending powers, of the binary generator polynomial. 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 x`code = encode(msg,n,k,'`

encodes `hamming/`

* fmt*',prim_poly)

`msg`

using
the Hamming encoding method. For this syntax, `n`

must
have the form 2`k`

must equal `n`

-m. `prim_poly`

is
a polynomial string or
a row vector that gives the binary coefficients, in order of ascending
powers, of the primitive polynomial for GF(2`prim_poly`

is
the default primitive polynomial `gfprimdf`

(m).`code = encode(msg,n,k)`

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

.

`[code,added] = encode(...)`

returns
the additional variable `added`

. `added`

is
the number of zeros that were placed at the end of the message matrix
before encoding in order for the matrix to have the appropriate shape.
"Appropriate" depends on `n`

, `k`

,
the shape of `msg`

, and the encoding method.

Was this topic helpful?