Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

# comm.RSDecoder

Decode data using Reed-Solomon decoder

## Description

The `RSDecoder` object recovers a message vector from a Reed-Solomon codeword vector. For proper decoding, the property values for this object should match the property values in the corresponding RS Encoder object.

To decode data using a Reed-Solomon decoding scheme:

1. Define and set up your Reed-Solomon decoder object. See Construction.

2. Call `step` to decode data according to the properties of `comm.RSDecoder`. The behavior of `step` is specific to each object in the toolbox.

### Note

Starting in R2016b, instead of using the `step` method to perform the operation defined by the System object™, you can call the object with arguments, as if it were a function. For example, ```y = step(obj,x)``` and `y = obj(x)` perform equivalent operations.

## Construction

`dec = comm.RSDecoder` creates a block decoder System object, `dec`. This object performs Reed-Solomon (RS) decoding.

`dec = comm.RSDecoder(N,K)` creates an RS decoder object, `dec` with the `CodewordLength` property set to `N` and the `MessageLength` property set to `K`.

`dec = comm.RSDecoder(N,K,GP)` creates an RS decoder object, `dec` with the `CodewordLength` property set to `N`, the `MessageLength` property set to `K`, and the `GeneratorPolynomial` property set to `GP`.

`dec = comm.RSDecoder(N,K,GP,S)` creates an RS decoder object, `dec` with the `CodewordLength` property set to `N`, the `MessageLength` property set to `K`, the `GeneratorPolynomial` property set to `GP`, and the `ShortMessageLength` property set to `S`.

`dec = comm.RSDecoder(N,K,GP,S,Name,Value)` creates an RS decoder object, `dec` with the `CodewordLength` property set to `N`, the `MessageLength` property set to `K`, the `GeneratorPolynomial` property set to `GP`, and each specified property `Name` set to the specified `Value`.

`dec = comm.RSDecoder(Name,Value)` creates an RS decoder object, `dec`, with each specified property name set to the specified value. You can specify additional name-value pair arguments in any order as (`Name1`,`Value1`,...,`NameN`,`ValueN`).

## Properties

### Note

The input and output signal lengths are listed in Input and Output Signal Lengths in BCH and RS System Objects on the `comm.BCHDecoder` reference page.

 `BitInput` Assume that input is bits Specify whether the input comprises bits or integers. The default is `false`. When you set this property to `false`, the `step` method input data value must be a numeric, column vector of integers. The `step` method outputs an encoded data output vector. The output result is a column vector of integers. Each symbol that forms the input message and output codewords is an integer between 0  and 2M – 1. These integers correspond to an element of the finite Galois field `gf`(2M). M is the degree of the primitive polynomial that you specify with the `PrimitivePolynomialSource` and `PrimitivePolynomial` properties. When you set this property to `true`, the input value must be a numeric, column vector of bits. The encoded data output result is a column vector of bits. `CodewordLength` Codeword length Specify the codeword length of the RS code in symbols as a double-precision, positive, integer scalar value. The default is `7`. For a full-length RS code, the value of this property must be 2M–1, where M is an integer such that 3$\le$M $\le$16. `MessageLength` Message length Specify the message length in symbols as a double-precision positive integer scalar value. The default is `3`. `ShortMessageLengthSource` Short message length source Specify the source of the shortened message as  `Auto` or `Property`. When this property is set to `Auto`, the RS code is defined by the `CodewordLength`, `MessageLength`, `GeneratorPolynomial`, and `PrimitivePolynomial` properties. When `ShortMessageLengthSource` is set to `Property`, you must specify the `ShortMessageLength` property, which is used with the other properties to define the RS code. The default is `Auto`. `ShortMessageLength` Shortened message length Specify the length of the shortened message in symbols as a double-precision positive integer scalar whose value must be less than or equal to `MessageLength`. When `ShortMessageLength` < `MessageLength`, the RS code is shortened. The default is `3`. `GeneratorPolynomialSource` Source of generator polynomial Specify the source of the generator polynomial as `Auto` or `Property`. The default is `Auto`. When you set this property to `Auto`, the object chooses the generator polynomial automatically. The object calculates the generator polynomial based on the value of the `PrimitivePolynomialSource` property. When you set this property to `Auto`, the object automatically chooses the generator polynomial. The object calculates the generator polynomial based on the value of the `PrimitivePolynomial`  property. When you set this property to Property, you must specify a generator polynomial using the `GeneratorPolynomial`  property. `GeneratorPolynomial` Generator polynomial Specify the generator polynomial for the RS code as a double-precision integer row vector or as a Galois field row vector whose entries are in the range from 0 to 2M–1 and represent a generator polynomial in descending order of powers. The length of the generator polynomial must be `CodewordLength`-`MessageLength`+1. This property applies when you set `GeneratorPolynomialSource` to `Property`. The default is the result of `rsgenpoly(7,3,[],[],'double')`, which corresponds to `[1 3 1 2 3]`. When you use this object to generate code, you must set the generator polynomial to a double-precision integer row vector. `CheckGeneratorPolynomial` Enable generator polynomial checking Set this property to `true` to perform a generator polynomial check. The default is `true`. This check verifies that the specified generator polynomial is valid. For larger codes, disabling the check accelerates processing time. As a best practice, perform the check at least once before setting this property to `false`. This property applies when you set `GeneratorPolynomialSource` to `Property`. `PrimitivePolynomialSource` Source of primitive polynomial Specify the source of the primitive polynomial as `Auto` or `Property`. The default is `Auto`. When you set this property to `Auto`, the object uses a primitive polynomial of degree M = `ceil`(log2(`CodewordLength`+1)). When you set`PrimitivePolynomialSource` to `Property`, you must specify a polynomial using `PrimitivePolynomial`. `PrimitivePolynomial` Primitive polynomial Specify the primitive polynomial that defines the finite field `gf`(2M) corresponding to the integers that form messages and codewords. The default is the result of `fliplr`(`de2bi`(`primpoly`(3))), which is `[1 0 1 1]` or the polynomial ${x}^{3}+x+1$. Specify this property as a double-precision, binary, row vector that represents a primitive polynomial over `GF`(2) of degree M in descending order of powers. This property applies when you set `PrimitivePolynomialSource` to `Property`. `PuncturePatternSource` Source of puncture pattern Specify the source of the puncture pattern as `None` or `Property`. The default is `None`. If you set this property to `None`, the object does not apply puncturing to the code. If you set it to `Property`, the object punctures the code based on a puncture pattern vector specified in `PuncturePattern`. `PuncturePattern` Puncture pattern vector Specify the pattern used to puncture the encoded data as a double-precision, binary column vector of length (`CodewordLength`-`MessageLength`). The default is `[ones(2,1); zeros(2,1)]`. Zeros in the puncture pattern vector indicate the position of the parity symbols that are punctured or excluded from each codeword. This property applies when you set `PuncturePatternSource` to `Property`. `ErasuresInputPort` Enable erasures input Set this property to `true` to specify a vector of erasures as an input to the `step` method. The default is `false`. The erasures input must be a double-precision or logical binary column vector that indicates which symbols of the input codewords to erase. The length of the erasures vector is explained in Input and Output Signal Lengths in BCH and RS System Objects. When this property is set to `false`, the object assumes no erasures. `NumCorrectedErrorsOutputPort` Enable number of corrected errors output Set this property to `true` to obtain the number of corrected errors as an output to the `step` method. The default is `true`. A nonnegative value in the i-th element of the error output vector, denotes the number of corrected errors in the i-th input codeword. A value of `-1` in the i-th element of the error output vector indicates that a decoding error occurred for that codeword. A decoding error occurs when an input codeword has more errors than the error correction capability of the RS code. `OutputDataType` Data type of output Specify the output data type as `Same as input`, `double`, or `logical`. The default is `Same as input`. This property applies when you set `BitInput` to `true`.

## Methods

 step Decode data using a Reed-Solomon decoder
Common to All System Objects
`release`

Allow System object property value changes

## Examples

expand all

Transmit an RS-encoded, 8-DPSK-modulated symbol stream through an AWGN channel. Then, demodulate, decode, and count errors.

``` enc = comm.RSEncoder; mod = comm.DPSKModulator('BitInput',false); chan = comm.AWGNChannel(... 'NoiseMethod','Signal to noise ratio (SNR)','SNR',10); demod = comm.DPSKDemodulator('BitOutput',false); hDdecec = comm.RSDecoder; errorRate = comm.ErrorRate('ComputationDelay',3); for counter = 1:20 data = randi([0 7], 30, 1); encodedData = step(enc, data); modSignal = step(mod, encodedData); receivedSignal = step(chan, modSignal); demodSignal = step(demod, receivedSignal); receivedSymbols = step(hDdecec, demodSignal); errorStats = step(errorRate, data, receivedSymbols); end fprintf('Error rate = %f\nNumber of errors = %d\n', ... errorStats(1), errorStats(2))```
```Error rate = 0.115578 Number of errors = 69 ```

Transmit a shortened RS-encoded, 256-QAM-modulated symbol stream through an AWGN channel. Then demodulate, decode, and count errors.

Set the parameters for the Reed-Solomon code, where `N` is the codeword length, `K` is the nominal message length, and `S` is the shortened message length. Set the modulation order, `M`, and the number of frames, `L`.

```N = 255; K = 239; S = 188; M = 256; L = 50;```

Create an AWGN channel System object and an error rate System object.

```awgnChan = comm.AWGNChannel('NoiseMethod','Signal to noise ratio (Eb/No)', ... 'EbNo',15,'BitsPerSymbol',log2(M)); errorRate = comm.ErrorRate('ComputationDelay',3);```

Create the Reed-Solomon generator polynomial from the DVB-T standard.

`gp = rsgenpoly(N,K,[],0);`

Create a Reed-Solomon encoder and decoder pair using the shortened message length, `S`, and the DVB-T generator polynomial, `gp`.

```enc = comm.RSEncoder(N,K,gp,S); dec = comm.RSDecoder(N,K,gp,S);```

Generate random symbol frames whose length equals one message block. Encode, modulate, apply AWGN, demodulate, decode, and collect statistics.

```for counter = 1:L data = randi([0 1],S,log2(M)); encodedData = step(enc,bi2de(data)); modSignal = qammod(encodedData,M,'UnitAveragePower',true); rxSignal = awgnChan(modSignal); demodSignal = qamdemod(rxSignal,M,'UnitAveragePower',true); rxBits = dec(demodSignal); dataOut = de2bi(rxBits); errorStats = errorRate(data(:),dataOut(:)); end```

Display the error rate and number of errors.

```fprintf('Error rate = %5.2e\nNumber of errors = %d\n', ... errorStats(1), errorStats(2))```
```Error rate = 2.01e-02 Number of errors = 1509 ```

## Algorithms

This object implements the algorithm, inputs, and outputs described in Algorithms for BCH and RS Errors-only Decoding.