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 | ||
| Unsigned fixed-point data type |
|
| Signed fixed-point data type |
|
| Scaled double override of an unsigned fixed-point data
type ( |
|
| Scaled double override of a signed fixed-point 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 backward compatibility only. |
T or t | Compressed encoding for Slope Note If you pass this character vector to the | No example available. For backward compatibility only. |
Fixed-Point Data in MATLAB
To assign a fixed-point data type to a number or variable in MATLAB,
use the fi (Fixed-Point Designer) 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: 13b = fi(0.1)
b =
0.0999984741210938
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 18Read 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
fi(Fixed-Point Designer) |fimath(Fixed-Point Designer) |fixdt|Simulink.NumericType