Main Content

Configure Eb/No for AWGN Channels with Coding

This example shows how to set the bit energy to noise density ratio (Eb/No) for communication links employing channel coding.

Specify the codeword and message length for a Reed-Solomon code. Specify the modulation order.

N = 15;        % R-S codeword length in symbols
K = 9;         % R-S message length in symbols
M = 16;        % Modulation order
bps = log2(M); % Bits per symbol

Construct a (15,9) Reed-Solomon encoder and a 16-PSK modulator. Specify the objects so that they accept bit inputs.

rsEncoder = comm.RSEncoder( ...
    CodewordLength=N, ...
    MessageLength=K, ...
    BitInput=true);

Create the corresponding Reed-Solomon decoder and 16-PSK demodulator objects.

rsDecoder = comm.RSDecoder( ...
    CodewordLength=N, ...
    MessageLength=K, ...
    BitInput=true);

Calculate the Reed-Solomon code rate based on the ratio of message symbols to the codeword length.

codeRate = K/N;

Specify the uncoded Eb/No in dB. Convert the uncoded Eb/No to the corresponding coded Eb/No using the code rate.

UncodedEbNo = 6;
CodedEbNo = UncodedEbNo + 10*log10(codeRate);

Construct an AWGN channel taking into account the number of bits per symbol. Set the EbNo property of channel to the coded Eb/No.

channel = comm.AWGNChannel(BitsPerSymbol=bps);
channel.EbNo = CodedEbNo;

Set the total number of errors and bits for the simulation. For accuracy, the simulation should run until a sufficient number of bit errors are encountered. The number of total bits is used to ensure that the simulation does not run too long.

totalErrors = 100;
totalBits = 1e6;

Construct an error rate calculator System object™ and initialize the error rate vector.

errorRate = comm.ErrorRate;
errorVec = zeros(3,1);

Run the simulation to determine the BER.

while errorVec(2) < totalErrors && errorVec(3) < totalBits
    % Generate random bits
    dataIn = randi([0,1],360,1);
    % Add error correction capability by using the RS (15,9) encoder
    dataEnc = rsEncoder(dataIn);
    % Apply 16-PSK modulation
    %txSig = pskModulator(dataIn);
    txSig = pskmod(dataIn,M,InputType="bit");
    % Pass the modulated data through the AWGN channel
    rxSig = channel(txSig);
    % Demodulate the received signal
    %demodData = pskDemodulator(rxSig);
    demodData = pskdemod(rxSig,M,OutputType="bit");
    % Decode the demodulated data with the RS (15,9) decoder
    dataOut = rsDecoder(demodData);
    % Collect error statistics
    errorVec = errorRate(dataIn,demodData);
end

Display the resultant bit error rate.

ber = errorVec(1)
ber = 0.0991