This example extends the Use Pulse Shaping on 16-QAM Signal example to show bit error rate (BER) performance improvement when using forward error correction (FEC) coding.
This example shows how to process a binary data stream by using a communications link that consists of a baseband modulator, channel, demodulator, pulse shaping and matching filters, and error correction.
In this example, to achieve a more accurate BER estimate, the number of bits to process is increased from the value used in the Use Pulse Shaping on 16-QAM Signal example. Other simulation variables match the settings in that example.
Define simulation parameters for a 16-QAM modulation scheme with raised cosine filtering and an AWGN channel.
M = 16; % Modulation order k = log2(M); % Number of bits per symbol numBits = 1e6; % Number of bits to process sps = 4; % Number of samples per symbol (oversampling factor) filtlen = 10; % Filter length in symbols rolloff = 0.25; % Filter rolloff factor
Set the rng
function to its default state, or any static seed value, so that the example produces repeatable results. Then, use the randi
function to generate random binary data.
rng default; % Use default random number generator dataIn = randi([0 1],numBits,1); % Generate vector of binary data
To correct errors arising from the noisy channel, apply convolutional coding to the data before transmission and Viterbi decoding to the received data. The decoder uses a hard decision algorithm, which means each received data bit is interpreted as either 0
or 1
.
Define a convolutional coding trellis for a rate 2/3 code by using the poly2trellis
function. The defined trellis represents the convolutional code that the convenc
function uses for encoding the binary vector, dataIn
.
constrlen = [5 4]; % Code constraint length genpoly = [23 35 0; 0 5 13] % Generator polynomials
genpoly = 2×3
23 35 0
0 5 13
tPoly = poly2trellis(constrlen,genpoly); codeRate = 2/3;
Encode the input data by using the tPoly
trellis.
dataEnc = convenc(dataIn,tPoly);
Reshape the input vector into a matrix of 4-bit binary data. Then, use the bi2de
function to convert the encoded binary data to an integer format.
dataEncMatrix = reshape(dataEnc, ... length(dataEnc)/k,k); % Reshape data into binary 4-tuples dataSymbolsIn = bi2de(dataEncMatrix); % Convert to integers
Use the qammod
function to apply 16-QAM modulation.
dataMod = qammod(dataSymbolsIn,M);
Use the rcosdesign
function to create an RRC filter.
rrcFilter = rcosdesign(rolloff,filtlen,sps);
Use the upfirdn
function to upsample the signal by the oversampling factor and apply the RRC filter. The upfirdn
function pads the upsampled signal with zeros at the end to flush the filter. Then, the function applies the filter.
txSignal = upfirdn(dataMod,rrcFilter,sps,1);
Using the number of bits per symbol (k
) and the number of samples per symbol (sps
), convert the ratio of energy per bit to noise power spectral density (EbNo
) to an SNR value for use by the awgn
function. When converting the to SNR, you must account for the number of information bits per symbol. With no FEC applied, each symbol corresponded to k
bits. With FEC applied, each symbol corresponds to (k
codeRate
) information bits. For the 2/3 code rate and 16-QAM transmissions used in this example, three symbols correspond to 12 coded bits and 8 uncoded (information) bits.
EbNo = 10; snr = EbNo+10*log10(k*codeRate)-10*log10(sps);
Pass the filtered signal through an AWGN channel.
rxSignal = awgn(txSignal,snr,'measured');
Filter the received signal by using the RRC filter. Remove a portion of the signal to account for the filter delay.
rxFiltSignal = upfirdn(rxSignal,rrcFilter,1,sps); % Downsample and filter rxFiltSignal = rxFiltSignal(filtlen + 1:end - filtlen); % Account for delay
Use the qamdemod
function to demodulate the received filtered signal.
dataSymbolsOut = qamdemod(rxFiltSignal,M);
Use the de2bi
function to convert the recovered integer symbols into binary data.
dataOutMatrix = de2bi(dataSymbolsOut,k);
codedDataOut = dataOutMatrix(:); % Return data in column vector
Use the vitdec
function, configured for hard decisions and continuous operation mode, to decode the convolutionally encoded data. The continuous operation mode maintains the internal state when the decoder is repeatedly invoked, such as when receiving frames of data operating in a loop. The continuous operation mode also adds delay to the system. Although this example does not use a loop, the 'cont
' mode is used for the purpose of illustrating how to compensate for the delay in this decoding operation.
traceBack = 16; % Traceback length for decoding numCodeWords = floor(length(codedDataOut)*2/3); % Number of complete codewords dataOut = vitdec(codedDataOut(1:numCodeWords*3/2), ... tPoly,traceBack,'cont','hard'); % Decode data
Use the biterr
function to compute the number of errors and the BER by comparing dataIn
and dataOut
. The delay introduced by the transmit and receive RRC filters is already accounted for in the recovered data, but the decoder delay is not accounted for yet. The continuous operation mode of the Viterbi decoder incurs a delay with a duration in bits equal to the traceback length, traceBack
, times the number of input streams at the encoder. For the 2/3 code rate used in this example, the encoder has two input streams, so the delay is 2×traceBack
bits. As a result, the first 2×traceBack
bits in the decoded vector, dataOut
, are zeros. When computing the BER, discard the first 2×traceBack
bits in dataOut
and the last 2×traceBack
bits in the original vector, dataIn
.
decDelay = 2*traceBack; % Decoder delay, in bits [numErrors,ber] = ... biterr(dataIn(1:end - decDelay),dataOut(decDelay + 1:end)); fprintf('\nThe bit error rate is %5.2e, based on %d errors.\n', ... ber,numErrors)
The bit error rate is 1.00e-04, based on 100 errors.
For the same of 10 dB, less errors occur when using FEC and the BER improves from approximately 2×10-3 to 1×10-4.
The decoding operation in this example incurs a delay that causes the output of the decoder to lag the input. Timing information does not appear explicitly in the example, and the length of the delay depends on the specific operations being performed. Delays occur in various communications system operations, including convolutional decoding, convolutional interleaving and deinterleaving, equalization, and filtering. To find out the duration of the delay caused by specific functions or operations, see the specific documentation for those functions or operations. For more information on delays, see Delays of Convolutional Interleavers and Fading Channels.