| Simulink Reference | ![]() |
Convert an input signal to a specified data type
Library
Description
The Data Type Conversion block converts an input signal of any Simulink data type to the data type and scaling specified by the block's Output data type mode, Output data type, and/or Output scaling parameters. 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/or scaling for the conversion. If you want to inherit this information from an input signal, you should use the Data Type Conversion Inherited block. |
The Input and output to have equal parameter controls how the input is processed. The possible values are Real World Value (RWV) and Stored Integer (SI):
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. This is the default value.
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 may be useful in these circumstances:
Working with Fixed-Point Values Greater than 32 Bits
The MATLAB built-in integer data types are limited to 32 bits. If you want to output fixed-point numbers that range between 33 and 53 bits without loss of precision or range, you should break the number into pieces using the Gain block, and then output the pieces using the Data Type Conversion block to store the value inside a double.
For example, suppose the original signal is an unsigned 128-bit value with default scaling. You can break this signal into four pieces using four parallel Gain blocks configured with the gain and output settings shown below.
| Piece |
Gain |
Output Data Type |
| 1 |
2^0 |
uint(32) - Least significant 32 bits |
| 2 |
2^-32 |
uint(32) |
| 3 |
2^-64 |
uint(32) |
| 4 |
2^-96 |
uint(32) - Most significant 32 bits |
For each Gain block, you must also configure the Round integer calculations toward parameter to Floor, and the Saturate on integer overflow check box must be cleared.
Data Type Support
The Data Type Conversion block handles any data type supported by Simulink, including fixed-point data types.
For a discussion on the data types supported by Simulink, refer to Data Types Supported by Simulink in the Using Simulink documentation.
Parameters and Dialog Box
Specify via dialog, the Output data type, Output scaling value, and Lock output scaling against changes by the autoscaling tool parameters become visible.
Specify via dialog for the Output data type mode parameter.
Specify via dialog for the Output data type mode parameter.
Specify via dialog for the Output data type mode parameter.
Real World Value (RWV) or the Stored Integer (SI) of the input and output should be the same.
Example 1 -- Real World Values Versus Stored Integers
This example uses the Data Type Conversion block to help you understand the difference between a real-world value and a stored integer. Consider the two fixed-point models shown below.

In the top model, 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. 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 model, 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, 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.
Example 2 -- Real World Values and Stored Integers in Summations
The model shown below illustrates how a summation operation applies to real-world values and stored integers, and how scaling information is dealt with in generated code.

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);
Characteristics
| Direct Feedthrough |
Yes |
| Sample Time |
Inherited from driving block |
| Scalar Expansion |
N/A |
| Dimensionalized |
Yes |
| Zero Crossing |
No |
See Also
Data Type Conversion Inherited
| Data Store Write | Data Type Conversion Inherited | ![]() |
© 1994-2005 The MathWorks, Inc.