Documentation Center |
Convert input signal to specified data type
The Data Type Conversion block converts an input signal of any Simulink^{®} data type to the data type you specify for the Output data type parameter. The input can be any real- or complex-valued signal. If the input is real, the output is real. If the input is complex, the output is complex.
Note This block requires that you specify the data type and scaling for the conversion. If you want to inherit the data type or scaling from an input signal, use the Data Type Conversion Inherited block. |
The Input and output to have equal parameter controls how the block handles the input in the context of fixed point data representation. For more information, see Fixed-Point Numbers.
Select Real World Value (RWV) to treat the input as V = SQ + B, where S is the slope and B is the bias. V is used to produce Q = (V – B)/S, which is stored in the output.
Select Stored Integer (SI) to treat the input as a stored integer, Q. The value of Q is directly used to produce the output. In this mode, the input and output are identical, except that the input is a raw integer lacking proper scaling information. Selecting Stored Integer might be useful in the following cases:
Generating code for a fixed-point processor
The resulting code uses only integers and does not use floating-point operations.
Partitioning your model based on hardware characteristics
For example, part of your model might involve simulating hardware that produces integers as output.
For more information on scaling of fixed point numbers, see Scaling.
Use a Data Type Conversion block to cast enumerated signals as follows.
To cast a signal of enumerated type to a signal of any numeric type
The underlying integers of all enumerated values input to the Data Type Conversion block should be within the range of the numeric type; otherwise, an error occurs during simulation.
To cast a signal of any integer type to a signal of enumerated type
The value input to the Data Type Conversion block should match the underlying value of an enumerated value; otherwise, an error occurs during simulation.
You can enable the block's Saturate on integer overflow parameter so that Simulink uses the default value of the enumerated type when the value input to the block does not match the underlying value of an enumerated value. See Type Casting for Enumerations.
You cannot use a Data Type Conversion block in the following cases.
To cast a non-integer numeric signal to an enumerated signal
To cast a complex signal to an enumerated signal, regardless of the data types of the complex signal's real and imaginary parts.
See About Simulink Enumerations for information on working with enumerated types.
The Data Type Conversion block handles any data type that Simulink supports, including fixed-point and enumerated data types.
For more information, see Data Types Supported by Simulink in the Simulink documentation.
Display the Data Type Assistant.
The Data Type Assistant helps you set the Output data type parameter.
For more information, see Specify Block Output Data Types.
Select to lock the output data type setting of this block against changes by the Fixed-Point Tool and the Fixed-Point Advisor.
Default: Off
Locks the output data type setting for this block.
Allows the Fixed-Point Tool and the Fixed-Point Advisor to change the output data type setting for this block.
Parameter: LockScale |
Type: string |
Value: 'off' | 'on' |
Default: 'off' |
For more information, see Use Lock Output Data Type Setting.
Specify which type of input and output should be equal, in the context of fixed point data representation.
Default: Real World Value (RWV)
Specifies the goal of making the Real World Value (RWV) of the input equal to the Real World Value (RWV) of the output.
Specifies the goal of making the Stored Integer (SI) value of the input equal to the Stored Integer (SI) value of the output.
See Block-Specific Parameters for the command-line information.
Specify the rounding mode for fixed-point operations.
Default: Floor
Rounds both positive and negative numbers toward positive infinity. Equivalent to the MATLAB^{®} ceil function.
Rounds number to the nearest representable value. If a tie occurs, rounds to the nearest even integer. Equivalent to the Fixed-Point Designer™ convergent function.
Rounds both positive and negative numbers toward negative infinity. Equivalent to the MATLAB floor function.
Rounds number to the nearest representable value. If a tie occurs, rounds toward positive infinity. Equivalent to the Fixed-Point Designer nearest function.
Rounds number to the nearest representable value. If a tie occurs, rounds positive numbers toward positive infinity and rounds negative numbers toward negative infinity. Equivalent to the Fixed-Point Designer round function.
Automatically chooses between round toward floor and round toward zero to generate rounding code that is as efficient as possible.
Rounds number toward zero. Equivalent to the MATLAB fix function.
Parameter: RndMeth |
Type: string |
Value: 'Ceiling' | 'Convergent' | 'Floor' | 'Nearest' | 'Round' | 'Simplest' | 'Zero' |
Default: 'Floor' |
For more information, see Rounding in the Fixed-Point Designer documentation.
Specify whether overflows saturate.
Default: Off
Overflows saturate to either the minimum or maximum value that the data type can represent.
For example, an overflow associated with a signed 8-bit integer can saturate to -128 or 127.
Overflows wrap to the appropriate value that is representable by the data type.
For example, the number 130 does not fit in a signed 8-bit integer and wraps to -126.
Consider selecting this check box when your model has possible overflow and you want explicit saturation protection in the generated code.
Consider clearing this check box when you want to optimize efficiency of your generated code.
Clearing this check box also helps you avoid overspecifying how a block handles out-of-range signals. For more information, see Checking for Signal Range Errors.
When you select this check box, saturation applies to every internal operation on the block, not just the output or result.
In general, the code generation process can detect when overflow is not possible. In this case, the code generator does not produce saturation code.
Parameter: SaturateOnIntegerOverflow |
Type: string |
Value: 'off' | 'on' |
Default: 'off' |
Enter the discrete interval between sample time hits or specify another appropriate sample time such as continuous or inherited.
Default: -1
By default, the block inherits its sample time based upon the context of the block within the model. To set a different sample time, enter a valid sample time based upon the table in Types of Sample Time.
See also Specify Sample Time in the online documentation for more information.
See Block-Specific Parameters for the command-line information.
Lower value of the output range that Simulink checks.
Default: [] (unspecified)
Specify this number as a finite, real, double, scalar value.
Note: If you specify a bus object as the data type for this block, do not set the minimum value for bus data on the block. Simulink ignores this setting. Instead, set the minimum values for bus elements of the bus object specified as the data type. For information on the Minimum parameter for a bus element, see Simulink.BusElement. |
Simulink uses the minimum to perform:
Parameter range checking (see Check Parameter Values) for some blocks
Simulation range checking (see Signal Ranges and Enabling Simulation Range Checking)
Automatic scaling of fixed-point data types
Note: Output minimum does not saturate or clip the actual output signal. Use the Saturation block instead. |
Parameter: OutMin |
Type: string |
Value: '[ ]' |
Default: '[ ]' |
Upper value of the output range that Simulink checks.
Default: [] (unspecified)
Specify this number as a finite, real, double, scalar value.
Note: If you specify a bus object as the data type for this block, do not set the maximum value for bus data on the block. Simulink ignores this setting. Instead, set the maximum values for bus elements of the bus object specified as the data type. For information on the Maximum parameter for a bus element, see Simulink.BusElement. |
Simulink uses the maximum value to perform:
Parameter range checking (see Check Parameter Values) for some blocks
Simulation range checking (see Signal Ranges and Enabling Simulation Range Checking)
Automatic scaling of fixed-point data types
Note: Output maximum does not saturate or clip the actual output signal. Use the Saturation block instead. |
Parameter: OutMax |
Type: string |
Value: '[ ]' |
Default: '[ ]' |
Specify the output data type.
Default: Inherit: Inherit via back propagation
Use data type of the driving block.
Output data type is double.
Output data type is single.
Output data type is int8.
Output data type is uint8.
Output data type is int16.
Output data type is uint16.
Output data type is int32.
Output data type is uint32.
Output data type is boolean. The Data Type Conversion block converts real, nonzero numeric values (including NaN and Inf) to boolean true (1).
Output data type is fixed point fixdt(1,16,0).
Output data type is fixed point fixdt(1,16,2^0,0).
Use an enumerated data type, for example, Enum: BasicColors.
Use a data type object, for example, Simulink.NumericType.
See Block-Specific Parameters for the command-line information.
For more information, see Specify Block Output Data Types.
Select the category of data to specify.
Default: Inherit
Inheritance rules for data types. Selecting Inherit enables Inherit via back propagation.
Built-in data types. Selecting Built in enables a second menu/text box to the right. Select one of the following choices:
double (default)
single
int8
uint8
int16
uint16
int32
uint32
boolean
Fixed-point data types.
Enumerated data types. Selecting Enumerated enables a second menu/text box to the right, where you can enter the class name.
Expressions that evaluate to data types. Selecting Expression enables a second menu/text box to the right, where you can enter the expression.
Clicking the Show data type assistant button enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specify Data Types Using Data Type Assistant.
Specify data type override mode for this signal.
Default: Inherit
Inherits the data type override setting from its context, that is, from the block, Simulink.Signal object or Stateflow^{®} chart in Simulink that is using the signal.
Ignores the data type override setting of its context and uses the fixed-point data type specified for the signal.
The ability to turn off data type override for an individual data type provides greater control over the data types in your model when you apply data type override. For example, you can use this option to ensure that data types meet the requirements of downstream blocks regardless of the data type override setting.
This parameter appears only when the Mode is Built in or Fixed point.
Specify whether you want the fixed-point data as signed or unsigned.
Default: Signed
Selecting Mode > Fixed point enables this parameter.
For more information, see Specifying a Fixed-Point Data Type.
Specify the bit size of the word that holds the quantized integer.
Default: 16
Minimum: 0
Maximum: 32
Selecting Mode > Fixed point enables this parameter.
For more information, see Specifying a Fixed-Point Data Type.
Specify the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors.
Default: Best precision
Specify binary point location.
Enter slope and bias.
Specify best-precision values.
Selecting Mode > Fixed point enables this parameter.
Selecting Binary point enables:
Fraction length
Calculate Best-Precision Scaling
Selecting Slope and bias enables:
Slope
Bias
Calculate Best-Precision Scaling
For more information, see Specifying a Fixed-Point Data Type.
Specify fraction length for fixed-point data type.
Default: 0
Binary points can be positive or negative integers.
Selecting Scaling > Binary point enables this parameter.
For more information, see Specifying a Fixed-Point Data Type.
Specify slope for the fixed-point data type.
Default: 2^0
Specify any positive real number.
Selecting Scaling > Slope and bias enables this parameter.
For more information, see Specifying a Fixed-Point Data Type.
Specify bias for the fixed-point data type.
Default: 0
Specify any real number.
Selecting Scaling > Slope and bias enables this parameter.
For more information, see Specifying a Fixed-Point Data Type.
The following modelmodel uses the Data Type Conversion block to explain the difference between a real-world value and a stored integer. Consider these two fixed-point block diagrams:
In the top block diagram, the Data Type Conversion block treats the input as a real-world value, and maps that value to an 8-bit signed generalized fixed-point data type with a scaling of 2^{-2} (i.e., binary point scaling with slope = 2^{-2} and bias = 0). When the value is then output from the Data Type Conversion1 block as a real-world value, the scaling and data type information is retained and the output value is 001111.00, or 15. When the value is output from the Data Type Conversion2 block as a stored integer, the scaling and data type information is not retained and the stored integer is interpreted as 00111100, or 60.
In the bottom block diagram, the Data Type Conversion3 block treats the input as a stored integer, and the data type and scaling information is not applied. When the value is then output from the Data Type Conversion4 block as a real-world value, the scaling and data type information is applied to the stored integer (Slope = 2^{-2} and Bias = 0), and the output value is 000011.11, or 3.75. When the value is output from the Data Type Conversion5 block as a stored integer, you get back the original input value of 15.
The following modelmodel shows how a summation operation applies to real-world values and stored integers, and how the generated code handles scaling information.
Note that the summation operation produces the correct result when the Data Type Conversion (2 or 5) block outputs a real-world value. This is because the specified scaling information is applied to the stored integer value. However, when the Data Type Conversion4 block outputs a stored integer value, then the summation operation produces an unexpected result due to the absence of scaling information.
If you generate code for the above model, then the code captures the appropriate scaling information. The code for the Sum block is shown below. The inputs to this block are tagged with the specified scaling information so that the necessary shifts are performed for the summation operation.
/* Sum Block: <Root>/Sum * * y = u0 + u1 * * Input0 Data Type: Fixed Point S16 2^-2 * Input1 Data Type: Fixed Point S16 2^-4 * Output0 Data Type: Fixed Point S16 2^-5 * * Round Mode: Floor * Saturation Mode: Wrap * */ sum = ((in1) << 3); sum += ((in2) << 1);