| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Simulink |
| Contents | Index |
| Learn more about Simulink |
Signal Attributes
The Data Type Conversion block converts an input signal of any Simulink software data type to the data type and scaling 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/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):
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. This is the default value.
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 may be useful in these circumstances:
If you are generating code for a fixed-point processor, the resulting code only uses integers and does not use floating-point operations.
If you want to partition your model based on hardware characteristics. For example, part of your model may involve simulating hardware that produces integers as output.
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.
Suppose that 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 Integer rounding mode parameter to Floor and clear the Saturate on integer overflow check box.
You can use a Data Type Conversion block to cast signal of an enumerated type to a signal of any numeric type, provided that the underlying integers of all enumerated values input to the block are within the range of the numeric type. Otherwise, an error occurs during simulation.
You can use a Data Type Conversion block to cast a signal of any integer type to a signal of an enumerated type, provided that every value input to the Data Type Conversion block is the underlying integer of some value in the enumerated type. Otherwise, an error occurs during simulation.
You cannot use a Data Type Conversion block to cast a non-integer numeric signal an enumerated signal. You cannot cast a complex signal to an enumerated signal regardless of the data types of its real and imaginary parts. See Using Enumerated Data for information about enumerated data types in Simulink.
When you generate code for a Data Type Conversion block that casts to an enumerated type, the code uses safe casting if the block's Saturate on integer overflow option is selected. If the option is cleared, the code does not use safe casting to enumerated types. See Enumerated Type Safe Casting for more information.
The Data Type Conversion block handles any data type supported by Simulink software, including fixed-point and enumerated data types.
For a discussion on the data types supported by Simulink software, see Data Types Supported by Simulink.

Display the Data Type Assistant.
The Data Type Assistant helps you set the Output data type parameter.
See Specifying Block Output Data Types for more information.
See Block-Specific Parameters for the command-line information.
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.
See Block-Specific Parameters for the command-line information.
For more information, see Fixed-Point Tool and Fixed-Point Advisor in the Simulink Fixed Point documentation.
Specify which type of input and output should be equal.
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.
Select the rounding mode for fixed-point operations.
Default: Floor
Round both positive and negative numbers toward positive infinity.
Round number to the nearest representable value. If a tie occurs, round to the nearest even stored value.
Round both positive and negative numbers toward negative infinity.
Round number to the nearest representable value. If a tie occurs, round toward positive infinity.
Round number to the nearest representable value. If a tie occurs, round positive numbers toward positive infinity and round negative numbers toward negative infinity.
This option provides for an optimization of the rounding code for several blocks.
Round number toward zero.
See Block-Specific Parameters for the command-line information.
For more information, see Rounding in the Simulink Fixed Point User's Guide.
Specify whether overflows saturate.
Default: Off
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 which case, no saturation code is necessary.
See Block-Specific Parameters for the command-line information.
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 How to Specify the Sample Time in the online documentation for more information.
See Block-Specific Parameters for the command-line information.
Specify the minimum value that the block should output.
Default: []
The default value, [], is equivalent to -Inf.
Simulink software uses this value to perform:
Parameter range checking (see Checking Parameter Values) for some blocks
Simulation range checking (see Checking Signal Ranges)
Automatic scaling of fixed-point data types
This number must be a double scalar value.
See Block-Specific Parameters for the command-line information.
Specify the maximum value that the block should output.
Default: []
The default value, [], is equivalent to Inf.
Simulink software uses this value to perform:
Parameter range checking (see Checking Parameter Values) for some blocks
Simulation range checking (see Checking Signal Ranges)
Automatic scaling of fixed-point data types
This number must be a double scalar value.
See Block-Specific Parameters for the command-line information.
Specify the output data type.
Default: Inherit: Inherit via internal rule (Discrete-Time Integrator, Gain, Product, Sum, Switch block), Inherit: Inherit from 'Constant value' (Constant block), Inherit: Inherit via back propagation (Data Type Conversion block), Inherit: Same as input (Saturation block)
This option appears for some blocks. Simulink software chooses a combination of output scaling and data type that requires the smallest amount of memory consistent with accommodating the calculated output range and maintaining the output precision of the block and with the word size of the targeted hardware implementation specified for the model. If the Device type parameter on the Hardware Implementation configuration parameters pane is set to ASIC/FPGA, Simulink software chooses the output data type without regard to hardware constraints. Otherwise, Simulink software chooses the smallest available hardware data type capable of meeting the range and precision constraints. For example, if the block multiplies an input of type int8 by a gain of int16 and ASIC/FPGA is specified as the targeted hardware type, the output data type is sfix24. If Unspecified (assume 32-bit Generic), i.e., a generic 32-bit microprocessor, is specified as the target hardware, the output data type is int32. If none of the word lengths provided by the target microprocessor can accommodate the output range, Simulink software displays an error message in the Simulation Diagnostics Viewer.
Use data type of Constant value parameter. This option appears for some blocks.
Use data type of the driving block.
Use data type of sole input signal. This option appears for some blocks.
Use data type of first input signal. This option appears for some blocks.
Output data type is the same as accumulator data type. This option appears for some blocks.
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 unt32.
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. This option appears for some blocks.
Use a data type object, for example, Simulink.NumericType.
See Block-Specific Parameters for the command-line information.
See Specifying Block Output Data Types in the Simulink User's Guide for more information.
Select the category of data to specify.
Default: Inherit (Constant, Data Type Conversion, Discrete Time Integrator, Gain, Inport, Outport, Product, Saturation, Sum, Switch), Built in (Logical Operator, Relational Operator)
Inheritance rules for data types. Selecting Inherit enables a second menu/text box to the right. The following list is the possible values, which can vary by block:
Inherit from 'Constant value' (Constant block default)
Inherit via internal rule (Discrete-Time Integrator, Gain, Product, Sum, Switch block default)
Inherit via back propogation (Data Type Conversion block default)
auto (Inport, Outport block default)
Logical (see Configuration Parameters: Optimization)
Same as first input
Same as input (Saturation block default)
Same as accumulator
Built-in data types. Selecting Built in enables a second menu/text box to the right. The following list is the possible values, which can vary by block:
double (Constant, Data Type Conversion, Discrete-Time Integrator, Gain, Inport, Outport, Product, Saturation, Sum, Switch block default)
single
int8
uint8
int16
uint16
int32
uint32
boolean (Logical Operator, Relational Operator block default)
Fixed-point data types.
Enumerated data types. This option is available on some blocks. Selecting Enumerated enables a second menu/text box to the right. The following list is the possible values, which can vary by block:
<class name>
Expressions that evaluate to data types. Selecting Expression enables a second menu/text box to the right. The following list is the possible values, which can vary by block:
<data type expression>
Clicking the Show data type assistant button enables this parameter.
See Block-Specific Parameters for the command-line information.
See Using the Data Type Assistant in the Simulink User's Guide.
Specify whether you want the fixed-point data as signed or unsigned.
Default: Signed
Selecting Mode > Fixed point enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify the bit size of the word that holds the quantized integer.
Default: 16
Minimum: 0
Maximum: 32
Large word sizes represent large values with greater precision than small word sizes.
Selecting Mode > Fixed point enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors.
Default: Best precision (Constant), Binary point (Data Type Conversion, Discrete-Time Integrator, Gain, Inport, Outport, Product, Saturation, Sum, Switch), Integer (Logical Operator, Relational Operator)
Specify binary point location.
Enter slope and bias.
Specify best-precision values. This option appears for some blocks.
Specify integer. This setting has the same result as specifying a binary point location and setting fraction length to 0. This option appears for some blocks.
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
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
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.
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify slope for the fixed-point data type.
Default: 2^0
Specify any positive real number.
Selecting Scaling > Slope and bias enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify bias for the fixed-point data type.
Default: 0
Specify any real number.
Selecting Scaling > Slope and bias enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
This example uses the Data Type Conversion block to explain 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.
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); sum += ((in2) << 1);
Direct Feedthrough | Yes |
Sample Time | Inherited from driving block |
Scalar Expansion | N/A |
Dimensionalized | Yes |
Multidimensionalized | Yes |
Zero-Crossing Detection | No |
Data Type Conversion Inherited
![]() | Data Store Write | Data Type Conversion Inherited | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |