MATLAB Examples

# Rate 2/3 Convolutional Code in AWGN

This example generates a bit error rate versus Eb/No curve for a link that uses 16-QAM modulation and a rate 2/3 convolutional code in AWGN.

Set the modulation order, and compute the number of bits per symbol.

```M = 16; k = log2(M); ```

Create a trellis for a rate 2/3 convolutional code. Set the traceback and code rate parameters.

```trellis = poly2trellis([5 4],[23 35 0; 0 5 13]); traceBack = 16; codeRate = 2/3; ```

Create a convolutional encoder and its equivalent Viterbi decoder.

```convEncoder = comm.ConvolutionalEncoder('TrellisStructure',trellis); vitDecoder = comm.ViterbiDecoder('TrellisStructure',trellis, ... 'InputFormat','Hard','TracebackDepth',traceBack); ```

Create a 16-QAM modulator and demodulator pair having bit inputs and outputs. Set the constellation to normalize on average power.

```qamModulator = comm.RectangularQAMModulator('BitInput',true,'NormalizationMethod','Average power'); qamDemodulator = comm.RectangularQAMDemodulator('BitOutput',true,'NormalizationMethod','Average power'); ```

Create an error rate object. Set the receiver delay to twice the traceback depth, which is the delay through the decoder.

```errorRate = comm.ErrorRate('ReceiveDelay',2*traceBack); ```

Set the range of Eb/No values to be simulated. Initialize the bit error rate statistics matrix.

```ebnoVec = 0:2:10; errorStats = zeros(length(ebnoVec),3); ```

Simulate the link by following these steps:

• Generate binary data.
• Encode the data with a rate 2/3 convolutional code.
• Modulate the encoded data.
• Pass the signal through an AWGN channel.
• Decode the demodulated signal by using a Viterbi decoder.
• Collect the error statistics.
```for m = 1:length(ebnoVec) ```
``` snr = ebnoVec(m) + 10*log10(k*codeRate); ```
``` while errorStats(m,2) <= 100 && errorStats(m,3) <= 1e7 dataIn = randi([0 1],10000,1); dataEnc = convEncoder(dataIn); txSig = qamModulator(dataEnc); rxSig = awgn(txSig,snr); demodSig = qamDemodulator(rxSig); dataOut = vitDecoder(demodSig); errorStats(m,:) = errorRate(dataIn,dataOut); end reset(errorRate) ```
```end ```

Compute the theoretical BER vs. Eb/No curve for the case without forward error correction coding.

```berUncoded = berawgn(ebnoVec','qam',M); ```

Plot the BER vs. Eb/No curve for the simulated coded data and the theoretical uncoded data.

```semilogy(ebnoVec,[errorStats(:,1) berUncoded]) grid legend('Coded','Uncoded') xlabel('Eb/No (dB)') ylabel('Bit Error Rate') ```

At higher Eb/No values, the error correcting code provides performance benefits.