This example shows how to refine the fixed-point types of a model with bus objects based on simulation data. The following video provides an overview of automatic data typing and data type override for bus objects: Automatic Data Typing for Bus Objects.
ex_bus_Fix model. At the MATLAB® command
Update the diagram. Notice the use of fixed-point data types in the model.
Simulate the model.
The Diagnostic Viewer warns that several overflows occurred during simulation.
Open the Fixed-Point Tool from the model menu by selecting Analysis > Fixed-Point Tool.
The rows containing the Gain3, Gain5, and Gain1 blocks are highlighted in red, indicating where the overflows occurred.
Under System under design, click Continue to
ex_bus_Fix as the system for conversion.
Obtain the ideal numerical behavior of the model by overriding all of the data types with doubles.
Under Configure model settings, click the Range collection using double override button. This button overrides all of the data types in the model with doubles and enables instrumentation to collect range information.
The model is simulated using floating-point doubles, so this
run does not contain any overflows. The Fixed-Point Tool stores range
information in the run titled
Return to the model. A prefix has been added to the names on the bus signals. This prefix indicates that the bus objects are replaced by temporary overridden bus objects specifying double data types. For more information, see Bus Naming Conventions with Data Type Override.
Overridden bus objects are not stored in the base workspace, so you cannot see them in the Bus Editor. The Bus Editor continues to display the data types of the bus objects before they were overridden.
Propose new fraction lengths for your model based on the simulation
results from the
Under Automatic data typing, click the Propose data types button .
In the Propose Data Types dialog
DoubleOverride as the run to use for
proposing data types. Click OK.
The proposed data types appear in the Contents pane of the Fixed-Point Tool.
The Fixed-Point Tool uses the default proposal settings to propose new data types for objects in the model.
Examine the new data types that the Fixed-Point Tool proposed
On the Fixed-Point Tool toolbar, select Show > Groups that must share the same data type to better understand the proposed data types.
In the Contents pane, right-click
the column labeled DTGroup and select
by This Column.
The Fixed-Point Tool organizes the Contents pane to group the elements by data type.
In the Contents pane, select
element (element of the bus object). Click the Result Details tab.
In the Result Details tab, view the details of the proposed data type for the bus element. The data type proposal for a bus element is found by taking the union of the ranges of all blocks that must share the same data type, which includes all of the sources driving the bus element. The software then proposes a data type for this range.
The Shared Simulation minimum and maximum
values of the Range Information table represent
the union of the ranges of the sources driving the bus element. The
data type proposal for
SensorData:Speed is based
on this range.
Right-click the bus element and select
Elements Sharing Same Data Type to see all of the sources
driving the bus element.
Return to the Fixed-Point Tool Workflow tab. Click the Apply accepted data types button to write the proposed data types to the model.
Under Configure model settings, click the Range collection with specified data types button to remove data type override. Now, when you simulate the model, it uses the new fixed-point types that you applied.
Simulate the model. This time, the Fixed-Point Tool
stores the results in a new run named
In the Fixed-Point Tool Contents pane,
verify that there are no overflows in the
Click Compare Runs
to launch the Simulation Data Inspector.
In the Simulation Data Inspector, compare the results of
the results of the
Return to the model. Notice that the bus objects no longer contain the prefixes.
Open the Bus Editor from the model menu by selecting Edit > Bus Editor. You can now view the new, refined data types of the bus objects in the Bus Editor.
Click the Remove overrides and disable range collection button to remove instrumentation and restore model to maximum simulation speed.
Data types for bus elements are stored in the base workspace,
not the model. To save the fixed-point data types for the bus elements
ex_bus_Fix, export them from the Bus Editor
.mat file. For instructions, see Export Bus Objects. Alternatively,
you can save workspace variables to a file at the MATLAB command
line using the