Simulink Reference Previous page   Next Page
Data Type Conversion

Convert an input signal to a specified data type

Library

Signal Attributes

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.

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):

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

Output data type mode
You can set the output signal to a built-in data type from this drop-down list, or you can choose to inherit the output data type and scaling by backpropagation. Lastly, if you choose Specify via dialog, the Output data type, Output scaling value, and Lock output scaling against changes by the autoscaling tool parameters become visible.
Output data type
Set the output data type. This parameter is only visible if you select Specify via dialog for the Output data type mode parameter.
Output scaling value
Set the output scaling using either binary point-only or [Slope Bias] scaling. This parameter is only visible if you select Specify via dialog for the Output data type mode parameter.
Lock output scaling against changes by the autoscaling tool
Select to lock scaling of outputs. This parameter is only visible if you select Specify via dialog for the Output data type mode parameter.
Input and output to have equal
Specify whether the Real World Value (RWV) or the Stored Integer (SI) of the input and output should be the same.
Round integer calculations toward
Select the rounding mode for fixed-point operations.
Saturate on integer overflow
Select to have overflows saturate.

Examples

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 += ((in2) << 1);

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


Previous page  Data Store Write Data Type Conversion Inherited Next page

© 1994-2005 The MathWorks, Inc.