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.
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, see Control Data Type Override.
Validate a Single-Precision 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.
About the Model
The inputs
In2
andIn3
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 ofIn2
andIn3
or the product ofIn2
andIn3
, passes to the output port. BecauseIn1
is a control input, its data type isint8
.The Relational Operator block compares the output of the Multiport Switch block to
In4
, and outputs a Boolean signal.
Run the Example
Open the Model
Open the
ex_single_validation
model. At the MATLAB® command line, enter:addpath(fullfile(docroot,'toolbox','simulink','examples')) ex_single_validation
Override Floating-Point Data Types With Singles
At the command line, override the floating-point data types in the model with singles
set_param(gcs, 'DataTypeOverride', 'Single',... 'DataTypeOverrideAppliesTo','Floating-point');
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 withsingle
data types, but does not affect the integer or Boolean data types.
Run Model Advisor Check
From the model, on the Modeling tab, click Model Advisor.
In the System Selector dialog box, click OK.
The Model Advisor opens.
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.
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
Simulink.AliasType
| Simulink.NumericType
Related Topics
- Single-Precision Design for Simulink Models (Fixed-Point Designer)
- Specify Single-Precision Data Type for Embedded Application (Simulink Coder)
- Control Data Types of Signals
- Default for underspecified data type
- Identify questionable operations for strict single-precision design
- Inf or NaN block output
- About Data Types in Simulink