This example shows how to set up the Reed-Solomon (RS) encoder/decoder to shorten the (63,53) code to a (28,18) code.

In addition to this example, the examples "Reed-Solomon
Coding Part I – Erasures" and "Reed-Solomon Coding
Part II – Punctures" show a rectangular 64-QAM communications
system with a (63,53) RS block code with erasures and punctures respectively.
As was mentioned in the two examples, puncturing has the 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 *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.

**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 analyzes the effects of RS coding with erasures, puncturing, and shortening, 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.

**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**

Consider the same (63,53) RS code operating in concert with a 64-QAM modulation scheme that was used in the examples Reed-Solomon Coding Part I - Erasures and Reed-Solomon Coding Part II - Punctures to showcase how to decode erasures and how to puncture the code. This example shows how to shorten the (63,53) code to a (28,18) code.

Shortening a block code removes symbols from its message portion, while puncturing removes symbols from its parity portion. You can incorporate both techniques with the RS encoder and decoder System objects.

For example, to shorten a (63,53) code to a (53,43) code, you
can simply enter 53 and 43 for the `CodewordLength`

and `MessageLength`

properties,
respectively (since $$2\lceil {\mathrm{log}}_{2}(53+1)\rceil -1=63$$).
However, to shorten it by 35 symbols to a (28,18) code, you must explicitly
specify that the symbols belong to the Galois field GF(2^{6}).
Otherwise, the RS blocks will assume that the code is shortened from
a (31,21) code (since $$2\lceil {\mathrm{log}}_{2}(28+1)\rceil -1=31$$).

Set the RS encoder/decoder System objects so that they perform block coding with a (28,18) code shortened from a (63,53) code.

Create a (63,53) `RSEncoder`

System object,
and an `RSDecoder`

object with an erasures input port,
and two punctures.

N = 63; % Codeword length K = 53; % Message length S = 18; numErasures = 6; numPuncs = 2; rsEncoder = comm.RSEncoder(N, K, 'BitInput', false); rsDecoder = comm.RSDecoder(N, K, 'BitInput', false, 'ErasuresInputPort', true); rsEncoder.PuncturePatternSource = 'Property'; rsEncoder.PuncturePattern = [ones(N-K-numPuncs,1); zeros(numPuncs,1)]; rsDecoder.PuncturePatternSource = 'Property'; rsDecoder.PuncturePattern = rsEncoder.PuncturePattern; % Set the shortened message length values rsEncoder.ShortMessageLength = S; rsDecoder.ShortMessageLength = S;

Specify the field of GF(2^{6}) in
the RS encoder/decoder System objects, by setting the `PrimitivePolynomialSource`

property
to 'Property' and the `PrimitivePolynomial`

property
to a 6th degree primitive polynomial.

rsEncoder.PrimitivePolynomialSource = 'Property'; rsEncoder.PrimitivePolynomial = de2bi(primpoly(6, 'nodisplay'), 'left-msb'); rsDecoder.PrimitivePolynomialSource = 'Property'; rsDecoder.PrimitivePolynomial = de2bi(primpoly(6, 'nodisplay'), 'left-msb');

**Stream Processing Loop**

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

Shortening alters the code rate much like puncturing does. You
must adjust the value of the coded *E _{b}/N_{0}* ratio
to account for punctures and shortening. In this example, the uncoded

```
EbNoCoded = EbNoUncoded + ...
10*log10(S/(N - numPuncs - K + S));
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); while (codedErrorStats(2) < targetErrors) && ... (codedErrorStats(3) < maxNumTransmissions) % Data symbols - transmit 1 message word at a time, each message word has % S symbols in the [0 2^P-1] range. P is the degree of the % primitive polynomial specified in the RS encoder/decoder, which in this % example equals 6. data = randi([0 2^6-1],S,1); % Encode the shortened message word. The encoded word encData is % N-numPuncs-K+S symbols long. encData = rsEncoder(data); % Modulate encoded data. modData = qamModulator(encData); % Add noise. chanOutput = channel(modData); % Demodulate channel output. demodData = qamDemodulator(chanOutput); % Get erasures vector. 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 updates of the measured BER value,
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 = 9.6599e-05 totalCorrectedErrors = 1436

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

From the curves, observe that the channel BER is worse with
shortening because the coded *E _{b}/N_{0}* is
worse. This degraded coded

**Summary**

This example utilized several System objects to simulate a rectangular 64-QAM communications system over an AWGN channel with a shortened RS block code. It showed how to configure the RS encoder/decoder to shorten a (63,53) code to a (28,18) code. System performance was measured using channel and coded BER curves obtained with the help of error rate measurement System objects.

The examples "Reed-Solomon Coding Part I – Erasures", "Reed-Solomon Coding Part II – Punctures", and "Reed-Solomon Coding Part III – Shortening" show how to configure RS encoders and decoders to perform block coding with erasures, puncturing, and shortening.

**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?