Documentation

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

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

enc = comm.RSEncoder(N,K) creates an RS encoder object, enc, with the CodewordLength property set to N and the MessageLength property set to K.

enc = comm.RSEncoder(N,K,GP) creates an RS encoder object, enc, with the CodewordLength property set to N, the MessageLength property set to K, and the GeneratorPolynomial property set to GP.

enc = comm.RSEncoder(N,K,GP,S) creates an RS encoder object, enc, 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.

enc = comm.RSEncoder(N,K,GP,S,Name,Value) creates an RS encoder object, enc, with the CodewordLength property set to N, the MessageLength property set to K, the GeneratorPolynomial property set to GP, the ShortMessageLength property set to S, and each specified property Name set to the specified Value.

enc = comm.RSEncoder(Name,Value) creates an RS encoder object, enc, 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

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. 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 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 ≤ M ≤ 16.

MessageLength

Message length

Specify the message length 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 CodewordLengthMessageLengthGeneratorPolynomial, 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 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 PrimitivePolynomial property.

When you set GeneratorPolynomialSource 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 row vector. The Galois row vector entries must be in the range from 0 to 2M-1. These entries must represent a generator polynomial in descending order of powers. Each coefficient is an element of the Galois field gf(2M), represented in integer format. The length of the generator polynomial must be CodewordLengthMessageLength + 1.

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 GeneratorPolynomialSource 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 the specified generator polynomial is valid. For larger codes, disabling the check speeds up processing. As a best practice, perform the check at least once before setting this property to false. This property applies when GeneratorPolynomialSource is set 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 this property to Property, you must 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. 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.

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 x3+x+1.

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 this property to Property, 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 (CodewordLengthMessageLength). 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, or logical. The default is Same as input. This property applies when you set the BitInput property to true.

Methods

cloneCreate RS encoder object with same property values
getNumInputsNumber of expected inputs to step method
getNumOutputsNumber of outputs from step method
isLockedLocked status for input attributes and nontunable properties
releaseAllow property value and input characteristics changes
stepEncode data using a Reed-Solomon encoder

Examples

expand all

Transmit an RS-encoded, 8-DPSK-modulated symbol stream

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

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 the QAM modulator, QAM demodulator, AWGN channel, and error rate System objects.

mod = comm.RectangularQAMModulator(M, ...
    'NormalizationMethod','Average power');
chan = comm.AWGNChannel('NoiseMethod','Signal to noise ratio (Eb/No)', ...
    'EbNo',15,'BitsPerSymbol',log2(M));
demod = comm.RectangularQAMDemodulator(M, ...
    'NormalizationMethod','Average power');
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 = step(mod,encodedData);
    receivedSignal = step(chan,modSignal);
    demodSignal = step(demod,receivedSignal);
    receivedBits = step(dec,demodSignal);
    dataOut = de2bi(receivedBits);
    errorStats = step(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.

Introduced in R2012a

Was this topic helpful?