| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Communications Toolbox |
| Contents | Index |
| Learn more about Communications Toolbox |
| On this page… |
|---|
Creating Error Rate Plots Using semilogy |
Error rate plots provide a visual way to examine the performance of a communication system, and they are often included in publications. This section mentions some of the tools you can use to create error rate plots, modify them to suit your needs, and do curve fitting on error rate data. It also provides an example of curve fitting. For more detailed discussions about the more general plotting capabilities in MATLAB, see the MATLAB documentation set.
In many error rate plots, the horizontal axis indicates Eb/N0 values in dB and the vertical axis indicates the error rate using a logarithmic (base 10) scale. To see an example of such a plot, as well as the code that creates it, see Comparing Theoretical and Empirical Error Rates. The part of that example that creates the plot uses the semilogy function to produce a logarithmic scale on the vertical axis and a linear scale on the horizontal axis.
Other examples that illustrate the use of semilogy are in these sections:
Example: Using the Semianalytic Technique, which also illustrates
Plotting two sets of data on one pair of axes
Adding a title
Adding a legend
Plotting Theoretical Error Rates, which also illustrates
Adding axis labels
Adding grid lines
Curve fitting is useful when you have a small or imperfect data set but want to plot a smooth curve for presentation purposes. The berfit function in Communications Toolbox offers curve-fitting capabilities that are well suited to the situation when the empirical data describes error rates at different Eb/N0 values. This function enables you to
Customize various relevant aspects of the curve-fitting process, such as the type of closed-form function (from a list of preset choices) used to generate the fit.
Plot empirical data along with a curve that berfit fits to the data.
Interpolate points on the fitted curve between Eb/N0 values in your empirical data set to make the plot smoother looking.
Collect relevant information about the fit, such as the numerical values of points along the fitted curve and the coefficients of the fit expression.
Note The berfit function is intended for curve fitting or interpolation, not extrapolation. Extrapolating BER data beyond an order of magnitude below the smallest empirical BER value is inherently unreliable. |
For a full list of inputs and outputs for berfit, see its reference page.
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 sets up the parameters to 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, 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 = 100000; % Number of bits in each trial
M = 2; % DBPSK is binary.
hMod = modem.dpskmod('M', M); % Create a DPSK modulator
hDemod = modem.dpskdemod(hMod); % Create a DPSK
% demodulator using the modulator object
EbNomin = 0; EbNomax = 9; % 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 intervalsThe 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 = modulate(hMod, msg); % Modulate.
rxsig = awgn(txsig, snr, 'measured'); % Add noise.
decodmsg = demodulate(hDemod, rxsig); % Demodulate.
if (ntrials==0)
% The first symbol of a differentially encoded transmission
% is discarded.
newerrs = biterr(msg(2:end),decodmsg(2:end)); ...
% Errors in this trial
else
newerrs = biterr(msg,decodmsg); % Errors in this trial
end
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)-1,.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 this example uses random numbers.
EbNo = 0 dB, 189 errors, BER = 0.18919 EbNo = 1 dB, 139 errors, BER = 0.13914 EbNo = 2 dB, 105 errors, BER = 0.10511 EbNo = 3 dB, 66 errors, BER = 0.066066 EbNo = 4 dB, 40 errors, BER = 0.04004 EbNo = 5 dB, 18 errors, BER = 0.018018 EbNo = 6 dB, 6 errors, BER = 0.006006 EbNo = 7 dB, 11 errors, BER = 0.0055028 EbNo = 8 dB, 5 errors, BER = 0.00071439 EbNo = 9 dB, 5 errors, BER = 0.00022728 EbNo = 10 dB, 5 errors, BER = 1.006e-005
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,[],'exp');
% Also plot confidence intervals.
hold on;
for jj=1:numEbNos
semilogy([EbNovec(jj) EbNovec(jj)],intv{jj},'g-+');
end
hold off;

![]() | Theoretical Performance Results | Eye Diagrams | ![]() |

Learn how to apply early verification to your development process through these technical resources.
How much time do you spend on testing to ensure implementation meets system-level requirements?
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |