Documentation Center

  • Trial Software
  • Product Updates

Propose Data Types for a Referenced Model

This example shows how to propose data types for a referenced model. To run this example, you must first run the "Log Simulation Minimum and Maximum Values for Referenced Models" example.

  1. In the Model Hierarchy pane of the Fixed-Point Tool, select the ex_controller model.

  2. In the Automatic data typing for selected system pane, click the Configure link and verify that Propose fraction lengths for specified word lengths is selected.

  3. In the same pane, specify the Safety margin for simulation min/max (%) parameter as 20 and click Apply.

  4. In the Fixed-Point Tool, click Propose fraction lengths, .

    Because no design minimum and maximum information is supplied, the simulation minimum and maximum data that was collected during the simulation run is used to propose data types. The Percent safety margin for simulation min/max parameter value multiplies the "raw" simulation values by a factor of 1.2. Setting this parameter to a value greater than 1 decreases the likelihood that an overflow will occur when fixed-point data types are being used.

    Because of the nonlinear effects of quantization, a fixed-point simulation will produce results that are different from an idealized, doubles-based simulation. Signals in a fixed-point simulation can cover a larger or smaller range than in a doubles-based simulation. If the range increases enough, overflows or saturations could occur. A safety margin decreases the likelihood of this happening, but it might also decrease the precision of the simulation.

  5. In the Propose Data Types dialog box, select double_run and click OK.

    The Fixed-Point Tool analyzes the scaling of all fixed-point blocks whose:

    • Lock output data type setting against changes by the fixed-point tools parameter is not selected.

    • Output data type parameter specifies a generalized fixed-point number.

    The Fixed-Point Tool uses the minimum and maximum values stored in the selected run to propose each block's scaling such that the precision is maximized while the full range of simulation values is spanned. The tool displays the proposed scaling in its Contents pane. Now, it displays the Automatic Data Typing View to provide information, such as ProposedDT, ProposedMin, ProposedMax, which are relevant at this stage of the fixed-point conversion.

  6. Review the scaling that the Fixed-Point Tool proposes. You can choose to accept the scaling proposal for each block by selecting the corresponding Accept check box in the Contents pane. By default, the Fixed-Point Tool accepts all scaling proposals that differ from the current scaling. For this example, verify that the Accept check box associated with the active run is selected for each of the Controller subsystem's blocks.

    The Fixed-Point Tool does not propose a data type for Combine Terms:Accumulator and displays n/a in the ProposedDT column. The tool does not propose a data type because the SpecifiedDT is Inherit: Inherit via internal rule. To view more information about a proposal, click the Show details for selected result button .

  7. In the Fixed-Point Tool, click the Apply accepted fraction lengths button .

    The Fixed-Point Tool applies to the scaling proposals that you accepted in the previous step.

  8. In the Model Hierarchy pane of the Fixed-Point Tool, select the ex_mdlref_controller model.

    1. In the Settings for selected system pane, set Data type override to Use local settings. This option enables each of the model's subsystems to use its locally specified data type settings, however, it does not apply to the referenced model.

    2. In the Data collection pane, set Store results in run to scaled_fixed_run and then click Apply.

  9. In the Model Hierarchy pane, select the ex_controller model and set its Data type override parameter as Use local settings and click Apply.

  10. In the Fixed-Point Tool, click Simulate.

    The Simulink® software simulates the ex_mdlref_controller model using the new scaling that you applied. Afterward, the Fixed-Point Tool displays in its Contents pane information about blocks that logged fixed-point data.

  11. Use the Simulation Data Inspector to plot the Analog Plant output for the floating-point and fixed-point runs and the difference between them.

    The difference plot shows that the difference between the floating-point signal and the fixed-point signal is within the specified tolerance of 0.04.

Was this topic helpful?