This example shows how to configure the `RSEncoder`

and `RSDecoder`

System
objects to perform Reed-Solomon (RS) block coding with erasures when
simulating a communications system. RS decoders can correct both errors
and erasures. A receiver that identifies the most unreliable symbols
in a given codeword can generate erasures. When a receiver erases
a symbol, it replaces that symbol with a zero. The receiver then passes
a flag to the decoder, indicating that the symbol is an erasure, not
a valid code symbol. In addition, an encoder can generate punctures
for which specific parity symbols are always removed from its output.
The decoder, which knows the puncture pattern, inserts zeros in the
puncture positions and treats those symbols as erasures. The decoder
treats encoder-generated punctures and receiver-generated erasures
the exact same way when it decodes a symbol. Puncturing also has the
added benefit of making the code rate more flexible, at the expense
of some error correction capability. Shortened codes achieve the same
code rate flexibility without degrading the error correction performance,
given the same demodulator input energy per bit to noise power spectral
density ratio (*E _{b}/N_{0}*).
Note that puncturing is the removal of parity symbols from a codeword,
and shortening is the removal of message symbols from a codeword.
In addition to this example, the examples "Reed-Solomon Coding
Part II – Punctures" and "Reed-Solomon Coding
Part III – Shortening" show RS block coding with punctures
and shortened codes, respectively.

**Introduction**

This example shows the simulation of a communication system consisting of a random source, an RS encoder, a rectangular 64-QAM modulator, an AWGN channel, a rectangular 64-QAM demodulator, and an RS decoder. It includes analysis of RS coding with erasures by comparing the channel bit error rate (BER) performance versus the coded BER performance. This example obtains Channel BER by comparing inputs for the rectangular QAM modulator to outputs from the rectangular QAM demodulator. This example obtains Coded BER by comparing inputs for the RS encoder to outputs from the RS decoder. THIS IS FLAWED!

**Initialization**

The script file RSCodingConfigExample configures
the rectangular 64-QAM modulator and demodulator, the AWGN channel,
and the error rate measurement System objects used to simulate the
communications system. The script also sets an uncoded *E _{b}/N_{0}* ratio
to EbNoUncoded = 15 dB, and sets the simulation stop criteria by defining
the target number of errors and the maximum number of bit transmissions
to 500 and 5×10

RSCodingConfigExample

**Configuring the RS Encoder/Decoder**

This example shows a (63,53) RS code operating with a 64-QAM modulation scheme. This code can correct (63-53)/2 = 5 errors, or it can alternatively correct (63-53) = 10 erasures. For each codeword at the output of the 64-QAM demodulator, the receiver determines the six least reliable symbols using the RSCodingGetErasuresExample function. The indices that point to the location of these unreliable symbols are passed as an input to the RS decoder. The RS decoder treats these symbols as erasures resulting in an error correction capability of (10-6)/2 = 2 errors per codeword.

Create a (63,53) `RSEncoder`

System object and
set the `BitInput`

property to `false`

to
specify that the encoder inputs and outputs are integer symbols.

N = 63; % Codeword length K = 53; % Message length rsEncoder = comm.RSEncoder(N,K, 'BitInput', false); numErasures = 6;

Create an `RSDecoder`

System object using
the same settings as in the encoder. Request an additional input for
specifying erasures as an input to the object. This is done by setting
the `ErasuresInputPort`

property to `true`

.

rsDecoder = comm.RSDecoder(N,K, 'BitInput', false, 'ErasuresInputPort', true);

Set the `NumCorrectedErrorsOutputPort`

property
to `true`

so that the decoder outputs the number
of corrected errors. A non negative value in the error output denotes
the number of corrected errors in the input codeword. A value of −1
in the error output indicates a decoding error. A decoding error occurs
when the input codeword has more errors than the error correction
capability of the RS code.

rsDecoder.NumCorrectedErrorsOutputPort = true;

**Stream Processing Loop**

Simulate the communications system for an uncoded *E _{b}/N_{0}* ratio
of 15 dB. The uncoded

The signal going into the AWGN channel is the encoded signal,
so you must convert the uncoded *E*_{b}/*N*_{0} values
so that they correspond to the energy ratio at the encoder output.
This ratio is the coded *E _{b}*/

`EbNo`

property of the AWGN channel object
to the computed coded EbNoCoded = EbNoUncoded + 10*log10(K/N); channel.EbNo = EbNoCoded;

Loop until the simulation reaches the target number of errors or the maximum number of transmissions.

chanErrorStats = zeros(3,1); codedErrorStats = zeros(3,1); correctedErrors = 0; while (codedErrorStats(2) < targetErrors) && ... (codedErrorStats(3) < maxNumTransmissions) % Data symbols - transmit 1 message word at a time. Each message word has % K symbols in the [0 N] range. data = randi([0 N],K,1); % Encode the message word. The encoded word encData is N symbols long. encData = rsEncoder(data); % Modulate encoded data. modData = qamModulator(encData); % Add noise. chanOutput = channel(modData); % Demodulate channel output. demodData = qamDemodulator(chanOutput); % Find the 6 least reliable symbols and generate an erasures vector using % the RSCodingGetErasuresExample function. The length of the erasures vector % must be equal to the number of symbols in the demodulated codeword. A % one in the ith element of the vector erases the ith symbol in the % codeword. Zeros in the vector indicate no erasures. erasuresVec = RSCodingGetErasuresExample(chanOutput, numErasures); % Decode data. [estData, errs] = rsDecoder(demodData,erasuresVec); % If a decoding error did not occur, accumulate the number of corrected % errors using the cumulative sum object. if errs >= 0 correctedErrors = cumulativeSum(errs); end % Convert integers to bits and compute the channel BER. chanErrorStats(:,1) = ... chanBERCalc(intToBit1(encData),intToBit1(demodData)); % Convert integers to bits and compute the coded BER. codedErrorStats(:,1) = ... codedBERCalc(intToBit2(data),intToBit2(estData)); end

The error rate measurement objects, `chanBERCalc`

and `codedBERCalc`

,
output 3-by-1 vectors containing BER measurement updates, the number
of errors, and the total number of bit transmissions. Display the
coded BER and the total number of errors corrected by the RS decoder.

codedBitErrorRate = codedErrorStats(1) totalCorrectedErrors = correctedErrors

codedBitErrorRate = 0 totalCorrectedErrors = 882

You can add a for loop around the processing loop above
to run simulations for a set of *E _{b}/N_{0}* values.
Simulations were run offline for uncoded

**Summary**

This example utilized several System objects to simulate a rectangular 64-QAM communications system over an AWGN channel with RS block coding. It showed how to configure the RS decoder to decode symbols with erasures. System performance was measured using channel and coded BER curves obtained using error rate measurement System objects.

The examples "Reed-Solomon Coding Part II − Punctures" and "Reed-Solomon Coding Part III − Shortening" show how to perform RS block coding with punctured and shortened codes, respectively.

**Appendix**

This example uses the following script and helper function:

**Selected Bibliography**

[1] G. C. Clark, Jr., J. B. Cain, *Error-Correction
Coding for Digital Communications*, Plenum Press, New York,
1981.

Was this topic helpful?