Main Content

# rsgenpoly

Generator polynomial of Reed-Solomon code

## Syntax

``genpoly = rsgenpoly(N,K)``
``genpoly = rsgenpoly(N,K,prim_poly)``
``genpoly = rsgenpoly(N,K,prim_poly,B)``
``genpoly = rsgenpoly(N,K,prim_poly,B,outputFormat)``
``[genpoly,T] = rsgenpoly(___)``

## Description

example

````genpoly = rsgenpoly(N,K)` returns the narrow-sense generator polynomial of an [`N`,`K`] Reed-Solomon code. The output `genpoly` is a Galois field array that represents the coefficients of the generator polynomial in order of descending powers. A narrow-sense BCH code is a BCH code with `B` = 1. Here, the narrow-sense generator polynomial is (X – α1)(X – α2)...(X – α`N`–`K`), where α is a root of the default primitive polynomial for the field GF(`N+1`). For additional information, see Narrow-Sense BCH Codes and Reed-Solomon Codes.```

example

````genpoly = rsgenpoly(N,K,prim_poly)` also specifies the primitive polynomial, `prim_poly`, for GF(`N`+1) that has α as a root.```

example

````genpoly = rsgenpoly(N,K,prim_poly,B)` returns the generator polynomial, (X – α`B`)(X – α`B`+1)...(X – α`B`+`N`–`K` – 1), where `B` is an integer.```

example

````genpoly = rsgenpoly(N,K,prim_poly,B,outputFormat)` specifies the output format of `genpoly` as a Galois field array or double-precision array.```

example

````[genpoly,T] = rsgenpoly(___)` also returns the error-correction capability of the [`N`,`K`] Reed-Solomon code, `T`, using any of the preceding input argument syntaxes.```

## Examples

collapse all

Specify the codeword length, `n`, and message length, `k`.

```n = 7; k = 3;```

Create the narrow-sense generator polynomial for the [n,k] Reed-Solomon code. `genpoly` is a Galois field array, by default, that represents the coefficients of this generator polynomial in order of descending powers.

`genpoly = rsgenpoly(n,k)`
``` genpoly = GF(2^3) array. Primitive polynomial = D^3+D+1 (11 decimal) Array elements = 1 3 1 2 3 ```

Create the narrow-sense generator polynomial of a Reed-Solomon code with respect to the primitive polynomial ${\mathit{D}}^{3}+{\mathit{D}}^{2}+1$.

Specify the codeword length, `n`, message length, `k`, and primitive polynomial ${\mathit{D}}^{3}+{\mathit{D}}^{2}+1$ represented in decimal form.

```n = 7; k = 3; prim_poly = 13;```

Create the narrow-sense generator polynomial for the [`n`,`k`] Reed-Solomon code with respect to primitive polynomial ${\mathit{D}}^{3}+{\mathit{D}}^{2}+1$ for GF(8). `genpoly` is a Galois field array, by default, that represents the coefficients of this generator polynomial in order of descending powers.

`genpoly = rsgenpoly(n,k,prim_poly)`
``` genpoly = GF(2^3) array. Primitive polynomial = D^3+D^2+1 (13 decimal) Array elements = 1 4 5 1 5 ```

Create the generator polynomial of a Reed-Solomon code with respect to the default primitive polynomial.

Specify the codeword length, `n`, message length, `k`, and exponent of $\alpha$, `b`.

```n = 7; k = 3; b = 4;```

Create the generator polynomial $\left(\mathit{X}-{\alpha }^{4}\right)\left(\mathit{X}-{\alpha }^{5}\right)\left(\mathit{X}-{\alpha }^{6}\right)\left(\mathit{X}-{\alpha }^{7}\right)$, with respect to the default primitive polynomial. `genpoly` is a Galois field array that represents the coefficients of this generator polynomial in order of descending powers. Display the error-correcting capability of the code.

`[genpoly,t] = rsgenpoly(n,k,[],b)`
``` genpoly = GF(2^3) array. Primitive polynomial = D^3+D+1 (11 decimal) Array elements = 1 5 5 3 2 ```
```t = 2 ```

Create the generator polynomial of a Reed-Solomon code with respect to the primitive polynomial ${\mathit{D}}^{8}+{\mathit{D}}^{4}+{\mathit{D}}^{3}+{\mathit{D}}^{2}+1$.

Specify the codeword length, `n`, message length, `k`, the primitive polynomial represented in decimal form, and the exponent of $\alpha$, `b`.

```n = 255; k = 239; prim_poly = 285; b = 0;```

Create the generator polynomial for the [`n`,`k`] Reed-Solomon code. `genpoly` is a Galois field array that represents a generator polynomial and is compliant with DVB-S and WiMAX.

`genpoly = rsgenpoly(n,k,prim_poly,b)`
``` genpoly = GF(2^8) array. Primitive polynomial = D^8+D^4+D^3+D^2+1 (285 decimal) Array elements = Columns 1 through 13 1 59 13 104 189 68 209 30 8 163 65 41 229 Columns 14 through 17 98 50 36 59 ```

Create the narrow-sense generator polynomial of a Reed-Solomon code. Specify the output data type as a double-precision array.

Specify the codeword length, `n`, and message length, `k`.

```n = 7; k = 3;```

Create the narrow-sense generator polynomial for the [`n`,`k`] Reed-Solomon code. `genpoly` is a double-precision array, that represents the coefficients of this generator polynomial in order of descending powers. Specify defaults values for the primitive polynomial and exponent of $\alpha$ inputs by assigning [ ] for them.

`genpoly = rsgenpoly(n,k,[],[],'double')`
```genpoly = 1×5 1 3 1 2 3 ```

Use the `genpoly2b` function to determine the corresponding Galois field array value.

Use `rsgenpoly` with codeword length of 7 and message word length of 3 to create a valid Galois field array.

```n = 7; k = 3; genpoly = rsgenpoly(n,k)```
``` genpoly = GF(2^3) array. Primitive polynomial = D^3+D+1 (11 decimal) Array elements = 1 3 1 2 3 ```

Use `genpoly2b` to determine the corresponding Galois field array value for the polynomial input.

`b = genpoly2b(genpoly)`
```b = 1 ```

## Input Arguments

collapse all

Codeword length, specified as an integer of the form `N` = 2M – 1, where M is in the range [3,16]. For more information, see Limitations.

Example: Set `N` to `15` for `M=4`.

Message length, specified as a positive integer. For more information, see Limitations.

Primitive polynomial, specified as a positive integer. `prim_poly` is an integer whose binary representation indicates the coefficients of the primitive polynomial. To use the default primitive polynomial GF(`N`+`1`), set `prim_poly` to `[]`. For more information, see Default Primitive Polynomials.

Example: `19` specifies the primitive polynomial `D4+D+1` because its binary representation is 10011.

Exponent of α, specified as a positive integer. α is a root of `prim_poly`.

Output format of `genpoly`, specified as:

• `'gf'` — to output a Galois field array.

• `'double'` — to output a double-precision array of the Galois field values.

For more information, see Working with Galois Fields.

## Output Arguments

collapse all

Generator polynomial coefficients in descending order, returned as a Galois field array or double-precision array. `genpoly` is a row vector that represents the coefficients of the narrow-sense generator polynomial of an [`N`,`K`] Reed-Solomon code in order of descending powers.

Error-correction capability of the code, returned as a positive integer equal to ⌊(`N``K`)/2⌋.

## Limitations

• Valid values for `N` = 2M – 1, where M is an integer in the range [3,16]. The maximum allowable value of `N` = 216 – 1 = 65,535.

• Valid values for `K` = [1,`N` – 1].

## More About

collapse all

### Default Primitive Polynomials

This table lists the default primitive polynomial used for each Galois field array GF(2`m`). To use a different primitive polynomial, specify `prim_poly` as an input argument. `prim_poly` must be in the range [(2`m` + 1), (2`m`+1 – 1)] and must indicate an irreducible polynomial. For more information, see Primitive Polynomials and Element Representations.

Value of mDefault Primitive PolynomialInteger Representation
`1`D + 13
`2`D2 + D + 17
`3`D3 + D + 111
`4`D4 + D + 119
`5`D5 + D2 + 137
`6`D6 + D + 167
`7`D7 + D3 + 1137
`8`D8 + D4 + D3 + D2 + 1285
`9`D9 + D4 + 1529
`10`D10 + D3 + 11033
`11`D11 + D2 + 12053
`12`D12 + D6 + D4 + D + 14179
`13`D13 + D4 + D3 + D + 18219
`14`D14 + D10 + D6 + D + 117475
`15`D15 + D + 132771
`16`D16 + D12 + D3 + D + 169643

## Version History

Introduced before R2006a