Fixed-Point Blockset    
fixpt_convert

Convert Simulink models and subsystems to fixed-point equivalents

Syntax

Description

res is a structure that contains lists of blocks handled during conversion. res = fixpt_convert converts the Simulink model or subsystem specified by bdroot. The fields of this structure are given below.

Output Field
Description
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.
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 downstream input ports.

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
filename
Write detailed block information to the specified file.
off
Do not display block information.
on
Display detailed block information.
on+filename
Display detailed block information, and write detailed block information to the specified file.
outline
Display the conversion process outline.
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 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:

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