This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Refine Data Types of a Model with Buses Using Simulation Data

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.

Open and Simulate the Model

Open the ex_bus_Fix model. At the MATLAB® command line, enter:

  1. Update the diagram. Notice the use of fixed-point data types in the model.

  2. Simulate the model.

    The Diagnostic Viewer warns that several overflows occurred during simulation.

Use Data Type Override to Resolve Overflows

  1. Open the Fixed-Point Tool from the model menu by selecting Analysis > Data Type Design > Fixed-Point Tool.

    The rows containing the Gain3, Gain5, and Gain1 blocks are highlighted in red, indicating where the overflows occurred.

  2. Under System under design, click Continue to select ex_bus_Fix as the system for conversion.

  3. 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.

    Click Simulate.

    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 DoubleOverride.

  4. 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

Propose new fraction lengths for your model based on the simulation results from the DoubleOverride run.

  1. Under Automatic data typing, click the Propose data types button .

  2. In the Propose Data Types dialog box, select 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 and Apply Proposed Types

Examine the new data types that the Fixed-Point Tool proposed for ex_bus_Fix.

  1. On the Fixed-Point Tool toolbar, select Show > Groups that must share the same data type to better understand the proposed data types.

  2. 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.

  3. In the Contents pane, select the SensorData:Speed bus 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 Highlight Elements Sharing Same Data Type to see all of the sources driving the bus element.

  4. Return to the Fixed-Point Tool Workflow tab. Click the Apply accepted data types button to write the proposed data types to the model.

Verify New Fixed-Point Settings

  1. 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.

  2. Simulate the model. This time, the Fixed-Point Tool stores the results in a new run named NoOverride.

  3. In the Fixed-Point Tool Contents pane, verify that there are no overflows in the NoOverride run.

  4. Click Compare Runs

    to launch the Simulation Data Inspector.

    In the Simulation Data Inspector, compare the results of NoOverride to the results of the DoubleOverride run.

  5. 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.

  6. Click the Remove overrides and disable range collection button to remove instrumentation and restore model to maximum simulation speed.

Save the Model and New Bus Data Types

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_Fix, export them from the Bus Editor to a .mat file. For instructions, see Save and Import Bus Objects (Simulink). Alternatively, you can save workspace variables to a file at the MATLAB command line using the save function .

Related Topics

Was this topic helpful?