Model Discretizer selectively replaces continuous Simulink^{®} blocks with discrete equivalents. Discretization is a critical step in digital controller design and for hardware in-the-loop simulations.
You can use the Model Discretizer to:
Identify a model's continuous blocks
Change a block's parameters from continuous to discrete
Apply discretization settings to all continuous blocks in the model or selected blocks
Create configurable subsystems that contain multiple discretization candidates along with the original continuous block(s)
Switch among the different discretization candidates and evaluate the resulting model simulations
To use Model Discretizer
You must have a Control System Toolbox™ license, Version 5.2 or later.
Make sure your model does not contain any obsolete blocks and is upgraded to the current Simulink version. For more information, see Model Upgrades
Make sure your model does not contain any masked subsystems. For more information, see Masking.
To discretize a model:
Start the Model Discretizer
Specify the Transform Method
Specify the Sample Time
Specify the Discretization Method
Discretize the Blocks
The f14
model shows the
steps in discretizing a model.
To open the tool, in the Simulink Editor, select Analysis > Control Design > Model Discretizer.
The Simulink Model Discretizer opens.
Alternatively, you can open Model Discretizer from the MATLAB^{®} Command
Window using the slmdldiscui
function.
The following command opens the Simulink
Model Discretizer window with the f14
model:
slmdldiscui('f14')
To open a new model or library from Model Discretizer, select File > Load model.
The transform method specifies the type of algorithms used in the discretization. For more information on the different transform methods, see the Control System Toolbox documentation.
The Transform method
drop-down list
contains the following options:
zero-order hold
Zero-order hold on the inputs.
first-order hold
Linear interpolation of inputs.
tustin
Bilinear (Tustin) approximation.
tustin with prewarping
Tustin approximation with frequency prewarping.
matched pole-zero
Matched pole-zero method (for SISO systems only).
Enter the sample time in the Sample time field.
You can specify an offset time by entering a two-element vector for discrete blocks or configurable subsystems. The first element is the sample time and the second element is the offset time. For example, an entry of [1.0 0.1] would specify a 1.0 second sample time with a 0.1 second offset. If no offset is specified, the default is zero.
You can enter workspace variables when discretizing blocks in the s-domain. See Discrete blocks (Enter parameters in s-domain).
Specify the discretization method in the Replace current selection with field. The options are
Discrete blocks (Enter parameters in s-domain)
Creates a discrete block whose parameters are retained from the corresponding continuous block.
Discrete blocks (Enter parameters in z-domain)
Creates a discrete block whose parameters are "hard-coded" values placed directly into the block's dialog.
Configurable subsystem (Enter parameters in s-domain)
Create multiple discretization candidates using s-domain values for the current selection. A configurable subsystem can consist of one or more blocks.
Configurable subsystem (Enter parameters in z-domain)
Create multiple discretization candidates in z-domain for the current selection. A configurable subsystem can consist of one or more blocks.
Discrete blocks (Enter parameters in s-domain). Creates a discrete block whose parameters are retained from the corresponding continuous block. The sample time and the discretization parameters are also on the block's parameter dialog box.
The block is implemented as a masked discrete block that uses c2d
to transform the continuous parameters
to discrete parameters in the mask initialization code.
These blocks have the unique capability of reverting to continuous
behavior if the sample time is changed to zero. Entering the sample
time as a workspace variable ('Ts'
, for example)
allows for easy changeover from continuous to discrete and back again.
See Specify the Sample Time.
Note Parameters are not tunable when Inline parameters is selected in the model's Configuration Parameters dialog box. |
The following figure shows a continuous Transfer Function block next to a Transfer Function block that has been discretized in the s-domain. The Block Parameters dialog box for each block appears below the block.
Discrete blocks (Enter parameters in z-domain). Creates a discrete block whose parameters are "hard-coded"
values placed directly into the block's dialog box. Model Discretizer
uses the c2d
function to obtain
the discretized parameters, if needed.
For more help on the c2d
function,
type the following in the Command Window:
help c2d
The following figure shows a continuous Transfer Function block next to a Transfer Function block that has been discretized in the z-domain. The Block Parameters dialog box for each block appears below the block.
Note If you want to recover exactly the original continuous parameter values after the Model Discretization session, you should enter parameters in the s-domain. |
Configurable subsystem (Enter parameters in s-domain). Create multiple discretization candidates using s-domain values for the current selection. A configurable subsystem can consist of one or more blocks.
The Location for block in configurable subsystem field becomes active when this option is selected. This option allows you to either create a new configurable subsystem or overwrite an existing one.
Note The current folder must be writable in order to save the library or libraries for the configurable subsystem option. |
Configurable subsystem (Enter parameters in z-domain). Create multiple discretization candidates in z-domain for the current selection. A configurable subsystem can consist of one or more blocks.
The Location for block in configurable subsystem field becomes active when this option is selected. This option allows you to either create a new configurable subsystem or overwrite an existing one.
Note The current folder must be writable in order to save the library or libraries for the configurable subsystem option. |
Configurable subsystems are stored in a library containing the
discretization candidates and the original continuous block. The library
will be named <model name>_disc_lib
and it
will be stored in the current . For example a library containing a
configurable subsystem created from the f14
model
will be named f14_disc_lib
.
If multiple libraries are created from the same model, then
the filenames will increment accordingly. For example, the second
configurable subsystem library created from the f14
model
will be named f14_disc_lib2
.
You can open a configurable subsystem library by right-clicking on the subsystem in the model and selecting Library Link > Go to library block from the pop-up menu.
To discretize blocks that are linked to a library, you must either discretize the blocks in the library itself or disable the library links in the model window.
You can open the library from Model Discretizer by selecting Load model from the File menu.
You can disable the library links by right-clicking on the block and selecting Library Link > Disable Link from the pop-up menu.
There are two methods for discretizing blocks.
Select Blocks and Discretize.
Select a block or blocks in the Model Discretizer tree view pane.
To choose multiple blocks, press and hold the Ctrl button on the keyboard while selecting the blocks.
Note You must select blocks from the Model Discretizer tree view. Clicking blocks in the editor does not select them for discretization. |
Select Discretize current block from the Discretize menu if a single block is selected or select Discretize selected blocks from the Discretize menu if multiple blocks are selected.
You can also discretize the current block by clicking the Discretize button, shown below.
Store the Discretization Settings and Apply Them to Selected Blocks in the Model.
Enter the discretization settings for the current block.
Click Store Settings.
This adds the current block with its discretization settings to the group of preset blocks.
Repeat steps 1 and 2, as necessary.
Select Discretize preset blocks from the Discretize menu.
You can delete a discretization candidate from a configurable subsystem by selecting it in the Location for block in configurable subsystem field and clicking the Delete button, shown below.
To undo a discretization, click the Undo discretization button, shown below.
Alternatively, you can select Undo discretization from the Discretize menu.
This operation undoes discretizations in the current selection and its children. For example, performing the undo operation on a subsystem will remove discretization from all blocks in all levels of the subsystem's hierarchy.
Model Discretizer displays the model in a hierarchical tree view.
The block's icon in the tree view becomes highlighted with a "z" when the block has been discretized.
The following figure shows that the Aircraft Dynamics Model subsystem has been discretized into a configurable subsystem with three discretization candidates.
The other blocks in this f14
model have
not been discretized.
The following figure
shows the Aircraft Dynamics Model subsystem of the f14
example
model after discretization into a configurable subsystem containing
the original continuous model and three discretization candidates.
The following figure shows the library containing the Aircraft Dynamics Model configurable subsystem with the original continuous model and three discretization candidates.
To refresh Model Discretizer's tree view of the model when the model has been changed, click the Refresh button, shown below.
Alternatively, you can select Refresh from the View menu.
You can replace continuous blocks in a Simulink software model with the equivalent blocks discretized in the s-domain using the Discretizing library.
The procedure below shows how to replace a continuous Transfer
Fcn block in the Aircraft Dynamics Model subsystem of the f14
model
with a discretized Transfer Fcn block from the Discretizing Library.
The block is discretized in the s-domain with a zero-order hold transform
method and a two second sample time.
Open the f14
model.
Open the Aircraft Dynamics Model subsystem
in the f14
model.
Open the Discretizing library window.
Enter discretizing
at the MATLAB command
prompt.
The Library: discretizing window opens.
This library contains s-domain discretized blocks.
Add the Discretized Transfer Fcn (with initial states) block to the f14/Aircraft Dynamics Model window.
Click the Discretized Transfer Fcn block in the Library: discretizing window.
Drag it into the f14/Aircraft Dynamics Model window.
Open the parameter dialog box for the Transfer Fcn.1 block.
Double-click the Transfer Fcn.1 block in the f14/Aircraft Dynamics Model window.
The Block Parameters: Transfer Fcn.1 dialog box opens.
Open the parameter dialog box for the Discretized Transfer Fcn block.
Double-click the Discretized Transfer Fcn block in the f14/Aircraft Dynamics Model window.
The Block Parameters: Discretized Transfer Fcn dialog box opens.
Copy the parameter information from the Transfer Fcn.1 block's dialog box to the Discretized Transfer Fcn block's dialog box.
Enter 2
in the Sample time field.
Select zoh
from
the Method drop-down list.
The parameter dialog box for the Discretized Transfer Fcn now looks like this.
Click OK.
The f14/Aircraft Dynamics Model window now looks like this.
Delete the original Transfer Fcn.1 block.
Click the Transfer Fcn.1 block.
Press the Delete key.
The f14/Aircraft Dynamics Model window now looks like this.
Add the Discretized Transfer Fcn block to the model.
Click the Discretized Transfer Fcn block.
Drag the Discretized Transfer Fcn block into position to complete the model.
The f14/Aircraft Dynamics Model window now looks like this.
Use the sldiscmdl
function
to discretize Simulink software models from the MATLAB Command
Window. You can specify the transform method, the sample time, and
the discretization method with the sldiscmdl
function.
For example, the following command discretizes the f14
model
in the s-domain with a 1-second sample time using a zero-order hold
transform method:
sldiscmdl('f14',1.0,'zoh')