This example shows how to set up the Reed-Solomon (RS) encoder/decoder to use punctured codes. 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 in exactly the same way when it decodes. Puncturing has the added benefit of making the code rate more flexible, at the expense of some error correction capability.

In addition to this example, the example “Reed-Solomon Coding Part I – Erasures” shows a rectangular 64-QAM communications system with a (63,53) RS block code with erasures, and the example “Reed-Solomon Coding Part III – Shortening” shows RS block coding with shortened codes.

**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 and puncturing 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^{6}, respectively.

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 example “Reed-Solomon Coding Part I − Erasures” to showcase how to decode erasures. This example shows how to set up the RS encoder/decoder to use a punctured code. In addition to decoding receiver-generated erasures, the RS decoder can correct encoder-generated punctures. The decoding algorithm is identical for the two cases. For each codeword, the sum of the punctures and erasures cannot exceed twice the error-correcting capability of the code.

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

To enable code puncturing you set the `PuncturePatternSource`

property
to 'Property' and set the `PuncturePattern`

property
to the desired puncture pattern vector. The same puncture vector must
be specified in both the encoder and decoder. This example punctures
two symbols from each codeword. Values of one in the puncture pattern
vector indicate nonpunctured symbols, while values of zero indicate
punctured symbols.

numPuncs = 2; rsEncoder.PuncturePatternSource = 'Property'; rsEncoder.PuncturePattern = [ones(N-K-numPuncs,1); zeros(numPuncs,1)]; rsDecoder.PuncturePatternSource = 'Property'; rsDecoder.PuncturePattern = rsEncoder.PuncturePattern;

**Stream Processing Loop**

Simulate the communications system for an uncoded
*E*_{b}/*N*_{0}
ratio of 15 dB. The uncoded
*E*_{b}/*N*_{0}
is the ratio that would be measured at the input of the channel if there was no coding in
the system.

The length of the codewords generated by the RS encoder is reduced by the number of punctures
specified in the puncture pattern vector. For this reason, the value of the coded
*E*_{b}/*N*_{0}
ratio needs to be adjusted to account for these punctures. In this example, the uncoded
*E*_{b}/*N*_{0}
ratio relates to the coded
*E*_{b}/*N*_{0}
as shown below. Set the `EbNo`

property of the AWGN channel object to
the computed coded
*E*_{b}/*N*_{0}
value.

EbNoCoded = EbNoUncoded + 10*log10(K/(N - numPuncs)); 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-numPuncs 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 objet. 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 = 4.3198e-05 totalCorrectedErrors = 578

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 slightly better in the punctured case. The
reason for this is that the coded
*E*_{b}/*N*_{0}
is slightly higher. On the other hand, the coded BER is worse in the punctured case,
because the two punctures reduce the error correcting capability of the code by one,
leaving it able to correct only (10-6-2)/2 = 1 error per codeword.

**Summary**

The 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 encoder/decoder System objects to obtain punctured codes. System performance was measured using channel and coded BER curves obtained using the error rate measurement System objects.

The example “Reed-Solomon Coding Part III – Shortening” shows how to perform RS block coding with shortened codes.

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