fixpt_convert
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
res = fixpt_convert
converts the Simulink model or subsystem specified by bdroot
. res
is a structure that contains lists of blocks handled during conversion. The fields of this structure are given below.
Output Field | Description |
replaced | Blocks that are replaced with fixed-point equivalents or with other blocks from a user-specified replacement list. |
skipped | Blocks that are skipped because they are fixed-point compatible. Some of these blocks can cause errors if used in certain ways. For example, the Mux block can create lines that give different data types at down stream input ports. |
encapsulated | Structure containing lists of blocks grouped by type that are encapsulated between fixed-point gateway blocks. The encapsulated versions are not truly fixed point, but they will function within a fixed-point model. |
res = fixpt_convert('SystemName')
converts the Simulink model or subsystem specified by SystemName
.
res = fixpt_convert('SystemName','Display')
returns information associated with the conversion according to the method specified by Display
. The Display
methods are given below.
Display Method | Description |
on | Display detailed block information. |
outline | Display the conversion process outline. |
off | Do not display block information. |
filename | Write detailed block information to the specified file. |
on+filename | Display detailed block information, and write detailed block information to the specified file. |
outline+filename | Display the conversion process outline, and write detailed block information to the specified file. |
res = fixpt_convert('SystemName','Display','AutoSave')
determines the state of the converted model or subsystem. If 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 FixPt Gateway In or a FixPt 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 convert 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
BaseType = sfix(16)
LogicType = uint(8)
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 binary 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 Blockset Interface, fxptdlg
.
Example
This example uses fixpoint_convert
to convert a Simulink model of a direct form II realization to its fixed-point equivalent. This realization is discussed in Direct Form II. 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.
res = fixpt_convert('fxpdemo_preconvert','off','off')
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.
res.skipped
ans =
Mux: {'fxpdemo_preconvert_fixpt/Mux'}
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.
res.encapsulated
ans =
Scope: {[1x42 char]}
SignalGenerator: {'fxpdemo_preconvert_fixpt/Input'}
Note that the initial class of the base data type is double.
BaseType =
Class: 'DOUBLE'
You can now run the simulation for the converted model.
sim fxpdemo_preconvert_fixpt
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.
BaseType = sfix(16)
Follow the automatic scaling procedure described in the autofixexp reference pages with 20% safety margin, and then run the simulation.
sim fxpdemo_preconvert_fixpt
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 non-homogeneous 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 homogeneous using the FixPt 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.