Documentation Center

  • Trial Software
  • Product Updates

Automatic Data Typing Using Simulation Data

Workflow for Automatic Data Typing Using Simulation Data

For more information about a step in the workflow, click the relevant box.

Set Up the Model

To use the Fixed-Point Tool to generate data type proposals for your model based on simulation minimum and maximum values only, you must first set up your model in Simulink®.

  1. Back up your model in case of error and as a baseline for testing and validation.

  2. Open your model in Simulink.

  3. From the Simulink menu, select Simulation > Mode > Normal so that the model runs in Normal mode. The Fixed-Point Tool supports only Normal mode.

  4. If you are using design minimum and maximum range information, add this information to blocks.

    You specify a design range for model objects using parameters typically titled Output minimum and Output maximum. For a list of blocks that permit you to specify these values, see Blocks That Allow Signal Range Specification.

  5. Specify fixed-point data types for blocks and signals in your model. For blocks with the Data Type Assistant, use the Calculate Best-Precision Scaling button to calculate best-precision scaling automatically. For more information, see Specify Fixed-Point Data Types with the Data Type Assistant. Use the Fixed-Point Advisor to prepare your model for conversion to an equivalent fixed-point representation For more information, see Preparation for Fixed-Point Conversion.

  6. You can choose to lock some blocks against automatic data typing by selecting the Lock output data type setting against changes by the fixed-point tools parameter. If you select the Lock output data type setting against changes by the fixed-point tools parameter, the tool does not propose data types for that object.

  7. From the Simulink Simulation menu, select Update Diagram to perform parameter range checking for all blocks in the model.

    If update diagram fails, use the failure information to fix the errors in your model. After fixing the errors, test update diagram again. If you are unable to fix the errors, restore your back-up model.

  8. If the model changed, back up the model again in case of error and as a baseline for testing and validation.

  9. Create a shortcut to capture the initial fixed-point instrumentation and data type override settings. For more information, see Capture Model Settings Using the Shortcut Editor.

Prepare the Model for Fixed-Point Conversion

First use the Fixed-Point Advisor to prepare the model for conversion to fixed point. You do this preparation only once. The Fixed-Point Advisor gives advice about model and block configuration settings to prepare for automatic conversion to fixed point using the Fixed-Point Tool. The Fixed-Point Advisor:

  • Checks the model against fixed-point guidelines.

  • Identifies unsupported blocks.

  • Removes output data type inheritance from blocks.

The Fixed-Point Advisor also makes recommendations for a model, such as model-level diagnostic settings and removal of inheritance rules. It configures the model for autoscaling by the Fixed-Point Tool. Therefore, even if your model uses only fixed-point data types, it is useful to run the Fixed-Point Advisor on the model.

To open the Fixed-Point Advisor:

  1. From the Simulink Analysis menu, select Fixed-Point Tool.

  2. On the Fixed-Point Tool Model Hierarchy pane, select the system or subsystem of interest.

  3. On the Fixed-point preparation for selected system pane, click Fixed-Point Advisor.

    Use the Fixed-Point Advisor to prepare the model for conversion. For more information, see Preparation for Fixed-Point Conversion.

Gather a Floating-Point Benchmark

First, run the model with a global override of the fixed-point data types using double-precision numbers to avoid quantization effects. This action provides a floating-point benchmark that represents the ideal output. The Simulink software logs the signal logging results to the MATLAB® workspace. The Fixed-Point Tool displays the simulation results, including minimum and maximum values, that occur during the run.

  1. From the Simulink Analysis menu, select Fixed-Point Tool.

  2. Enable signal logging for the system or subsystem of interest. Using the Fixed-Point Tool you can enable signal logging for multiple signals simultaneously. For more information, see Signal Logging Options in the fxptdlg Reference.

    To enable signal logging:

    1. On the Fixed-Point Tool Model Hierarchy pane, select the system or subsystem.

    2. Right-click the selected system to open the context menu.

    3. Use the Enable Signal Logging option to enable signal logging, as necessary.

    The Contents pane of the Fixed-Point Tool displays an antenna icon next to items that have signal logging enabled.

      Note:   You can plot results only for signals that have signal logging enabled.

  3. On the Fixed-Point Tool Model Hierarchy pane, select the system or subsystem for which you want a proposal.

  4. On the Shortcuts to set up runs pane, click the Model-wide double override and full instrumentation button to set:

    • Data type override to Double

    • Data type override applies to to All numeric types

    • Fixed-point instrumentation mode to Minimums, maximums and overflows

    • The run name (in the Data collection pane Store results in run field) to DoubleOverride

    The Fixed-Point Tool performs a global override of the fixed-point data types with double-precision data types, thus avoiding quantization effects. During simulation, the tool logs minimum value, maximum value, and overflow data for all blocks in the current system or subsystem in the run DoubleOverride.

      Note:   Data type override does not apply to boolean or enumerated data types.

  5. Click the Fixed-Point Tool Simulate button to run the simulation.

    The Fixed-Point Tool highlights any simulation results that have issues, such as overflows or saturations.

Proposing Data Types

Unless you select an object's Lock output data type setting against changes by the fixed-point tools parameter or the data types are using inheritance rules, the Fixed-Point Tool proposes data types for model objects that specify fixed-point data types.

When proposing data types, the Fixed-Point Tool collects the following types of range data for model objects:

  • Design minimum or maximum values — You specify a design range for model objects using parameters typically titled Output minimum and Output maximum. For a list of blocks that permit you to specify these values, see Blocks That Allow Signal Range Specification.

  • Simulation minimum or maximum values — When simulating a system whose Fixed-point instrumentation mode parameter specifies Minimums, maximums and overflows, the Fixed-Point Tool logs the minimum and maximum values generated by model objects. For more information about the Fixed-point instrumentation mode parameter, see fxptdlg.

  • Derived minimum or maximum values — When deriving minimum and maximum values for a selected system, the Fixed-Point Tool uses the design minimum and maximum values that you specify for the model to derive range information for signals in your model. For more information, see Derive Ranges.

The Fixed-Point Tool uses available range data to calculate data type proposals according to the following rules:

  • Design minimum and maximum values take precedence over the simulation and derived range.

    The Safety margin for design and derived min/max (%) parameter specifies a range that differs from that defined by the design range. For example, a value of 20 specifies that a range of at least 20 percent larger is desired. A value of -10 specifies that a range of up to 10 percent smaller is acceptable. If this parameter is not visible in the Automatic data typing for selected system pane, click the Configure link.

  • The tool observes the derived range only when the Derived min/max option is selected. Otherwise, the tool ignores the derived range.

    The Safety margin for design and derived min/max (%) parameter specifies a range that differs from that defined by the derived range. For example, a value of 20 specifies that a range of at least 20 percent larger is desired. A value of -10 specifies that a range of up to 10 percent smaller is acceptable. If this parameter is not visible in the Automatic data typing for selected system pane, click the Configure link.

  • The tool observes the simulation range only when the Simulation min/max option is selected. Otherwise, the tool ignores the simulation range.

    The Safety margin for simulation min/max (%) parameter specifies a range that differs from that defined by the simulation range. For example, a value of 20 specifies that a range of at least 20 percent larger is desired. A value of -10 specifies that a range of up to 10 percent smaller is acceptable. If this parameter is not visible in the Automatic data typing for selected system pane, click the Configure link.

Propose Data Types

  1. In the Automatic data typing for selected system Settings pane, select either Propose fraction lengths for specified word lengths or Propose word lengths for specified fraction lengths.

    If these options are not visible, use the Configure link to display them.

  2. To use simulation min/max information only, clear Derived min/max.

  3. If you have safety margins to apply:

    1. Enter Safety margin for design and derived min/max (%), if applicable. For example, enter 10 for a 10% safety margin. If this parameter is not visible in the Automatic data typing for selected system pane, click the Configure link.

    2. Enter Safety margin for simulation min/max (%), if applicable.

  4. Click the Propose fraction lengths or Propose word lengths button to generate a proposal, .

      Note:   When the Fixed-Point Tool proposes data types, it does not alter your model.

    If there are conflicts in your model, the Fixed-Point Tool displays the Result Details dialog box.

    If you do not see this warning, there are no conflicts in your model. Go to Apply Proposed Data Types.

Examine Results to Resolve Conflicts

You can examine each proposal using the Result Details dialog box, which displays the rationale underlying the proposed data types. Also, this dialog box describes potential issues or errors, and it suggests methods for resolving them. To open the dialog box:

  1. On the Contents pane, select an object that has proposed data types.

  2. Click the Show details for selected result button .

The Result Details dialog box provides the following information about the proposed data types, as appropriate.

Summary

Details which run the result is in and the current data type specified for the selected object.

Proposed Data Type Summary

Describes a proposal in terms of how it differs from the object's current data type. For cases when the Fixed-Point Tool does not propose data types, this section provides a rationale. For example, the data type might be locked against changes by the fixed-point tools.

Needs Attention

Lists potential issues and errors associated with data type proposals. It describes the issues and suggests methods for resolving them. The dialog box uses the following icons to differentiate warnings from errors:

Indicates a warning message.

Indicates an error message.

Shared Data Type Summary

This section of the dialog box informs you that the selected object must share the same data type as other objects in the model because of data type propagation rules. For example, the inputs to a Merge block must have the same data type. Therefore, the outputs of blocks that connect to these inputs must share the same data type. Similarly, blocks that are connected by the same element of a virtual bus must share the same data type.

The dialog box provides a hyperlink that you can click to highlight the objects that share data types in the model. To clear this highlighting, from the model View menu, select Remove Highlighting.

The Fixed-Point Tool allocates an identification tag to objects that must share the same data type. The tool displays this identification tag in the DTGroup column for the object. To display only the objects that must share data types, from the Fixed-Point Tool main toolbar, select the Show option.

Constrained Data Type Summary

Some Simulink blocks accept only certain data types on some ports. This section of the dialog box informs you when a block that connects to the selected object has data type constraints that impact the proposed data type of the selected object. The dialog box lists the blocks that have data type constraints, provides details of the constrained data types, and links to the blocks in the model.

Data Type Details

Provides a table with model object attributes that influence its data type proposal.

ItemDescription

Currently Specified Data Type

Data type that an object specifies.

Proposed Data Type

Data type that the Fixed-Point Tool proposes for this object.

Proposed Representable Maximum

Maximum value that the proposed data type can represent.

Design Maximum

Design maximum value that an object specifies using, e.g., its Output maximum parameter.

Simulation Maximum

Maximum value that occurs during simulation.

Simulation Minimum

Minimum value that occurs during simulation.

Design Minimum

Design minimum value that an object specifies using, e.g., its Output minimum parameter.

Proposed Representable Minimum

Minimum value that the proposed data type can represent.

The dialog box table also includes a column titled Percent Proposed Representable. This column indicates the percentage of the proposed representable range that each value covers. Overflows occur when values lie outside this range.

Shared Values.  When proposing data types, the Fixed-Point Tool attempts to satisfy data type requirements that model objects impose on one another. For example, the Sum block provides an option that requires all of its inputs to have the same data type. Consequently, the dialog box table might also list attributes of other model objects that impact the proposal for the selected object. In such cases, the table displays the following types of shared values:

  • Initial Values

    Some model objects provide parameters that allow you to specify the initial values of their signals. For example, the Constant block includes a Constant value parameter that initializes the block output signal. The Fixed-Point Tool uses initial values to propose data types for model objects whose design and simulation ranges are unavailable. When data type dependencies exist, the tool considers how initial values impact the proposals for neighboring objects.

  • Model-Required Parameters

    Some model objects require the specification of numeric parameters to compute the value of their outputs. For example, the Table data parameter of an n-D Lookup Table block specifies values that the block requires to perform a lookup operation and generate output. When proposing data types, the Fixed-Point Tool considers how this "model-required" parameter value impacts the proposals for neighboring objects.

To Examine the Results and Resolve Conflicts

  1. On the Fixed-Point Tool toolbar, use the Show option to filter the results to show Conflicts with proposed data types.

    The Fixed-Point Tool lists its data type proposals on the Contents pane under the ProposedDT column. The tool alerts you to potential issues for each object in the list by displaying a green, yellow, or red icon.

    The proposed data type poses no issues for this object.

    The proposed data type poses potential issues for this object.

    The proposed data type will introduce data type errors if applied to this object.

  2. Review and fix each error.

    1. Select the error, right-click and select Highlight Block In Model from the context menu to identify which block has a conflict.

    2. Click the Show details for selected result button to open the Result Details dialog box.

    3. Use the information provided in the Needs Attention section of the Result Details dialog box to resolve the conflict by fixing the problem in the Simulink model.

  3. Review the Result Details for the warnings and correct the problem if necessary.

  4. You have changed the Simulink model, so the benchmark data is not up to date. Click the Fixed-Point Tool Start button to rerun the simulation.

    The Fixed-Point Tool warns you that you have not applied proposals. Click the Ignore and Simulate button to continue.

  5. Click the Propose fraction lengths or Propose word lengths button to generate a proposal, .

  6. On the Fixed-Point Tool toolbar, use the Show option to filter the results to show All results.

Apply Proposed Data Types

After reviewing the data type proposals, apply the proposed data types to your model. The Fixed-Point Tool allows you to apply its data type proposals selectively to objects in your model. On the Contents pane, use the Accept check box to specify the proposals that you want to assign to model objects. The check box indicates the status of a proposal:

The Fixed-Point Tool will apply the proposed data type to this object. By default, the tool selects the Accept check box when a proposal differs from the object's current data type.

The Fixed-Point Tool will ignore the proposed data type and leave the current data type intact for this object.

No proposal exists for this object, for example, when the object specifies a data type inheritance rule or is locked against automatic data typing.

  1. Examine each result. For more information about a particular result, select the result and then click the Show details for selected result button to display the Result Details dialog box.

  2. If you do not want to accept the proposal for a result, on the Fixed-Point Tool Contents pane, clear the Accept check box for that result.

    Before applying proposals to your model, you can customize them with the Fixed-Point Tool. On the Contents pane, click a ProposedDT cell and edit the data type expression. For information about specifying fixed-point data types, see fixdt.

  3. Click the Apply accepted fraction lengths or Apply accepted word lengths button to write the proposed data types to the model.

    If you have not fixed all the warnings in the model, the Fixed-Point Tool displays a warning dialog box.

Verify New Settings

After applying proposed data types to your model, you simulate the model using the applied fixed-point data types.

  1. On the Fixed-Point Tool Model Hierarchy pane, select the system or subsystem for which you want a proposal.

  2. On the Shortcuts to set up runs pane, click the Model-wide no override and full instrumentation button to use the locally specified data type settings.

    This sets:

    • Data type override to Use local settings.

    • Fixed-point instrumentation mode to Minimums, maximums and overflows.

    • The run name (in the Data collection pane Store results in run field) to NoOverride.

    Using these settings, the Fixed-Point Tool simulates the model using the new fixed-point settings and logs minimum value, maximum value, and overflow data for all blocks in the current system or subsystem in the run NoOverride.

  3. Click the Fixed-Point Tool Start button to run the simulation.

  4. Compare the ideal results stored in the DoubleOverride run with the fixed-point results in the NoOverride run:

    1. On the Contents pane, select a result that has logged signal data. These results are annotated with the icon.

    2. Click the Compare Signals to view the difference between the fixed-point and double override runs for the selected result.

      If you have more than two runs, in the Compare Runs Selector dialog box, select the two runs that you want to compare.

Automatic Data Typing of Simulink Signal Objects

The Fixed-Point Tool can propose new data types for Simulink signal objects in the base or model workspace. If you accept the proposed data types, the Fixed-Point Tool automatically applies them to the Simulink signal objects.

    Caution   The Fixed-Point Tool does not save the changes to the signal object. Before closing the model, you must save the changes.

    After automatic data typing, if you delete or manipulate a signal object in the base workspace, you must rerun the automatic data typing.

Was this topic helpful?