| Communications Toolbox | ![]() |
This example simulates a simple DBPSK (differential binary phase shift keying) communication system and plots error rate data for a series of Eb/N0 values. It uses the berfit function to fit a curve to the somewhat rough set of empirical error rates. Because the example is long, this discussion presents it in multiple steps:
The first step in the example is to set up parameters that will be used during the simulation. Parameters include the range of Eb/N0 values to consider and the minimum number of errors that must occur before the simulation computes an error rate for that Eb/N0 value.
Note For most applications, you should base an error rate computation on a larger number of errors than is used here (for instance, you might change numerrmin to 100 in the code below). However, as shown, this example uses a small number of errors merely to illustrate how curve fitting can smooth out a rough data set. |
% Set up initial parameters. siglen = 1000; % Number of bits in each trial M = 2; % DBPSK is binary. EbNomin = 0; EbNomax = 10; % EbNo range, in dB numerrmin = 5; % Compute BER only after 5 errors occur. EbNovec = EbNomin:1:EbNomax; % Vector of EbNo values numEbNos = length(EbNovec); % Number of EbNo values % Preallocate space for certain data. ber = zeros(1,numEbNos); % BER values intv = cell(1,numEbNos); % Cell array of confidence intervals
The next step in the example is to use a for loop to vary the Eb/N0 value (denoted by EbNo in the code) and simulate the communication system for each value. The inner while loop ensures that the simulation continues to use a given EbNo value until at least the predefined minimum number of errors has occurred. When the system is very noisy, this requires only one pass through the while loop, but in other cases, this requires multiple passes.
The communication system simulation uses these toolbox functions:
randint to generate a random message sequence
dpskmod to perform DBPSK modulation
awgn to model a channel with additive white Gaussian noise
dpskdemod to perform DBPSK demodulation
biterr to compute the number of errors for a given pass through the while loop
berconfint to compute the final error rate and confidence interval for a given value of EbNo
As the example progresses through the for loop, it collects data for later use in curve fitting and plotting:
ber, a vector containing the bit error rates for the series of EbNo values
intv, a cell array containing the confidence intervals for the series of EbNo values. Each entry in intv is a two-element vector that gives the endpoints of the interval.
% Loop over the vector of EbNo values.
for jj = 1:numEbNos
EbNo = EbNovec(jj);
snr = EbNo; % Because of binary modulation
ntrials = 0; % Number of passes through the while loop below
numerr = 0; % Number of errors for this EbNo value
% Simulate until numerrmin errors occur.
while (numerr < numerrmin)
msg = randint(siglen, 1, M); % Generate message sequence.
txsig = dpskmod(msg,M); % Modulate.
rxsig = awgn(txsig, snr, 'measured'); % Add noise.
decodmsg = dpskdemod(rxsig,M); % Demodulate.
newerrs = biterr(msg,decodmsg); % Errors in this trial
numerr = numerr + newerrs; % Total errors for this EbNo value
ntrials = ntrials + 1; % Update trial index.
end
% Error rate and 98% confidence interval for this EbNo value
[ber(jj), intv1] = berconfint(numerr,(ntrials * siglen),.98);
intv{jj} = intv1; % Store in cell array for later use.
disp(['EbNo = ' num2str(EbNo) ' dB, ' num2str(numerr) ...
' errors, BER = ' num2str(ber(jj))])
endThis part of the example displays output in the Command Window as it progresses through the for loop. Your exact output might be different, because the example uses random numbers.
EbNo = 0 dB, 182 errors, BER = 0.182 EbNo = 1 dB, 156 errors, BER = 0.156 EbNo = 2 dB, 104 errors, BER = 0.104 EbNo = 3 dB, 66 errors, BER = 0.066 EbNo = 4 dB, 42 errors, BER = 0.042 EbNo = 5 dB, 27 errors, BER = 0.027 EbNo = 6 dB, 13 errors, BER = 0.0065 EbNo = 7 dB, 7 errors, BER = 0.007 EbNo = 8 dB, 5 errors, BER = 0.00125 EbNo = 9 dB, 5 errors, BER = 0.000625 EbNo = 10 dB, 5 errors, BER = 0.00041667
The final part of this example fits a curve to the BER data collected from the simulation loop. It also plots error bars using the output from the berconfint function.
% Use BERFIT to plot the best fitted curve,
% interpolating to get a smooth plot.
fitEbNo = EbNomin:0.25:EbNomax; % Interpolation values
berfit(EbNovec,ber,fitEbNo);
% Also plot confidence intervals.
hold on;
for jj=1:numEbNos
semilogy([EbNovec(jj) EbNovec(jj)],intv{jj},'g-+');
end
hold off;

| Curve Fitting for Error Rate Plots | Eye Diagrams | ![]() |
© 1994-2005 The MathWorks, Inc.