Accelerating the pace of engineering and science

# rsenc

Reed-Solomon encoder

## Syntax

code = rsenc(msg,n,k)
code = rsenc(msg,n,k,genpoly)
code = rsenc(...,paritypos)

## Description

code = rsenc(msg,n,k) encodes the message in msg using an [n,k] Reed-Solomon code with the narrow-sense generator polynomial. msg is a Galois array of symbols having m bits each. Each k-element row of msg represents a message word, where the leftmost symbol is the most significant symbol. n is at most 2m-1. If n is not exactly 2m-1, rsenc uses a shortened Reed-Solomon code. Parity symbols are at the end of each word in the output Galois array code.

code = rsenc(msg,n,k,genpoly) is the same as the syntax above, except that a nonempty value of genpoly specifies the generator polynomial for the code. In this case, genpoly is a Galois row vector that lists the coefficients, in order of descending powers, of the generator polynomial. The generator polynomial must have degree n-k. To use the default narrow-sense generator polynomial, set genpoly to [].

code = rsenc(...,paritypos) specifies whether rsenc appends or prepends the parity symbols to the input message to form code. The string paritypos can be either 'end' or 'beginning'. The default is 'end'.

## Examples

The example below encodes two message words using a (7,3) Reed-Solomon encoder.

```m = 3; % Number of bits per symbol
n = 2^m-1; k = 3; % Word lengths for code
msg = gf([2 7 3; 4 0 6],m); % Two rows of m-bit symbols
code = rsenc(msg,n,k)```

The output is below.

```code = GF(2^3) array. Primitive polynomial = D^3+D+1 (11 decimal)

Array elements =

2     7     3     3     6     7     6
4     0     6     4     2     2     0
```

For additional examples, see Represent Words for Reed-Solomon Codes and Create and Decode Reed-Solomon Codes.

## Limitations

n and k must differ by an integer. n between 7 and 65535.