FixedPoint Data in MATLAB and Simulink
FixedPoint Data in Simulink
You can use the fixdt
function in Simulink^{®} to specify a fixedpoint data type. The fixdt
function creates a Simulink.NumericType
object.
FixedPoint 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 fixedpoint value.
Symbol  Description  Example 

Container Type  
 Unsigned fixedpoint data type 

 Signed fixedpoint data type 

 Scaled double override of an unsigned fixedpoint data
type ( 

 Scaled double override of a signed fixedpoint data type
( 

Number Encoding  
 10^ 

 Negative 

 Decimal point 

Scaling Encoding  
 Slope 

 Bias 

 Fixed exponent (2^) A negative fixed exponent describes the fraction length 

 Slope adjustment factor 

C,c,D, or d  Compressed encoding for Bias Note If you pass this character vector to the  No example available. For backwards compatibility only. To
identify and replace calls to 
T or t  Compressed encoding for Slope Note If you pass this character vector to the  No example available. For backwards compatibility only. To
identify and replace calls to 
FixedPoint Data in MATLAB
To assign a fixedpoint data type to a number or variable in MATLAB,
use the fi
(FixedPoint Designer) constructor.
The resulting fixedpoint 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 mostsignificant bits of the value.
When the WordLength
property is not specified it
defaults to 16 bits.
a = fi(pi)
a = 3.1416015625 DataTypeMode: Fixedpoint: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 13
b = fi(0.1)
b = 0.0999984741210938 DataTypeMode: Fixedpoint: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 18
Read FixedPoint Data from the Workspace
Use the From Workspace block
to read fixedpoint 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, doubleprecision data.
Write FixedPoint Data to the Workspace
You can write fixedpoint output from a model to the MATLAB workspace via the To Workspace block in either array or structure format. Fixedpoint 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 floatingpoint and fixedpoint
numbers. FixedPoint Designer™ stores them as doubles with the scaling,
sign, and word length information retained. For example, the storage
container for a fixedpoint data type sfix16_En14
is int16
.
The storage container of the equivalent scaled doubles data type, flts16_En14
is
floatingpoint double
. FixedPoint Designer applies
the scaling information to the stored floatingpoint double to obtain
the realworld value. Storing the value in a double almost always
eliminates overflow and precision issues.
See Also
Functions
fi
(FixedPoint Designer) fimath
(FixedPoint Designer) fixdt
Simulink.NumericType