Propose Data Types for a Referenced Model

This example shows how to propose data types for a referenced model.

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

    addpath(fullfile(docroot,'toolbox','fixpoint','examples'));
    ex_mdlref_controller

  2. In the model menu, select Analysis > Data Type Design > Fixed-Point Tool.

  3. In the Fixed-Point Tool, in the Prepare System section of the toolstrip, under System Under Design, select the ex_controller model as the system you want to convert to fixed point.

  4. In the Collect Ranges section, select Simulation Ranges as the range collection method.

  5. Click the Prepare button. The Fixed-Point Tool checks the system under design for compatibility with the conversion process and reports any issues found in the model. In this example, the tool reports that the model is ready for conversion.

  6. Click the Collect Ranges button to start the simulation. The Fixed-Point Tool overrides the data types in the model with doubles and collects the minimum and maximum values for each object in your model that occur during the simulation. The Fixed-Point Tool stores this range information in a run titled Ranges (Double).

  7. In the Convert Data Types section of the toolstrip, click Settings. Specify the Safety margin for simulation min/max (%) parameter as 20.

  8. Click Propose Data Types.

    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 Safety margin for simulation min/max (%) parameter value multiplies the “raw” simulation values by a factor of 1.2. Setting the Safety margin for simulation min/max (%) 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 produces 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.

    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.

    The Fixed-Point Tool uses the minimum and maximum values collected during simulation to propose a scaling for each block such that the precision is maximized while the full range of simulation values is spanned. The tool displays the proposed scaling in the spreadsheet.

  9. 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. 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 is selected for each of the Controller system’s blocks.

    To view more information about a proposal, select the result and view the Result Details pane.

  10. In the Fixed-Point Tool, click the Apply Data Types button.

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

  11. In the Verify section of the toolstrip, click the Simulate with Embedded Types button.

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

  12. Click Compare Results. The Simulation Data Inspector plots the Analog Plant output for the floating-point and fixed-point runs and the difference between them.

Related Topics