Main Content

验证一个浮点嵌入模型

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.

Apply a Data Type Override to Floating-Point Data Types

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, seeControl Data Type Override.

Validate a Single-Precision Model

This example uses theex_single_validationmodel 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.

About the Model

  • The inputsIn2andIn3are double-precision inputs to theSumandProductblocks.

  • The outputs of theSumandProductblocks are data inputs to theMultiport Switchblock.

  • The inputIn1is the control input to theMultiport Switchblock. The value of this control input determines which of its other inputs, the sum ofIn2andIn3or the product ofIn2andIn3, passes to the output port. BecauseIn1is a control input, its data type isint8.

  • TheRelational Operatorblock compares the output of theMultiport Switchblock toIn4, and outputs a Boolean signal.

Run the Example

Open the Model

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

    addpath(fullfile(docroot,'toolbox','simulink','examples')) ex_single_validation

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 theModelingtab, clickUpdate Model.

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

Run Model Advisor Check

  1. From the model, on theModelingtab, clickModel Advisor.

  2. In the System Selector dialog box, clickOK.

    The Model Advisor opens.

  3. In the Model Advisor, expand theBy Tasknode and, underModeling Single-Precision Systems, select theIdentify questionable operations for strict single-precision designcheck.

  4. In the right pane, clickRun 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, seeGetting Started with Single Precision Converter(Fixed-Point Designer).

Blocks That Support Single Precision

对一致格fy Simulink®blocks that support single precision, at the command prompt, entershowblockdatatypetable. In a model, to find blocks that do not support single precision, use the Model Advisor checkIdentify questionable operations for strict single-precision design.

See Also

|

Related Topics