7.3 Masking in SIMULINK

A mask is a way of customizing blocks in SIMULINK to look a certain way. The mask can provide graphical information, telling the user what a particular block does, or provide an interface to a single block or group of blocks. Here is a simple example.

Suppose we want to combine the Gain and Transfer Function blocks into a single block whose parameters are variables. We want to be able to pass in a value for K, the gain, and num and den, the numerator and denominator of the transfer function.

First, we assemble the blocks, placing variable names in the dialog boxes of the blocks we wish to control:

Next, we group the two blocks we wish to mask by selecting the blocks and choosing Group from the Options menu:

Now we are ready to set up the mask. For this case, we will be passing in K, num, and den. Select the blocks with the mouse and choose Mask from the Options menu. This will open a dialog box which contains a series of editable text boxes. This is where we define the way the mask looks.

The first editable text box is named "New Block Type," and is used to define the type of block being created. This is arbitrary, and has no effect on how the block performs. For this block, we might choose something like "Variable Gain Filter."

The second editable text box is named "Dialog strings separated by |" This field is used to define the inputs that are needed by the masked block. These are user-defined editable text boxes which are specific to each block being masked. For this example, we'll choose the following strings:

test block | gain | numerator | denominator
This will set up three editable text boxes with the contents specified by each string. The vertical bars are necessary to create each field. The first string, "test block", is the title of the masked block. Each vertical bar creates a new editable text field, with the string following it as the label for the field.

The next box, named "Initialization commands," defines how the block is initialized. Since we are using variables in the underlying blocks, we need to associate these variables with a text field entry.

The order in which these parameters are passed is important. For our example, we need to pass in K, num, and den. To assign the contents of the editable text fields to underlying variables, we use the @ sign as follows:

K = @1; num = @2; den = @3;
This assigns the value of the first editable text block to K; the second to num; and the third to den.

The initialization commands can consist of any MATLAB command, but it is necessary to assign values to any variables before a simulation can be run. Good examples of how to initialize these blocks can be found in the Extras library, as most all of these blocks are masked blocks. To see how they are masked, select a block, then choose the Mask option from the Options menu.

The fourth editable text box, named "Drawing commands," is for making the block look a certain way. This can be text, a plot command such as an impulse response, or an icon which has been created with the iconedit program included with SIMULINK.

Finally, the last editable text box, "Help string," is used to create a help entry for the masked block. This information is displayed when the user selects the Help button. This is optional.

Once the above steps are complete, the block is ready for use. Clicking on the masked block will bring up a dialog box with three fields labeled "gain", "numerator", and "denominator". The initialization commands above will assign the contents of these boxes to the variable names used in the original blocks. Since K is used for gain in the underlying Gain block, the value placed in the first dialog is assigned to K, the filter gain.

The Windows version of SIMULINK has a limit of six editable text fields per masked block. This restriction requires that more than six parameters be vectorized. The syntax for initializing is similar to standard MATLAB syntax:

K  =  @1(2);
would allow the gain K to be initialized to the second element of the vector placed in the first field.

It is possible to create complex, multilevel masks in SIMULINK. Variables may be passed through many layers simply by keeping the names of the variables constant. For example, we can take the above block, connect another block, such as a discrete integrator on the input, and pass in values of initial condition and sample time. It is important however, to use the same variable names in the underlying block as the variable names in the higher level mask. This means the Variable Gain Filter block would have a mask which looks like this when double clicked on:

Since we would like to pass parameters to the Unit Delay block also, the editable text for this block must also contain variable names:

We would group the above blocks as we did with the previous example, using variables such as Ic and Ts for the Unit Delay values.

These values would then be added to the new mask which we would create after grouping the above blocks. The new mask would then be passed Ic, Ts, K, num, and den. This process can continue to virtually any level of complexity. The final compound mask should look like the following figure. (The format may be different for your computer)

(c) Copyright 1994 by The MathWorks, Inc.