Documentation

Model Discretizer

What Is the Model Discretizer?

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

  • 离散化的设置应用于所有连续的提单ocks 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

Requirements

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, seeModel Upgrades

Discretize a Model with the Model Discretizer

To discretize a model:

  • Start the Model Discretizer

  • Specify the Transform Method

  • Specify the Sample Time

  • Specify the Discretization Method

  • Discretize the Blocks

Thef14model shows the steps in discretizing a model.

Start Model Discretizer

To open the tool, in the Simulink Editor, on theAppstab, underApps, underControl Systems, clickModel Discretizer.

TheSimulink Model Discretizeropens.

Alternatively, you can open Model Discretizer from the MATLAB®Command Window using theslmdldiscuifunction.

The following command opens theSimulink Model Discretizerwindow with thef14model:

slmdldiscui('f14')

To open a new model or library from Model Discretizer, selectFile>Load model.

Specify the Transform Method

The transform method specifies the type of algorithms used in the discretization. For more information on the different transform methods, seethe Control System Toolbox.

TheTransform methodlist 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).

Specify the Sample Time

Enter the sample time in theSample timefield. For the Model Discretizer, this value must be numeric.

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. SeeDiscrete blocks (Enter parameters in s-domain).

Specify the Discretization Method

Specify the discretization method in theReplace current selection withfield. The options are

Discrete blocks (Enter parameters in s-domain).创建一个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 usesc2dto 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. SeeSpecify the Sample Time.

Note

If you generated code from a model, parameters are not tunable whenDefault parameter behavioris set toInlinedin 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).创建一个discrete block whose parameters are “hard-coded” values placed directly into the block's dialog box. Model Discretizer uses thec2dfunction to obtain the discretized parameters, if needed.

For more help on thec2dfunction, 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.

TheLocation for block in configurable subsystemfield 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.

TheLocation for block in configurable subsystemfield 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_disc_liband it will be stored in the current. For example a library containing a configurable subsystem created from thef14model will be namedf14_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 thef14model will be namedf14_disc_lib2.

You can open a configurable subsystem library by right-clicking on the subsystem in the model and selectingLibrary Link>Go to library blockfrom the context menu.

Discretize the Blocks

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 selectingLoad modelfrom theFilemenu.

You can disable the library links by right-clicking on the block and selectingLibrary Link>Disable Linkfrom the context menu.

There are two methods for discretizing blocks.

Select Blocks and Discretize

  1. Select a block or blocks in the Model Discretizer tree view pane.

    To choose multiple blocks, press and hold theCtrlbutton 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.

  2. SelectDiscretize current blockfrom theDiscretizemenu if a single block is selected or select离散化选择的块from theDiscretizemenu if multiple blocks are selected.

    You can also discretize the current block by clicking theDiscretizebutton, shown below.

Store the Discretization Settings and Apply Them to Selected Blocks in the Model

  1. Enter the discretization settings for the current block.

  2. ClickStore Settings.

    This adds the current block with its discretization settings to the group of preset blocks.

  3. Repeat steps 1 and 2, as necessary.

  4. SelectDiscretize preset blocksfrom theDiscretizemenu.

Deleting a Discretization Candidate from a Configurable Subsystem

You can delete a discretization candidate from a configurable subsystem by selecting it in theLocation for block in configurable subsystemfield and clicking the删除button.

Undoing a Discretization

To undo a discretization, click theUndo discretizationbutton.

Alternatively, you can selectUndo discretizationfrom theDiscretizemenu.

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.

View the Discretized Model

Model Discretizer displays the model in a hierarchical tree view.

Viewing Discretized Blocks

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 thisf14model have not been discretized.

The following figure shows the Aircraft Dynamics Model subsystem of thef14example 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.

Refreshing Model Discretizer View of the Model

To refresh the Model Discretizer tree view of the model when the model has been changed, click theRefreshbutton.

Alternatively, you can selectView>Refresh.

Discretize Blocks from the金宝appModel

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 continuousTransfer Fcnblock in the Aircraft Dynamics Model subsystem of thef14model with a discretizedTransfer Fcnblock 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.

  1. Open thef14model.

  2. Open the Aircraft Dynamics Model subsystem in thef14model.

  3. Open the Discretizing library window.

    Enterdiscretizingat the MATLAB command prompt.

    TheLibrary: discretizingwindow opens.

    This library contains s-domain discretized blocks.

  4. Add theDiscretized Transfer Fcn(with initial states) block to thef14/Aircraft Dynamics Modelwindow.

    1. Click theDiscretized Transfer Fcnblock in theLibrary: discretizingwindow.

    2. Drag it into thef14/Aircraft Dynamics Modelwindow.

  5. Open the parameter dialog box for the Transfer Fcn.1 block.

    双击Fcn.1块的转移f14/Aircraft Dynamics Modelwindow.

    The Block Parameters: Transfer Fcn.1 dialog box opens.

  6. Open the parameter dialog box for theDiscretized Transfer Fcnblock.

    Double-click theDiscretized Transfer Fcnblock in thef14/Aircraft Dynamics Modelwindow.

    The Block Parameters: Discretized Transfer Fcn dialog box opens.

    Copy the parameter information from theTransfer Fcn.1block dialog box to theDiscretized Transfer Fcnblock's dialog box.

  7. Enter2in theSample timefield.

  8. Selectzohfrom theMethoddropdown list.

    The parameter dialog box for theDiscretized Transfer Fcnnow looks like this.

  9. ClickOK.

    Thef14/Aircraft Dynamics Modelwindow now looks like this.

  10. 删除the original Transfer Fcn.1 block.

    1. Click the Transfer Fcn.1 block.

    2. Press the删除key.

      Thef14/Aircraft Dynamics Modelwindow now looks like this.

  11. Add theDiscretized Transfer Fcnblock to the model.

    1. Click theDiscretized Transfer Fcnblock.

    2. Drag theDiscretized Transfer Fcnblock into position to complete the model.

      Thef14/Aircraft Dynamics Modelwindow now looks like this.

Discretize a Model with the sldiscmdl Function

Use thesldiscmdlfunction to discretize Simulink software models from the MATLAB Command Window. You can specify the transform method, the sample time, and the discretization method with thesldiscmdlfunction.

For example, the following command discretizes thef14model in the s-domain with a 1-second sample time using a zero-order hold transform method:

sldiscmdl('f14',1.0,'zoh')

See Also

Related Topics