Main Content

comm.HDLRSDecoder

Decode message using Reed-Solomon decoder

Description

The HDL-optimized HDLRSDecoder System object™ recovers a message vector from a Reed-Solomon (RS) codeword vector. For proper decoding, the code and polynomial property values for this object must match those values in the corresponding encoder.

To recover a message vector from a Reed-Solomon codeword vector:

  1. Create the comm.HDLRSDecoder object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?

Troubleshooting

  • Each input frame must contain more than (N-K)*2 symbols and fewer than or exactly N symbols. The object infers a shortened code when the number of valid data samples between startIn and endIn is less than N. A shortened code still requires N cycles to perform the Chien search. If the input message is less than N symbols, leave a guard interval of at least N - size inactive cycles before starting the next frame, where sizeis the message length.

  • The decoder can operate on up to four messages at a time. If the object receives the start of a fifth message before completely decoding the first message, the object drops data samples from the first message. To avoid this issue, increase the number of inactive cycles between input messages.

  • The generator polynomial is not specified explicitly. However, it is defined by the codeword length, the message length, and the B value for the starting exponent of the roots. To get the value of B from a generator polynomial, use the genpoly2b function.

Creation

Description

RSDec = comm.HDLRSDecoder creates an HDL-optimized RS decoder System object, RSDec, that performs Reed-Solomon decoding.

RSDec = comm.HDLRSDecoder(Name,Value) sets properties using one or more name-value pairs. Enclose each property name in single quotes. For example,

comm.HDLRSDecoder('BSource','Property','B',2) 
sets a starting power of 2 for the roots of the primitive polynomial.

RSDec = comm.HDLRSDecoder(N,K,Name,Value) sets the CodewordLength property to N, the MessageLength property to K, and other specified property names to the specified values.

example

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

Starting power for roots of the primitive polynomial, specified as a positive integer.

Dependencies

The object uses this value when you set BSource to 'Property'.

Source of the starting power for roots of the primitive polynomial, specified as either 'Property' or 'Auto'. When you select 'Auto', the object uses B = 1.

Number of symbols, N, in the RS codeword, specified as a positive integer. This value is rounded up to 2M–1. M is the degree of the primitive polynomial, as specified by the PrimitivePolynomialSource and PrimitivePolynomial properties. The difference of CodewordLengthMessageLength must be an even integer.

If the value of this property is less than 2M–1, the object assumes a shortened RS code.

If you set PrimitivePolynomialSource to 'Auto', then CodewordLength must be in the range 3 < CodewordLength ≤ 216 – 1.

If you set PrimitivePolynomialSource to 'Property', then CodewordLength must be in the range 3 ≤ CodewordLength ≤ 2M– 1. M must be in the range 3 ≤ M ≤ 16.

Message length, K, specified as a positive integer. The difference of CodewordLengthMessageLength must be an even integer.

When you set this property to true, the object returns the number of corrected errors. The number of corrected errors is not valid when errOut is true, since there were more errors than could be corrected.

Source of the primitive polynomial, specified as either 'Property' or '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 int2bit(primpoly(M),bpi)', where bpi is the number of bits per integer.

  • When you set this property to 'Property', you must specify a polynomial using the PrimitivePolynomial property.

Primitive polynomial, specified as a binary row vector that represents a primitive polynomial over gf(2) of degree M, in descending order of powers. The polynomial defines the finite field gf(2M) corresponding to the integers that form messages and codewords.

Dependencies

The object uses this value when you set PrimitivePolynomialSource to 'Property'.

Usage

Description

[Y,startOut,endOut,validOut,errOut] = RSDec(X,startIn,endIn,validIn) decodes one encoded message symbol, X, and returns the decoded symbol Y. The start and end signals indicate the message frame boundaries. If errOut is 1 (true), then the object detected uncorrectable errors in the input frame.

example

[Y,startOut,endOut,validOut,errOut,numErrors] = RSDec(X,startIn,endIn,validIn) decodes the input data, and also returns the number of errors detected and corrected. To use this syntax, set the NumErrorsOutputPort property to true. If errOut is 1 (true), then the object detected uncorrectable errors in the output frame, and numErrors is invalid.

Input Arguments

expand all

Input message data and parity symbols, one symbol at a time, specified as an unsigned integer or fi() with any binary point scaling.

double type is allowed for simulation but not supported for HDL code generation.

Data Types: double | uint8 | uint16 | uint32 | fi

Start of input data frame, specified as a logical scalar.

Data Types: logical

End of input data frame, specified as a logical scalar.

Data Types: logical

Validity of input data, specified as a logical scalar.

Data Types: logical

Output Arguments

expand all

Message data symbols, returned one symbol at a time, as an integer with the same data type as the input message, X.

Data Types: double | uint8 | uint16 | uint32 | fi

Start of output data frame, returned as a logical scalar.

Data Types: logical

End of output data frame, returned as a logical scalar.

Data Types: logical

Validity of output data, returned as a logical scalar.

Data Types: logical

Uncorrectable error in output data frame, returned as a logical scalar. This signal is 1 (true) when the message frame contains uncorrectable errors. In this case, the output data symbols are corrupted. This value is valid when endOut is 1 (true).

Data Types: logical

Number of errors detected and corrected, returned as an integer. This value is valid when endOut is 1 (true) and errOut is 0 (false).

Data Types: uint8

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

expand all

stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

collapse all

Encode and decode a signal using Reed Solomon encoder and decoder System objects. This example shows how to include each object in a function for HDL code generation.

Create a random message to encode. This message is smaller than the codeword length to show how the objects support shortened codes. Pad the message with zeros to accommodate the latency of the decoder, including the Chien search.

messageLength = 188;
dataIn = [randi([0,255],1,messageLength,'uint8') zeros(1,1024-messageLength)];

Write a function that creates and calls a HDLRSEncoder System object™ with an RS(255,239) code. This code is used in the IEEE® 802.16 Broadband Wireless Access standard. B is the starting power of the roots of the primitive polynomial. You can generate HDL from this function.

function  [dataOut,startOut,endOut,validOut] = HDLRSEnc80216(dataIn,startIn,endIn,validIn)
%HDLRSEnc80216 
% Processes one sample of data using the comm.HDLRSEncoder System object(TM)
% dataIn is a uint8 scalar, representing 8 bits of binary data. 
% startIn, endIn, and validIn are logical scalar values.
% You can generate HDL code from this function.

  persistent rsEnc80216;
  if isempty(rsEnc80216)
    rsEnc80216 = comm.HDLRSEncoder(255,239,'BSource','Property','B',0)
  end    
  [dataOut,startOut,endOut,validOut] = rsEnc80216(dataIn,startIn,endIn,validIn);
end

% Copyright 2019-2022 The MathWorks, Inc.

Call the function to encode the message.

for ii = 1:1024
    messageStart = (ii==1);
    messageEnd = (ii==messageLength);
    validIn = (ii<=messageLength);
    [encOut(ii),startOut(ii),endOut(ii),validOut(ii)] = ...
        HDLRSEnc80216(dataIn(ii),messageStart,messageEnd,validIn);
end
rsEnc80216 = 

  comm.HDLRSEncoder with properties:

               CodewordLength: 255
                MessageLength: 239
    PrimitivePolynomialSource: 'Auto'
        PuncturePatternSource: 'None'
                      BSource: 'Property'
                            B: 0

Inject errors at random locations in the encoded message. Reed-Solomon can correct up to (NK)/2 errors in each N symbols. So, in this example, the error correction capability is (255 – 239)/2=8 symbols.

numErrors = 8;
loc = randperm(messageLength,numErrors);
% encOut is qualified by validOut, use an offset for injecting errors
vi = find(validOut==true,1);
for i = 1:numErrors
   idx = loc(i)+vi;
   symbol = encOut(idx);
   encOut(idx) = randi([0 255],'uint8');
   fprintf('Symbol(%d): was 0x%x, now 0x%x\n',loc(i),symbol,encOut(idx))
end
Symbol(147): was 0x1f, now 0x82
Symbol(16): was 0x6b, now 0x82
Symbol(173): was 0x3, now 0xd1
Symbol(144): was 0x66, now 0xcb
Symbol(90): was 0x13, now 0xa4
Symbol(80): was 0x5a, now 0x60
Symbol(82): was 0x95, now 0xcf
Symbol(56): was 0xf5, now 0x88

Write a function that creates and calls a HDLRSDecoder System object™. This object must have the same code and polynomial as the encoder. You can generate HDL from this function.

function  [dataOut,startOut,endOut,validOut,err] = HDLRSDec80216(dataIn,startIn,endIn,validIn)
%HDLRSDec80216 
% Processes one sample of data using the comm.HDLRSDecoder System object(TM)
% dataIn is a uint8 scalar, representing 8 bits of binary data. 
% startIn, endIn, and validIn are logical scalar values.
% You can generate HDL code from this function.

  persistent rsDec80216;
  if isempty(rsDec80216)
    rsDec80216 = comm.HDLRSDecoder(255,239,'BSource','Property','B',0)
  end    
  [dataOut,startOut,endOut,validOut,err] = rsDec80216(dataIn,startIn,endIn,validIn);
end

% Copyright 2019-2022 The MathWorks, Inc.

Call the function to detect errors in the encoded message.

for ii = 1:1024
 [decOut(ii),decStartOut(ii),decEndOut(ii),decValidOut(ii),decErrOut(ii)] = ...
     HDLRSDec80216(encOut(ii),startOut(ii),endOut(ii),validOut(ii));
end
rsDec80216 = 

  comm.HDLRSDecoder with properties:

               CodewordLength: 255
                MessageLength: 239
    PrimitivePolynomialSource: 'Auto'
                      BSource: 'Property'
                            B: 0
          NumErrorsOutputPort: false

Select the valid decoder output and compare the decoded symbols to the original message.

decOut = decOut(decValidOut==1);
originalMessage = dataIn(1:messageLength);
if all(originalMessage==decOut)
    fprintf('All %d message symbols were correctly decoded.\n',messageLength)
else
   for jj = 1:messageLength
      if dataIn(jj)~=decOut(jj)
        fprintf('Error in decoded symbol(%d). Original 0x%x, Decoded 0x%x.\n',jj,dataIn(jj),decOut(jj))
      end
   end
end
All 188 message symbols were correctly decoded.

Extended Capabilities

Version History

Introduced in R2012b