Products & Services Industries Academia Support User Community Company

Learn more about Simulink   

Data Type Conversion - Convert input signal to 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 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.

The Input and output to have equal parameter controls how the block handles the input. 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.

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 in the following table.

PieceGainOutput 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.

How Casting Works with Enumerated Signals

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 you select the Saturate on integer overflow check box. If you clear this check box, the code does not use safe casting for enumerated types. See Enumerated Type Safe Casting for more information.

Data Type Support

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.

Parameters and Dialog Box

Show data type assistant

Display the Data Type Assistant.

Settings

The Data Type Assistant helps you set the Output data type parameter.

See Specifying Block Output Data Types for more information.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Lock output data type setting against changes by the fixed-point tools

Select to lock the output data type setting of this block against changes by the Fixed-Point Tool and the Fixed-Point Advisor.

Settings

Default: Off

On

Locks the output data type setting for this block.

Off

Allows the Fixed-Point Tool and the Fixed-Point Advisor to change the output data type setting for this block.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

For more information, see Fixed-Point Tool and Fixed-Point Advisor in the Simulink Fixed Point documentation.

Input and output to have equal

Specify which type of input and output should be equal.

Settings

Default: Real World Value (RWV)

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.

Stored Integer (SI)

Specifies the goal of making the Stored Integer (SI) value of the input equal to the Stored Integer (SI) value of the output.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Integer rounding mode

Specify the rounding mode for fixed-point operations.

Settings

Default: Floor

Ceiling

Rounds both positive and negative numbers toward positive infinity. Equivalent to the MATLAB ceil function.

Convergent

Rounds number to the nearest representable value. If a tie occurs, rounds to the nearest even integer. Equivalent to the Fixed-Point Toolbox™ convergent function.

Floor

Rounds both positive and negative numbers toward negative infinity. Equivalent to the MATLAB floor function.

Nearest

Rounds number to the nearest representable value. If a tie occurs, rounds toward positive infinity. Equivalent to the Fixed-Point Toolbox nearest function.

Round

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 Toolbox round function.

Simplest

Automatically chooses between round toward floor and round toward zero to generate rounding code that is as efficient as possible.

Zero

Rounds number toward zero. Equivalent to the MATLAB fix function.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

For more information, see Rounding in the Simulink Fixed Point User's Guide.

Saturate on integer overflow

Specify whether overflows saturate.

Settings

Default: Off

On

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.

Off

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.

Tips

Command-Line Information

See Block-Specific Parameters for the command-line information.

Sample time (-1 for inherited)

Enter the discrete interval between sample time hits or specify another appropriate sample time such as continuous or inherited.

Settings

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.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Output minimum

Specify the minimum value that the block should output.

Settings

Default: []

The default value, [], is equivalent to -Inf.

Simulink software uses this value to perform:

Tip

This number must be a double scalar value.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Output maximum

Specify the maximum value that the block should output.

Settings

Default: []

The default value, [], is equivalent to Inf.

Simulink software uses this value to perform:

Tip

This number must be a double scalar value.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Output data type

Specify the output data type.

Settings

Default: Inherit: Inherit via back propagation

Inherit: Inherit via back propagation

Use data type of the driving block.

double

Output data type is double.

single

Output data type is single.

int8

Output data type is int8.

uint8

Output data type is uint8.

int16

Output data type is int16.

uint16

Output data type is uint16.

int32

Output data type is int32.

uint32

Output data type is uint32.

boolean

Output data type is boolean.

fixdt(1,16,0)

Output data type is fixed point fixdt(1,16,0).

fixdt(1,16,2^0,0)

Output data type is fixed point fixdt(1,16,2^0,0).

Enum: <class name>

Use an enumerated data type, for example, Enum: BasicColors.

<data type expression>

Use a data type object, for example, Simulink.NumericType.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

See Specifying Block Output Data Types in the Simulink User's Guide for more information.

Mode

Select the category of data to specify.

Settings

Default: Inherit

Inherit

Inheritance rules for data types. Selecting Inherit enables Inherit via back propagation.

Built in

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

Fixed-point data types.

Enumerated

Enumerated data types. Selecting Enumerated enables a second menu/text box to the right, where you can enter the class name.

Expression

Expressions that evaluate to data types. Selecting Expression enables a second menu/text box to the right, where you can enter the expression.

Dependency

Clicking the Show data type assistant button enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

See Using the Data Type Assistant in the Simulink User's Guide.

Signedness

Specify whether you want the fixed-point data as signed or unsigned.

Settings

Default: Signed

Signed

Specify the fixed-point data as signed.

Unsigned

Specify the fixed-point data as unsigned.

Dependencies

Selecting Mode > Fixed point enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.

Word length

Specify the bit size of the word that holds the quantized integer.

Settings

Default: 16

Minimum: 0

Maximum: 32

Large word sizes represent large values with greater precision than small word sizes.

Dependencies

Selecting Mode > Fixed point enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.

Scaling

Specify the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors.

Settings

Default: Binary point

Binary point

Specify binary point location.

Slope and bias

Enter slope and bias.

Dependencies

Selecting Mode > Fixed point enables this parameter.

Selecting Binary point enables:

Selecting Slope and bias enables:

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.

Fraction length

Specify fraction length for fixed-point data type.

Settings

Default: 0

Binary points can be positive or negative integers.

Dependencies

Selecting Scaling > Binary point enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.

Slope

Specify slope for the fixed-point data type.

Settings

Default: 2^0

Specify any positive real number.

Dependencies

Selecting Scaling > Slope and bias enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.

Bias

Specify bias for the fixed-point data type.

Settings

Default: 0

Specify any real number.

Dependencies

Selecting Scaling > Slope and bias enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.

Examples

Real World Values Versus Stored Integers

The following model 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. 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, 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.

Real World Values and Stored Integers in Summations

The following model 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);

Characteristics

Direct Feedthrough

Yes

Sample Time

Inherited from driving block

Scalar Expansion

N/A

Dimensionalized

Yes

Multidimensionalized

Yes

Zero-Crossing Detection

No

See Also

Data Type Conversion Inherited

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2010- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS