Accelerating the pace of engineering and science

# comm.RSEncoder System object

Package: comm

Encode data using Reed-Solomon encoder

## Description

The RSEncoder object creates a Reed-Solomon code with message and codeword lengths you specify.

To encode data using a Reed-Solomon encoding scheme:

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

2. Call step to encode data according to the properties of comm.RSEncoder. The behavior of step is specific to each object in the toolbox.

## Construction

H = comm.RSEncoder creates a block encoder System object™, H. This object performs Reed-Solomon (RS) encoding.

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

H = comm.RSEncoder(N,K,Name,Value) creates an RS encoder object, H. This object has the CodewordLength property set to N, the MessageLength property set to K, and the other specified properties set to the specified values.

## Properties

 BitInput Assume 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 length equals an integer multiple of the message length value stored in the MessageLength property. Each group of MessageLength input elements represents one message word the object will encode. The step method outputs an encoded data output vector. The output result is a column vector of integers. The length is an integer multiple of (CodewordLength – number of punctures). You specify the number of punctures with the PuncturePatternSource and PuncturePattern properties. 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 with an integer multiple of MessageLength$×$M bits. Each group of MessageLength$×$M input bits represents one message word the object will encode. The encoded data output result is a column vector of bits. The length of this vector equals an integer multiple of (CodewordLength – number of punctures)$×$M . You specify the number of punctures with the PuncturePatternSource and PuncturePattern properties. A group of M bits represents an integer between 0 and 2M–1 that belongs to the finite Galois field GF(2M). M is the degree of the primitive polynomial that you specify with the PrimitivePolynomialSource and PrimitivePolynomial properties. CodewordLength Codeword length Specify the codeword length of the RS code as a double-precision, positive, integer scalar value. The default is 7. If you set the PrimitivePolynomialSource property to Auto, CodewordLength must be in the range 7< CodewordLength $\le$ 216–1. When you set the PrimitivePolynomialSource property to Property, CodewordLength must be in the range 7 $\le$ CodewordLength $\le$ 2M–1. M is the degree of the primitive polynomial that you specify with the PrimitivePolynomialSource and PrimitivePolynomial properties. M must be in the range 3$\le$ M $\le$ 16. For a full-length RS code, the value of this property requires the form 2M–1. If the value of this property is less than 2M–1, the object assumes a shortened RS code. MessageLength Message length Specify the message length as a double-precision, positive integer scalar value. The default is 3. PrimitivePolynomialSource Source of primitive polynomial Specify the source of the primitive polynomial as Auto | 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)), which is the result of fliplr(de2bi(primpoly(M))). When you set this property to Property, you can specify a polynomial using the PrimitivePolynomial property. PrimitivePolynomial Primitive polynomial Specify the primitive polynomial that defines the finite field GF(2M) corresponding to the integers that form messages and codewords. You must set this property to a double-precision, binary row vector that represents a primitive polynomial over GF(2) of degree M in descending order of powers. If CodewordLength is less than 2M–1, the object uses a shortened RS code. The default is the result of fliplr(de2bi(primpoly(3))), which is [1 0 1 1] or the polynomial ${x}^{M}+x+1$. This property applies when you set the PrimitivePolynomialSource property to Property. GeneratorPolynomialSource Source of generator polynomial Specify the source of the generator polynomial as Auto | Property. The default is Auto. 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 PrimitivePolynomialSource property. When you set the PrimitivePolynomialSource property to Auto the object calculates the generator polynomial as rsgenpoly(CodewordLength+SL,MessageLength+SL). When you set the PrimitivePolynomialSource property to Property, the object computes generator polynomial as rsgenpoly(CodewordLength+SL,MessageLength+SL, PrimitivePolynomial). In both cases, SL = (2M–1)–CodewordLength is the shortened length, and M is the degree of the primitive polynomial that you specify with the PrimitivePolynomialSource and PrimitivePolynomial properties. When you set this property to Property, you can 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 row vector whose entries are in the range from 0 to 2M-1and represent a generator polynomial in descending order of powers. Each coefficient is an element of Galois field GF(2M) represented in integer format. The default is the result of rsgenpoly(7,3,[],[],'double'), which evaluates to a GF(23) array with elements [1 3 1 2 3]. This property applies when you set the GeneratorPolynomialSource property to Property. CheckGeneratorPolynomial Enable generator polynomial checking Set this property to true to perform a generator polynomial check. The default is true. This check verifies that $×$CodewordLength + 1 is divisible by the generator polynomial specified in the GeneratorPolynomial property. For larger codes, disabling the check speeds up processing. You should perform the check at least once before setting this property to false. This property applies when you set the GeneratorPolynomialSource property to Property. PuncturePatternSource Source of puncture pattern Specify the source of the puncture pattern as None | Property. The default is None. If you set this property to None then the object does not apply puncturing to the code. If you set this property to Property then the object punctures the code based on a puncture pattern vector specified in the PuncturePattern property. PuncturePattern Puncture pattern vector Specify the pattern used to puncture the encoded data as a double-precision, binary column vector with a length of (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 the PuncturePatternSource property to Property. OutputDataType Data type of output Specify the output data type as Same as input | double | logical. The default is Same as input. This property applies when you set the BitInput property to true.

## Methods

 clone Create RS encoder object with same property values getNumInputs Number of expected inputs to step method getNumOutputs Number of outputs from step method isLocked Locked status for input attributes and nontunable properties release Allow property value and input characteristics changes step Encode data using a Reed-Solomon encoder

## Examples

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

```    hEnc = comm.RSEncoder;
hMod = comm.DPSKModulator('BitInput',false);
hChan = comm.AWGNChannel(...
'NoiseMethod','Signal to noise ratio (SNR)','SNR',10);
hDemod = comm.DPSKDemodulator('BitOutput',false);
hDec = comm.RSDecoder;
hError = comm.ErrorRate('ComputationDelay',3);

for counter = 1:20
data = randi([0 7], 30, 1);
encodedData = step(hEnc, data);
modSignal = step(hMod, encodedData);
end

fprintf('Error rate = %f\nNumber of errors = %d\n', ...
errorStats(1), errorStats(2))```

## Algorithms

This object implements the algorithm, inputs, and outputs described on the Binary-Input RS Encoder and Integer-Input RS Encoder block reference pages. The object properties correspond to the block parameters, except for:

 The BitInput property allows you to select between the Binary-Input RS Encoder and Integer-Input RS Encoder algorithms.