Main Content

Validate a Floating-Point Embedded Model

You can use data type override mode to temporarily switch the data types in your model. This capability allows you to maintain one model but simulate your model using multiple data types, and validate the numerical behavior for each type. For example, if you implement an algorithm using double-precision data types and want to check whether the algorithm is also suitable for single-precision use, you can apply a data type override to floating-point data types to replace all doubles with singles without permanently affecting any other data types in your model.

To apply data type override, you must specify the data type that you want to apply and the data type that you want to replace.

You can set data type override using the following method. This example changes all floating-point data types to single.

For example:

set_param(gcs, 'DataTypeOverride', 'Single',...
 'DataTypeOverrideAppliesTo','Floating-point');

For more information on data type override settings, see Control Data Type Override.

Explore the Model

This example uses the ex_single_validation model to show how you can use data type override. It proves that an algorithm, which implements double-precision data types, is also suitable for single-precision embedded use.

Open the model

open_system('ex_single_validation')

  • The inputs In2 and In3 are double-precision inputs to the Sum and Product blocks.

  • The outputs of the Sum and Product blocks are data inputs to the Multiport Switch block.

  • The input In1 is the control input to the Multiport Switch block. The value of this control input determines which of its other inputs, the sum of In2 and In3 or the product of In2 and In3, passes to the output port. Because In1 is a control input, its data type is int8.

  • The Relational Operator block compares the output of the Multiport Switch block to In4, and outputs a Boolean signal.

Validate a Single-Precision Model

Override Floating-Point Data Types with Singles

  1. At the command line, override the floating-point data types in the model with singles

    set_param(gcs, 'DataTypeOverride', 'Single',...
     'DataTypeOverrideAppliesTo','Floating-point');
  2. In the model, on the Modeling tab, click Update Model.

    The data type override replaces all the floating-point (double) data types in the model with single data types, but does not affect the integer or Boolean data types.

    Model with data type annotations displayed for all of the blocks. In the model, all of the double data types have been replaced with single data types.

Run Model Advisor Check

  1. From the model, on the Modeling tab, click Model Advisor.

  2. In the System Selector dialog box, click OK.

    The Model Advisor opens.

  3. In the Model Advisor, expand the By Task node and, under Modeling Single-Precision Systems, select the Identify questionable operations for strict single-precision design check.

  4. In the right pane, click Run This Check.

    The check passes indicating that this algorithm is suitable for single-precision use. To ensure that no double-precision data types remain in the generated code, use the Single-Precision Converter before generating code for single-precision embedded use. For more information, see Getting Started with Single Precision Converter (Fixed-Point Designer).

Blocks That Support Single Precision

To identify Simulink® blocks that support single precision, at the command prompt, enter showblockdatatypetable. In a model, to find blocks that do not support single precision, use the Model Advisor check Identify questionable operations for strict single-precision design.

See Also

|

Related Topics