Decode data using a Reed-Solomon decoder
HDLRSDecoder System object™ recovers
a message vector from a Reed-Solomon codeword vector. For proper decoding,
the property values for this object should match those in the corresponding
HDLRSEncoder System object.
To recover a message vector from a Reed-Solomon codeword vector optimized for HDL code generation:
Define and set up your HDL RS decoder object. See Construction.
step to recover a message
vector from a Reed-Solomon codeword vector according to the properties
comm.HDLRSDecoder. The behavior of
specific to each object in the toolbox.
Starting in R2016b, instead of using the
Each input frame must contain more than
and fewer than or equal to
N symbols. A shortened
code is inferred when the number of valid data samples between
N. A shortened code still requires
to perform the Chien search. If the input is less than
leave a guard interval of at least
cycles before starting the next frame.
The decoder can operate on up to 4 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 code word 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
H = comm.HDLRSDecoder creates an HDL-optimized
RS decoder System object,
H, that performs
Reed-Solomon (RS) decoding.
H = comm.HDLRSDecoder(Name,Value) creates
an HDL-optimized RS decoder System object,
with additional options specified by one or more
arguments, where Name is a property name and Value is the corresponding
value. Name must appear inside single quotes (
You can specify several name-value pair arguments in any order as
H = comm.HDLRSDecoder(N,K,Name,Value) creates
an HDL-optimized RS decoder System object,
CodewordLength property set to
MessageLength property set to
and other specified property names set to the specified values.
B value for polynomial generation
Source of B, the starting power for roots of the primitive polynomial
Specify the source of the B value as one of these values:
Specify the codeword length of the RS code as a double-precision,
positive, integer scalar value. The default is
If you set the
When you set the
If the value of this property is less than 2M–1, the object assumes a shortened RS code.
Specify the message length as a double-precision, positive integer
scalar value. The default is
Enable number of errors output
When you set this property to true, the step method outputs number of corrected errors. The number of corrected errors is not valid when errOut is asserted, since there were more errors than could be corrected. The default is false.
Source of primitive polynomial
Specify the source of the primitive polynomial as
When you set this property to
Specify the primitive polynomial that defines the finite field
This property applies when you set the
|step||Perform Reed-Solomon decoding|
|Common to All System Objects|
Create System object with same property values
Expected number of inputs to a System object
Expected number of outputs of a System object
Check locked states of a System object (logical)
Allow System object property value changes
Create an HDLRSEncoder object with RS(255,239) code. This is the code used in the IEEE802.16 Broadband Wireless Access standard.
B is the starting power of the roots of the primitive polynomial.
rsEnc = comm.HDLRSEncoder(255,239,'BSource','Property','B',0)
rsEnc = comm.HDLRSEncoder with properties: CodewordLength: 255 MessageLength: 239 PrimitivePolynomialSource: 'Auto' PuncturePatternSource: 'None' BSource: 'Property' B: 0
Create a random message to encode. This message is smaller than the codeword length to demonstrate the shortened-code capability of the objects. Pad the message with zeros to accommodate the Chien search in the decoder and the decoder latency.
Note: This object syntax runs only in R2016b or later. If you are using an earlier release, replace each call of an object with the equivalent
step syntax. For example, replace
messageLength = 188; dataIn = [randi([0,255],1,messageLength,'uint8') zeros(1,1024-messageLength)]; for ii = 1:1024 messageStart = (ii==1); messageEnd = (ii==messageLength); validIn = (ii<=messageLength); [encOut(ii),startOut(ii),endOut(ii),validOut(ii)] = rsEnc(dataIn(ii),messageStart,messageEnd,validIn); end
Inject errors at random locations in the encoded message. Reed-Solomon can correct up to (N-K)/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.
Create an RS Decoder to detect and correct errors in the message. It must have the same code and polynomial as the encoder.
rsDec = comm.HDLRSDecoder(255,239,'BSource','Property','B',0) for ii = 1:1024 [decOut(ii),decStartOut(ii),decEndOut(ii),decValidOut(ii),decErrOut(ii)] = rsDec(encOut(ii),startOut(ii),endOut(ii),validOut(ii)); end
rsDec = comm.HDLRSDecoder with properties: CodewordLength: 255 MessageLength: 239 PrimitivePolynomialSource: 'Auto' BSource: 'Property' B: 0 NumErrorsOutputPort: false
Select the valid decoder output and compare 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.
For C/C++ code generation, these usage notes and limitations apply:
See System Objects in MATLAB Code Generation (MATLAB Coder).