| Communications Toolbox | ![]() |
The Communications Toolbox includes a graphical user interface (GUI) called BERTool that is designed to solve problems like the following:
Problem Modify the modulation example in so that it computes the BER for integer values of EbNo between 0 and 7. Plot the BER as a function of EbNo using a logarithmic scale for the vertical axis. |
BERTool solves the problem by managing a series of simulations with different values of Eb/N0, collecting the results, and creating a plot. You provide the core of the simulation, which in this case is a minor modification of the example in .
This section introduces BERTool as well as some simulation-related issues, in these topics:
However, this section is not a comprehensive description of BERTool; for more information about BERTool, see BERTool: A Bit Error Rate Analysis GUI.
This solution uses code from as well as code from a template file that is tailored for use with BERTool. To view the original code in an editor window, enter these commands in the MATLAB Command Window.
edit commdoc_gray edit bertooltemplate
To view a completed M-file for this example, enter edit commdoc_bertool in the MATLAB Command Window.
1. Save Template in Your Own Directory. Navigate to a directory where you want to save your own files. Save the BERTool template (bertooltemplate) under the filename my_commdoc_bertool to avoid overwriting the original template.
Also, change the first line of my_commdoc_bertool, which is the function declaration, to use the new filename.
function [ber, numBits] = my_commdoc_bertool(EbNo, maxNumErrs, maxNumBits)
2. Copy Setup Code Into Template. In the my_commdoc_bertool file, replace
% --- Set up parameters. --- % --- INSERT YOUR CODE HERE.
with the following setup code adapted from the example in .
% Setup % Define parameters. M = 16; % Size of signal constellation k = log2(M); % Number of bits per symbol n = 1000; % Number of bits to process nsamp = 1; % Oversampling rate
To save time in the simulation, the code above changes the value of n from its original value. At small values of EbNo, it is not necessary to process tens of thousands of symbols to compute an accurate BER; at large values of EbNo, the loop structure in the template file (described later) causes the simulation to include at least 100 errors even if it must iterate several times through the loop to accumulate that many errors.
3. Copy Simulation Code Into Template. In the my_commdoc_bertool file, replace
% --- Proceed with simulation. % --- Be sure to update totErr and numBits. % --- INSERT YOUR CODE HERE.
with the rest of the code (that is, the code following the Setup section) from the example in .
Also, type a semicolon at the end of the last line of the pasted code (the biterr command) to suppress screen output when BERTool runs the simulation.
6. Update numBits and totErr. After the pasted code from the last step and before the end statement from the template, insert the following code.
%% Update totErr and numBits. totErr = totErr + number_of_errors; numBits = numBits + n;
These commands enable the function to keep track of the number of bits processed and the number of errors detected.
5. Suppress Earlier Plots. Running multiple iterations would result in a large number of plots, which this example suppresses for simplicity. In the my_commdoc_bertool file, remove the lines of code that use these functions: stem, title, xlabel, ylabel, figure, scatterplot, hold, legend, axis.
6. Omit Direct Assignment of EbNo. When BERTool invokes a simulation function, it specifies a value of EbNo. The my_commdoc_bertool function must not directly assign EbNo. Therefore, remove or comment out the line that you pasted into my_commdoc_bertool (within the Channel section) that assigns EbNo directly.
% EbNo = 10; % In dB % COMMENT OUT FOR BERTOOL
7. Save Simulation Function. The simulation function, my_commdoc_bertool, is complete. Save the file so that BERTool can use it.
8. Open BERTool and Enter Parameters. To open BERTool, enter
bertool
in the MATLAB Command Window. Then click the Monte Carlo tab and enter parameters as shown below.

These parameters tell BERTool to run your simulation function, my_commdoc_bertool, for each value of EbNo in the vector 2:10 (that is, the vector [2 3 4 5 6 7 8 9 10]). Each time the simulation runs, it continues processing data until it detects 100 bit errors or processes a total of 1e8 bits, whichever occurs first.
9. Use BERTool to Simulate and Plot. Click the Run button on BERTool. BERTool begins the series of simulations and eventually reports the results to you in a plot like the one below.

To compare these BER results with theoretical results, leave BERTool open and use the procedure below.
To check whether the results from the solution above are correct, use BERTool again. This time, use its Theoretical panel to plot theoretical BER results in the same window as the simulation results from before. Follow this procedure:
In the BERTool GUI, click the Theoretical tab and enter parameters as shown below.

The parameters tell BERTool to compute theoretical BER results for 16-QAM over an AWGN channel, for Eb/N0 values in the vector 2:10.
Click the Plot button. The resulting plot shows a solid curve for the theoretical BER results and plotting markers for the earlier simulation results.

Notice that the plotting markers are close to the theoretical curve. It is relevant that the simulation code used a Gray-coded signal constellation, unlike the first modulation example of this chapter (in Modulating a Random Signal). The theoretical performance results assume a Gray-coded signal constellation.
To continue exploring BERTool, you can select the Fit check box to fit a curve to the simulation data, or set Confidence Level to a numerical value to include confidence intervals in the plot. See also BERTool: A Bit Error Rate Analysis GUI for more about BERTool.
Looking more closely at the simulation function in this example, you might make a few observations about its structure, and particularly about the loop marked with the comments
% Simulate until number of errors exceeds maxNumErrs % or number of bits processed exceeds maxNumBits.
The loop structure means that the simulation processes some data, accumulates bit errors, and then decides whether to repeat the process with another set of data. The advantage of this approach is that you do not have to guess in advance how much data you need to process to obtain an accurate BER estimate. This is very useful when your series of simulations spans a large Eb/N0 range because simulations at higher values of Eb/N0 require more data processing to maintain the same level of accuracy in the BER estimate. Another advantage of this approach is that you avoid memory problems caused by excessively large data sets.
However, a potential complication from dividing large data sets into a series of smaller data sets that you process in a loop is that you might need to take steps to ensure the continuity of computations from one iteration to the next. For example, continuity is important when the simulation includes convolutional decoding, convolutional interleaving/deinterleaving, continuous phase modulation, fading channels, and equalization. To learn more about how to maintain continuity, see the examples in
The vitdec reference page
The viterbisim demonstration function (designed to be used with BERTool)
The muxdeintrlv reference page
The mskdemod reference page
If you divide your data set into a series of very small data sets, then the large number of function calls might make the simulation slow. You can use the Profiler tool in MATLAB to help you make your code faster.
| Simulating a Communication System | Varying Parameters and Managing a Set of Simulations | ![]() |
© 1994-2005 The MathWorks, Inc.