This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Autoscaling Data Objects Using the Fixed-Point Tool

The Fixed-Point Tool generates a data type proposal for data objects based on ranges collected through simulation, derived range analysis, and design ranges specified on model objects. The Fixed-Point Tool also takes into consideration any data type constraints imposed by the model objects.

These types of data objects are supported for conversion using the Fixed-Point Tool.

The following sections describe how the tool collects the ranges and analyzes constraints.

Collecting Ranges for Data Objects

The objects in your model that use the same data object to specify its type must all share the same data type. The Fixed-Point Tool collects the ranges for all objects in your model. Objects that must share the same data type are placed in a data type group. The Fixed-Point Tool generates a data type proposal for the group based on the union of the ranges of all model objects in the group.

Collecting Ranges for Parameter Objects

Whenever possible, it is a best practice to specify design range information on the parameter object. When the data type of the parameter object is set to auto, the Fixed-Point Tool follows the same rules as when proposing for inherited data types. The Fixed-Point Tool determines the ranges to use for the data type proposal for a parameter object according to these rules:

CaseHow range is determined
Design ranges are specified on the parameter objectUse design ranges to propose data type
Design ranges are not specified on parameter objectNon-tunable parameter objectUse parameter value to propose data type
Tunable parameter objectDesign minimum and maximum specified on client blocksUse client design range to propose data type
No design ranges specified on client blocksUse parameter value to propose data type but issue warning about unavailability of range
Conflicting design ranges specified on client blocksUse parameter value to propose data type but issue warning about conflicting range

When the design ranges specified on a client block do not match the design ranges of the parameter object, there will be extra shifts and typecasts in the generated code.

Data Type Constraints in Data Objects

Some objects in a shared data type group may contain constraints on the data types they can accept. For example, some blocks can accept only signed data types.

Autoscaling Parameter Objects

The Fixed-Point Tool is not able to detect when a parameter object must be integer only, such as when using a parameter object as a variable for dimensions, variant control, or a Boolean value. In these cases, you must deselect the Accept box in the Fixed-Point Tool proposal stage before applying data types to your model.

Autoscaling Breakpoint Objects

Breakpoint data must always be strictly monotonically increasing. Although a breakpoint data set may be strictly monotonic in double format, due to saturation and quantization, it might not be after conversion to a fixed-point data type. The Fixed-Point Tool accounts for this behavior and proposes a data type large enough to satisfy the monotonicity constraint after conversion. In some cases, the data type is very large in order to satisfy the constraint. In this case, consider editing your breakpoint data such that it can be represented efficiently in fixed point.

Autoscale a Model Using Data Objects for Data Type Definitions

The following model uses several different types of data objects, including Simulink.Bus, Simulink.NumericType, Simulink.LookupTable, and Simulink.Breakpoint objects for data type definition. Use the Fixed-Point Tool to convert the floating-point model, including the data objects used in the model, to fixed point.

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

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

  2. Open the Fixed-Point Tool from the model menu by selecting 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 subsystem you want to convert to fixed point. In this example, select Target Embedded System.

  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.

    When model objects within the system under design share a data type with objects outside of the system under design, data type propagation issues can occur after conversion to fixed point. For this reason, during the preparation stage of the conversion, the Fixed-Point Tool inserts Data Type Conversion blocks at the outputs of the system under design.

    In this example, the tool is not able to automatically insert a Data Type Conversion block at the ex_data_objects/Throttle port because the port uses a bus signal. You can ignore this warning in this case because there are already Data Type Conversion blocks isolating this port inside the Throttle subsystem.

  6. Click the Collect Ranges button to start the simulation. The Fixed-Point Tool stores collected range information in a run titled Ranges (Double).

  7. In the Convert Data Types section, click the Propose Data Types button .

    The Fixed-Point Tool detects data objects in the model and proposes a data type that satisfies the constraints of the data object. You can view all data objects used in a model by selecting Data Objects in the Model Hierarchy pane.

    To learn more about a particular result, select the result in the spreadsheet. The Result Details pane provides more details about the proposal, and gives a link to highlight all blocks in your model using a particular data object.

    The tool displays the proposed data types for all results in the ProposedDT column of the spreadsheet.

  8. To view the data type group that a result belongs to, add the DTGroup column to the spreadsheet. Click the add column button . Select DTGroup in the menu.

    To sort by the DTGroup column, click on the column header. You can now see results that must share the same data type next to each other.

  9. Click the Apply Data Types button to write the proposed data types to the model.

    The Fixed-Point Tool applies the data type proposals to the data objects at their definition. In this example, the data objects are defined in the base workspace. View the details of a particular data object at the MATLAB command line.

    errorDT
      NumericType with properties:
    
          DataTypeMode: 'Fixed-point: binary point scaling'
            Signedness: 'Signed'
            WordLength: 16
        FractionLength: 11
               IsAlias: 1
             DataScope: 'Auto'
            HeaderFile: ''
           Description: ''

Related Topics