| 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… |
|---|
A Simulink model must satisfy these requirements before you can use it with BERTool, where the case-sensitive variable names must be exactly as shown below:
The channel block must use the variable EbNo rather than a hard-coded value for Eb/N0.
The simulation must stop when the error count reaches the value of the variable maxNumErrs or when the number of processed bits reaches the value of the variable maxNumBits, whichever occurs first.
You can configure the Error Rate Calculation block in Communications Blockset software to stop the simulation based on such criteria.
The simulation must send the final error rate data to the MATLAB workspace as a variable whose name you enter in the BER variable name field in BERTool. The variable must be a three-element vector that lists the BER, the number of bit errors, and the number of processed bits.
This three-element vector format is supported by the Error Rate Calculation block.
Here are some tips for preparing a Simulink model for use with BERTool:
To avoid using an undefined variable name in the dialog box for a Simulink block in the steps that follow, set up variables in the MATLAB workspace using a command such as the one below.
EbNo = 0; maxNumErrs = 100; maxNumBits = 1e8;
You might also want to put the same command in the model's preload function callback, to initialize the variables if you reopen the model in a future MATLAB session.
When you use BERTool, it provides the actual values based on what you enter in the GUI, so the initial values above are somewhat arbitrary.
To model the channel, use the AWGN Channel block in Communications Blockset software with these parameters:
Mode = Signal to noise ratio (Eb/No)
Eb/No = EbNo

To compute the error rate, use the Error Rate Calculation block in Communications Blockset software with these parameters:
Check Stop simulation.
Target number of errors = maxNumErrs
Maximum number of symbols = maxNumBits

To send data from the Error Rate Calculation block to the MATLAB workspace, set Output data to Port, attach a Signal to Workspace block from Signal Processing Blockset™ software, and set the latter block's Limit data points to last parameter to 1. The Variable name parameter in the Signal to Workspace block must match the value you enter in the BER variable name field of BERTool.
If your model computes a symbol error rate instead of a bit error rate, use the Integer to Bit Converter block in Communications Blockset software to convert symbols to bits.
Frame-based simulations often run faster than sample-based simulations for the same number of bits processed. The number of errors or number of processed bits might exceed the values you enter in BERTool, because the simulation always processes a fixed amount of data in each frame.
If you have an existing model that uses the AWGN Channel block using a Mode parameter other than Signal to noise ratio (Eb/No), you can adapt the block to use the Eb/No mode instead. To learn about how the block's different modes are related to each other, press the AWGN Channel block's Help button to view the online reference page.
If your model uses a preload function or other callback to initialize variables in the MATLAB workspace upon loading, make sure before you use the Run button in BERTool that one of these conditions is met:
The model is not currently in memory. In this case, BERTool loads the model into memory and runs the callback functions.
The model is in memory (whether in a window or not), and the variables are intact.
If you clear or overwrite the model's variables and want to restore their values before using the Run button in BERTool, you can use the bdclose function in the MATLAB Command Window to clear the model from memory. This causes BERTool to reload the model after you click Run. Similarly, if you refresh your workspace by issuing a clear all or clear variables command, you should also clear the model from memory by using bdclose all.
This example starts from a Simulink model originally created as an example in the Communications Blockset Getting Started documentation, and shows how to tailor the model for use with BERTool. The example also illustrates how to compare the BER performance of a Simulink simulation with theoretical BER results. The example assumes that you have Communications Blockset software installed.
To prepare the model for use with BERTool, follow these steps, using the exact case-sensitive variable names as shown:
Open the model by entering the following command in the MATLAB Command Window.
bpskdoc

To initialize parameters in the MATLAB workspace and avoid using undefined variables as block parameters, enter the following command in the MATLAB Command Window.
EbNo = 0; maxNumErrs = 100; maxNumBits = 1e8;
To ensure that BERTool uses the correct amount of noise each time it runs the simulation, open the dialog box for the AWGN Channel block by double-clicking the block. Set Es/No to EbNo and click OK. In this particular model, Es/N0 is equivalent to Eb/N0 because the modulation type is BPSK.
To ensure that BERTool uses the correct stopping criteria for each iteration, open the dialog box for the Error Rate Calculation block. Set Target number of errors to maxNumErrs, set Maximum number of symbols to maxNumBits, and click OK.
To enable BERTool to access the BER results that the Error Rate Calculation block computes, insert a Signal to Workspace block in the model and connect it to the output of the Error Rate Calculation block.
Note The Signal to Workspace block is in Signal Processing Blockset software and is different from the To Workspace block in Simulink. |

To configure the newly added Signal to Workspace block, open its dialog box. Set Variable name to BER, set Limit data points to last to 1, and click OK.

(Optional) To make the simulation run faster, especially at high values of Eb/N0, open the dialog box for the Bernoulli Binary Generator block. Select Frame-based outputs and set Samples per frame to 1000.
Save the model in a folder on your MATLAB path using the file name bertool_bpskdoc.mdl.
(Optional) To cause Simulink to initialize parameters if you reopen this model in a future MATLAB session, enter the following command in the MATLAB Command Window and resave the model.
set_param('bertool_bpskdoc','preLoadFcn',...
'EbNo = 0; maxNumErrs = 100; maxNumBits = 1e8;');
The bertool_bpskdoc model is now compatible with BERTool. To use it in conjunction with BERTool, continue the example by following these steps:
Open BERTool and go to the Monte Carlo tab.
Set parameters on the Monte Carlo tab as shown in the following figure.

Click Run.
BERTool spends some time computing results and then plots them.

To compare these simulation results with theoretical results, go to the Theoretical tab in BERTool and set parameters as shown below.

Click Plot.
BERTool plots the theoretical curve in the BER Figure window along with the earlier simulation results.

![]() | Running Simulink Simulations | Managing BER Data | ![]() |

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 |