|On this page…|
This example shows how to refine the fixed-point types of a model with bus objects based on simulation data.
Open the ex_bus_Fix model. At the MATLAB® command line, enter:
Press ctrl+d to 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.
Because the Fixed-Point Instrumentation Mode was set to Minimums, maximums and overflows, the rows containing the Gain3, Gain5, and Gain1 blocks are highlighted in red, indicating where the overflows occurred.
Obtain the ideal numerical behavior of the model by overriding all of the data types with floating-point singles.
In the Settings for selected system pane, set Data type override to Single. Set Data type override applies to to All numeric types.
In the Data collection pane, set Store results in run to SingleOverride. Click Simulate.
The model is simulated using floating-point singles, so this run does not contain any overflows.
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 single 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 SingleOverride run.
Click the Propose fraction lengths button .
In the Propose Data Types dialog box, select SingleOverride 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.
Examine the new data types that the Fixed-Point Tool has proposed for ex_bus_Fix.
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 Group by This Column.
The Fixed-Point Tool organizes the Contents pane to group the elements by data type.
Right-click the SensorData:Speed bus element (element of the bus object) and select Result Details.
In the Result Details dialog box, 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 Maximum and Shared Simulation Minimum 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.
Click OK to close the dialog box.
Right-click the bus element again. Select Highlight Blocks Sharing Same Data Type to see all of the sources driving the bus element.
Return to the Fixed-Point Tool. Click the Apply accepted fraction lengths button to write the proposed data types to the model.
In the Settings for selected system pane, set Data type override to Off so when you simulate the model, it uses the new fixed-point types that you applied.
Simulate the model. This time, store the results in Fixed_Run.
In the Fixed-Point Tool Contents pane, verify that there are no overflows in Fixed_Run.
In the Simulation Data Inspector, compare the results of Fixed_Run to the results of the SingleOverride run.
Return to the model. Notice that the bus objects no longer contain the prefixes.
Open the Bus Editor by clicking Edit > Bus Editor. You can now view the new, refined data types of the bus objects in the Bus Editor.
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 in ex_bus_Flt, export them from the Bus Editor to a .mat file. For instructions, see Export Bus Objects. Alternatively, you can save workspace variables to a file at the MATLAB command line using the save function .