Fixed-Point Blockset | ![]() ![]() |
Convert Simulink models and subsystems to fixed-point equivalents
Syntax
res = fixpt_convert res = fixpt_convert('SystemName') res = fixpt_convert('SystemName','Display
') res = fixpt_convert('SystemName','Display
','AutoSave
')
Description
converts the Simulink model or subsystem specified by res
is a structure that contains lists of blocks handled during conversion. res
= fixpt_convert
bdroot
. The fields of this structure are given below.
res = fixpt_convert('SystemName')
converts the Simulink model or subsystem specified by SystemName
.
res = fixpt_convert('SystemName','
returns information associated with the conversion according to the method specified by Display
')
Display
. The Display
methods are given below.
res = fixpt_convert('SystemName','
determines the state of the converted model or subsystem. If Display
','AutoSave
')
AutoSave
is on
, then the converted model or subsystem is saved and closed. If AutoSave
is off
, then the converted model or subsystem is unsaved and left open.
Remarks
If your Simulink model references blocks from a custom Simulink library, then these blocks are encapsulated upon conversion. A block is encapsulated when it cannot be converted to an equivalent fixed-point block. Encapsulation involves associating a Gateway In or a Gateway Out block with the Simulink block. To reduce the number of blocks that are encapsulated, you should convert the entire library by passing the library name to fixpt_convert
, and then converting the model.
To create a custom list of blocks to convert, you should use the fixpt_convert_userpairs
script. To learn how to use this script, read the comments included in the M-file.
The data types for fixed-point outputs taking Boolean values are specified by the variable LogicType
. The data types of all other fixed-point outputs and parameters are specified by the variable BaseType
. You can change these variables to any data type. For example, in the MATLAB workspace you can type
The converted model will not work if these variables are not defined.
Best precision mode is used when available. Otherwise, the precision is set to 20, which means that the radix point is to the right of all bits. To automatically set the scaling, run a simulation with doubles override on and then invoke the automatic scaling script, autofixexp
. You can run autofixexp
directly, or in conjunction with the Fixed-Point Settings interface, fxptdlg
.
Example
This example uses fixpoint_convert
to convert a Simulink model of a direct form II realization to its fixed-point equivalent. Direct Form II discusses this realization. The Simulink model shown below, fxpdemo_preconvet
, is included as a demo with the blockset.
The following command converts this model to its fixed-point equivalent, suppresses the display of detailed block information, and does not save the model after conversion:
The built-in blocks that are replaced by fixed-point equivalent blocks are given by the replaced
field:
res.replaced ans = UnitDelay: {3x1 cell} ZeroOrderHold: {[1x40 char]} Gain: {6x1 cell} Sum: {2x1 cell}
The built-in blocks that are skipped since they are compatible with the Fixed-Point Blockset are given by the skipped
field:
The built-in blocks that are encapsulated by fixed-point gateway blocks so that they are made compatible with the Fixed-Point Blockset are given by the encapsulated
field:
Note that the initial class of the base data type is double
:
You can now run the simulation for the converted model:
The output from the simulation is shown below. You should compare this output to the output produced by the fixed-point direct from II model, fxpdemo_direct_form2
.
Next, define a fixed-point base data type:
Follow the automatic scaling procedure described in the autofixexp
reference pages with 20% safety margin, and then run the simulation:
The simulation now produces an error. This is because the vector signal leading into the scope is not homogeneous with regard to data type and scaling.
In general, solving the problem of nonhomogeneous signals requires that you analyze how the signal is being used. If the distinct scaling and data type properties are important, then you must fully or partially unvectorize the relevant part of the model. Alternatively, you can force the signals to be homogenous using the Gateway Out block. Since this example plots real-world values in the Scope, inserting gateway blocks on the signals leading into the Scope is an adequate solution.
See Also
autofixexp
, fixpt_convert_prep
, fxptdlg
![]() | fixptbestprec | fixpt_convert_prep | ![]() |