This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Fixed-Point Data in MATLAB and Simulink

Fixed-Point Data in Simulink

You can use the fixdt function in Simulink® to specify a fixed-point data type. The fixdt function creates a Simulink.NumericType object.

Fixed-Point Data Type and Scaling Notation

Simulink data type names must be valid MATLAB® identifiers with less than 128 characters. The data type name provides information about container type, number encoding, and scaling.

The following table provides a key for various symbols that appear in Simulink products to indicate the data type and scaling of a fixed-point value.

Symbol

Description

Example

Container Type

ufix

Unsigned fixed-point data type

ufix8 is an 8-bit unsigned fixed-point data type

sfix

Signed fixed-point data type

sfix128 is a 128-bit signed fixed-point data type

fltu

Scaled double override of an unsigned fixed-point data type (ufix)

fltu32 is a scaled doubles override of ufix32

flts

Scaled double override of a signed fixed-point data type (sfix)

flts64 is a scaled doubles override of sfix64

Number Encoding

e

10^

125e8 equals 125*(10^(8))

n

Negative

n31 equals -31

p

Decimal point

1p5 equals 1.5

p2 equals 0.2

Scaling Encoding

S

Slope

ufix16_S5_B7 is a 16-bit unsigned fixed-point data type with Slope of 5 and Bias of 7

B

Bias

ufix16_S5_B7 is a 16-bit unsigned fixed-point data type with Slope of 5 and Bias of 7

E

Fixed exponent (2^)

A negative fixed exponent describes the fraction length

sfix32_En31 is a 32-bit signed fixed-point data type with a fraction length of 31

F

Slope adjustment factor

ufix16_F1p5_En50 is a 16-bit unsigned fixed-point data type with a SlopeAdjustmentFactor of 1.5 and a FixedExponent of -50

C,c,D, or d

Compressed encoding for Bias

Note

If you pass this character vector to the slDataTypeAndScale function, it returns a valid fixdt data type.

No example available. For backwards compatibility only.

To identify and replace calls to slDataTypeAndScale, use the Check for calls to slDataTypeAndScale Model Advisor check.

T or t

Compressed encoding for Slope

Note

If you pass this character vector to the slDataTypeAndScale, it returns a valid fixdt data type.

No example available. For backwards compatibility only.

To identify and replace calls to slDataTypeAndScale, use the Check for calls to slDataTypeAndScale Model Advisor check.

Fixed-Point Data in MATLAB

To assign a fixed-point data type to a number or variable in MATLAB, use the fi constructor. The resulting fixed-point value is called a fi object. For example, the following creates fi objects a and b with attributes shown in the display, all of which we can specify when the variables are constructed. Note that when the FractionLength property is not specified, it is set automatically to "best precision" for the given word length, keeping the most-significant bits of the value. When the WordLength property is not specified it defaults to 16 bits.

a = fi(pi)
a = 

              3.1416015625

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 13
b = fi(0.1)
b = 

        0.0999984741210938

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 18

Read Fixed-Point Data from the Workspace

Use the From Workspace block to read fixed-point data from the MATLAB workspace into a Simulink model. To do this, the data must be in structure format with a fi object in the values field. In array format, the From Workspace block only accepts real, double-precision data.

Write Fixed-Point Data to the Workspace

You can write fixed-point output from a model to the MATLAB workspace via the To Workspace block in either array or structure format. Fixed-point data written by a To Workspace block to the workspace in structure format can be read back into a Simulink model in structure format by a From Workspace block.

Scaled Doubles

Scaled doubles are a hybrid between floating-point and fixed-point numbers. Fixed-Point Designer™ stores them as doubles with the scaling, sign, and word length information retained. For example, the storage container for a fixed-point data type sfix16_En14 is int16. The storage container of the equivalent scaled doubles data type, flts16_En14 is floating-point double. Fixed-Point Designer applies the scaling information to the stored floating-point double to obtain the real-world value. Storing the value in a double almost always eliminates overflow and precision issues.

See Also

Functions