Transmit and Receive Shortened Reed-Solomon Codes
Transmit and receive standard and shortened RS-encoded, 64-QAM-modulated data through an AWGN channel. Compare the performance of the standard and shortened codes.
Set the parameters for the Reed-Solomon code, where N
is the codeword length, K
is the nominal message length, and S
is the shortened message length. Specify the modulation order, M
.
N = 63; % Codeword length K = 51; % Message length S = 39; % Shortened message length M = 64; % Modulation order
Specify the simulation parameters, where numErrors
is the number of errors per Eb/No point, and numBits
is the maximum number of bits per Eb/No point. Specify the range of Eb/No values to be simulated. Initialize the BER arrays.
numErrors = 200; numBits = 1e7; ebnoVec = (8:13)'; [ber0,ber1] = deal(zeros(size(ebnoVec)));
Create an error rate object to collect error statistics.
errorRate = comm.ErrorRate;
Create a Reed-Solomon encoder and decoder pair for an RS(63,51) code. Calculate the code rate.
rsEncoder = comm.RSEncoder(N,K,'BitInput',true); rsDecoder = comm.RSDecoder(N,K,'BitInput',true); rate = K/N;
Execute the main processing loop.
for k = 1:length(ebnoVec) % Convert the coded Eb/No to an SNR. Initialize the error statistics % vector. snrdB = ebnoVec(k) + 10*log10(rate) + 10*log10(log2(M)); errorStats = zeros(3,1); while errorStats(2) < numErrors && errorStats(3) < numBits % Generate binary data. txData = randi([0 1],K*log2(M),1); % Encode the data. encData = rsEncoder(txData); % Apply 64-QAM modulation. txSig = qammod(encData,M, ... 'UnitAveragePower',true,'InputType','bit'); % Pass the signal through an AWGN channel. rxSig = awgn(txSig,snrdB); % Demodulated the noisy signal. demodSig = qamdemod(rxSig,M, ... 'UnitAveragePower',true,'OutputType','bit'); % Decode the data. rxData = rsDecoder(demodSig); % Compute the error statistics. errorStats = errorRate(txData,rxData); end % Save the BER data, and reset the errorRate counter. ber0(k) = errorStats(1); reset(errorRate) end
Create a Reed-Solomon generator polynomial for an RS(63,51) code.
gp = rsgenpoly(N,K,[],0);
Create a Reed-Solomon encoder and decoder pair using shortened message length S
and generator polynomial gp
. Calculate the rate of the shortened code.
rsEncoder = comm.RSEncoder(N,K,gp,S,'BitInput',true); rsDecoder = comm.RSDecoder(N,K,gp,S,'BitInput',true); rate = S/(N-(K-S));
Execute the main processing loop using the shortened Reed-Solomon code.
for k = 1:length(ebnoVec) % Convert the coded Eb/No to an SNR. Initialize the error statistics % vector. snrdB = ebnoVec(k) + 10*log10(rate) + 10*log10(log2(M)); errorStats = zeros(3,1); while errorStats(2) < numErrors && errorStats(3) < numBits % Generate binary data. txData = randi([0 1],S*log2(M),1); % Encode the data. encData = rsEncoder(txData); % Apply 64-QAM modulation. txSig = qammod(encData,M, ... 'UnitAveragePower',true,'InputType','bit'); % Pass the signal through an AWGN channel. rxSig = awgn(txSig,snrdB); % Demodulated the noisy signal. demodSig = qamdemod(rxSig,M, ... 'UnitAveragePower',true,'OutputType','bit'); % Decode the data. rxData = rsDecoder(demodSig); % Compute the error statistics. errorStats = errorRate(txData,rxData); end % Save the BER data, and reset the errorRate counter. ber1(k) = errorStats(1); reset(errorRate) end
Calculate the approximate BER for an RS (63,51) code.
berapprox = bercoding(ebnoVec,'RS','hard',N,K,'qam',64);
Compare the BER curves for the RS(63,51) and RS(51,39) codes. Plot the theoretically approximated BER curve. Observe that shortening the code does not affect performance.
semilogy(ebnoVec,ber0,'o-',ebnoVec,ber1,'c^-',ebnoVec,berapprox,'k--') legend('RS(63,51)','RS(51,39)','Theory') xlabel('Eb/No (dB)') ylabel('Bit Error Rate') grid