You are on page 1of 25

AIN SHAMS UNIVERSITY

FACULTY OF ENGINEERING
MECHATRONICS ENGINEERING DEPARTMENT
Credit Hours Programs
Spring Semester, 2018

MCT 456: Dynamic Modeling and Simulation


Lab. 3: Modeling with SIMULINK Part 01

Contents
1- Introduction and Background.
2- Open Simulink and Identify its Environment, libraries and Simulink toolboxes.
3- Creating a Simulink model.
4- Simulink Simulation Settings and solvers.
Background:
Simulink is a block diagram environment for multi-domain simulation and Model-Based Design. It
supports system-level design, simulation, automatic code generation, and continuous test and verification
of embedded systems. Simulink provides a graphical editor, customizable block libraries, and solvers for
modeling and simulating dynamic systems. It is integrated with MATLAB, enabling you to incorporate
MATLAB algorithms into models and export simulation results to MATLAB for further analysis.

1. Exercise 1: Open Simulink and Identify its Environment, libraries and Simulink toolboxes.

 Steps:
To start SIMULINK on a Microsoft Windows System, use one of these approaches:

1. Click on the ‘New’ tab on the MATLAB toolbar, and then click on the ‘SIMULINK Model’
tab.

2. Entering the ‘SIMULINK’ command in the command window or click the SIMULINK (
) button on the MATLAB Home Tab.

3. You will see the SIMULINK library as shown in Figure 1.1. Then, click on ( ) button.

 After doing any of the previous approaches, you will then see the default appearance of SIMULINK
as shown in Figure 1.2.
 The Simulink library consists of blocks that are available for putting into SIMULINK block diagram.
The blocks are divided into 15 sections: Commonly used block, Continuous, Discontinuities, Discrete,
Logic and Bit operations, Lookup Tables, Math Operations, Model Verification, Model-Wide Utilities,
Ports & Subsystems, Signal Attributes, Signal Routing, Sinks, Sources and User-Defined Functions.
 Use the libraries pane shown in Figure 1.3 allows you to locate blocks by navigating block libraries.
The pane displays a tree view of the libraries installed on your system. You can navigate the tree with
your mouse or keyboard. When you select a library from this structure, the contents of that library
appear in the blocks pane.

Page 1 of 25
Figure 1.1 The default view of the SIMULINK library.

Figure 1.2 The default appearance of SIMULINK Desktop.

Figure 1.3 The SIMULINK library sections.

Page 2 of 25
 Explore the Commonly Used Blocks section in Figure 1.1.

………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
……………………………………………………………………………………………………………..
 Explore the New Model button arrow (the red box in Figure 1.1) and select From Template.
Comment

………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
…………………………………………………………………………………………………………….
 Explore the Normal button arrow (blue box in Figure 1.2) and Comment.

………………………………………………………………………………………………………………
…………………………………………………………………………………………………………….

Create Simple Model

 Model Overview for This Tutorial


You can use Simulink® to model a system and then simulate the dynamic behavior of that system. The basic
techniques you use to create the simple model in this tutorial are the same techniques that you use for more
complex models.
To create this simple model, you need four Simulink blocks. Blocks are the model elements that define the
mathematics of a system and provide input signals:
 Sine Wave — Generate an input signal for the model.
 Integrator — Process the input signal.
 Bus Creator — Combine multiple signals into one signal.
 Scope — Visualize and compare the input signal with the output signal.

Simulating this model integrates a sine wave signal to a cosine signal and then displays the result, along with
the original signal, in a Scope window.
 Open New Model in Simulink Editor
Use the Simulink Editor to build your models.

1. Start MATLAB®. From the MATLAB Toolstrip, click the Simulink button .
A short delay occurs the first time you open Simulink.

Page 3 of 25
2. Click the Blank Model template.
The Simulink Editor opens with a new block diagram.

3. From the File menu, select Save as. In the File name text box, enter a name for your model, For
example, simple_model. Click Save. The model is saved with the file extension.slx.
 Open Simulink Library Browser
From the Simulink Library Browser you can search for blocks to use in your model. Also, you can create a
new Simulink model, project.

1. From the Simulink Editor toolbar, click the Library Browser button .

Page 4 of 25
2. Set the Library Browser to stay on top of the other desktop windows. On the Library Browser toolbar,
select the Stay on top button .
 Browse or Search for Specific Blocks
To browse through the block libraries, select a MathWorks® product and then a functional area in the left
pane. To search all of the available block libraries, enter a search term.
1. Search for a Sine Wave block. In the search box on the browser toolbar, enter sine, and then press the
Enter key. Simulink searches the libraries for blocks with sine in their name or description, and then
displays the blocks.

2. Get detailed information about a block. Right-click a block, and then select Help for the <block name>.
The Help browser opens with the reference page for the block.
3. View block parameters. Right-click a block, and then select Block Parameters. The block parameters
dialog box opens.
 Add Blocks to Model
You build models by dragging blocks from the Simulink Library Browser window to the Simulink Editor or
single-clicking your model and entering a search term.

Page 5 of 25
To build the simple model, begin by copying blocks from the Simulink Library Browser to the Simulink
Editor.
1. In the left pane of Simulink Library Browser, select the Sources library.
2. From the right pane, select the Sine Wave block.

3. Drag the Sine Wave block to the Simulink Editor. A copy of the Sine Wave block appears in your model
with a text box for entering the value of the Amplitude parameter. In the text box enter 2.

4. Add a Scope block using this alternative procedure:


a. Double-click within the block diagram.
b. After the search icon appears, type scope, and then from the list, select Scope from
the Simulink/Sinks library.

5. Add the following blocks to your model using one of the approaches you used to add the Sine
Wave and Scope blocks.
Library Block
Simulink/Continuous Integrator
Simulink/Signal Routing Bus Creator
6. Your model should now have the blocks you need for the simple model.
Page 6 of 25
 Move and Resize Blocks
Before you connect the blocks in your model, arrange the block inputs and outputs to make signal
connections as straightforward as possible.
1. Move the Scope block after the Bus Creator block output. You can either:
o Click and drag the block.
o Select the block, and then press the arrow keys on your keyboard.
2. Move the blocks until your model looks similar to the following figure.

 Block Connections
Most blocks have angle brackets on one or both sides. These angle brackets represent input and output ports:
 The > symbol pointing into a block is an input port.
 The > symbol pointing out of a block is an output port.

You connect block output ports to input ports with lines. The lines represent signals with time-varying
values.
 Draw Signal Lines Between Blocks
Connect the blocks by drawing lines between output ports and input ports.
1. Position the cursor over the output port on the right side of the Sine Wave block.
The pointer changes to a cross hair (+).
2. Click, and then drag a line from the output port to the top input port of the Bus Creator block.
While holding down the mouse button, the connecting line appears as a red dotted arrow.

Page 7 of 25
3. Release the mouse button when the pointer is over the output port.
Simulink connects the blocks with a line and an arrow indicating the direction of signal flow.

4. Connect the output port of the Integrator block to the bottom input port on the Bus Creator block using
a Ctrl key shortcut:
a. Select the Integrator block.
b. Press and hold the Ctrl key.
c. Click the Bus Creator block.
The Integrator block connects to the Bus Creator block with a signal line.
5. Click and drag the output port from the Bus Creator block to the Scope block.

 Draw Branched Signal Lines


Your simple model is almost complete. To finish the model, connect the Sine Wave block to
the Integrator block. This connection is different from the other connections, which all connect output ports
to input ports.
1. Position the cursor where you want to start a branch line. In this example, position the cursor over the
signal line between the Sine Wave and Bus Creator blocks.
2. Right-click and drag the cursor away from the line to form a dotted line segment.

Page 8 of 25
3. Continue to drag the cursor to the Integrator input port, and then release the mouse button.
The new line, called a branch line, carries the same signal that passes from the Sine Wave block to
the Bus Creator block.
4. Drag line segments to straighten and align with blocks. Your model is now complete.

 Define Configuration Parameters


Before you simulate the behavior of your model, you can modify the default values for the configuration
parameters. The configuration parameters include the type of numerical solver, start time, stop time, and
maximum step size.
1. From the Simulink Editor menu, select Simulation > Model Configuration Parameters. The
Configuration Parameters dialog box opens to the Solver pane.
Tip

Alternatively, you can open the Model Configuration Parameters dialog box by clicking the parameters

button on the Simulink Editor toolbar.


2. In the Stop time field, enter 20. With the Solver parameter set to auto, Simulink determines the best
numerical solver for simulating your model.
3. Select Additional parameters. In the Max step size field, enter 0.2.

Page 9 of 25
4. Click Apply or OK.
 Run Simulation
After you define the configuration parameters, you are ready to simulate your model.
1. From the Simulink Editor menu bar, select Simulation > Run.
The simulation runs, and then stops when it reaches the stop time specified in the Model Configuration
Parameters dialog box.
Tip

Alternatively, you can control a simulation by clicking the Run simulation

button and Pause simulation button on the Simulink Editor toolbar or Scope window
toolbar.
Observe Simulation Results
After simulating a model, you can view the simulation results in a Scope window.
1. Double-click the Scope block.
The Scope window opens and displays the simulation results. The plot shows a sine wave signal with the
resulting cosine wave signal.

2. On the Scope window toolbar, click the Style button.

Page 10 of 25
A Style dialog box opens with display options.

3. Change the appearance of the display. For example, select white for the Figure color and Axes
color background (icons with a pitcher).
4. Select black for the Axes color ticks, labels, and grid colors (icon with a paintbrush).
5. Change signal line colors for the Sine Wave to blue and the Integrator to red. To see your changes,
click OK or Apply.

2. Exercise 2: Creating another Simulink model

To create a new model, you should choose the blocks needed from the library and drag them into
SIMULINK block diagram. The drag of the block can be done either by right click on the desired block
and click on (Add block to model) or left click on the block and drag the mouse while clicking to the block
diagram.
Any model can be classified into three major parts: Input (Source), Output (results or sinks) and Transfer
function (or mathematical operations).

Page 11 of 25
a. Sources shown in Figure 2.1 are used to produce different types of signal such as: step, ramp, sin,
custom (signal builder), etc…

Figure 2.1 The source icon at the library browser.


b. The sinks are used to terminate signals or view the results.

c. Connecting blocks are done either by drag a signal line from the output port of a block to the input of
another block or Ctrl-Click will automatically connect.

d. You can also create a branch point in a signal line by holding down the CTRL key, and clicking on the
line.
e. Block properties is modified by double click on the block to bring up a properties box (example shown
in Figure 2.2).

f. You can search about any block by typing its name inside the search box of the library browser.

Figure 2.2 An example for the properties box of ramp block.

Example: if x = 0 and increases to 5 in 10 seconds, determine y if y = 5 x+3


You can create this equation using several methods; such as ramp block, signal builder block, blocks
from Math Operations, or mix from all previous

Page 12 of 25
Open the Simulink library > sources, search for signal builder block and drag it to SIMULINK
desktop.
Double click on the signal builder block; you will see the following window.

Click on the pulse signal and then click on Signal in the toolbar >Replace with > custom, a window
will be displayed where you can enter the desired signal

Time values will be changed to 0 to 10 and the x values will be changed to 0 to 10 and press OK.
The desired signal will be then displayed that the value of the variable ‘x’.

Page 13 of 25
Return to Simulink library; click on Math operations, choose Product and add blocks and drag them
to SIMULINK. Then, click on sources > Constant and drag it to SIMULINK desktop.

Double click on the Constant block and change its value to from 1 to 10. Then, right click and drag
the Constant block to copy another one and change its value to 3.
You can view the results by using Scope block from Sinks in the library. Then you need to start
simulation by click on run button

Double click on Scope block and review the results

Page 14 of 25
 Note: This is just an example to create models on Simulink and it is not the best or efficient way to
simulate y = 5 x+3.

Reproduce the previous equation (y = 5 x+3 ) using only Signal Builder or Ramp block
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………

Try to model this equation and view the results: 𝑦 = 5 sin(3𝑡 + 5) − cos t (using Sine Wave Function and
Math operations blocks)
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………

Try to model the above equation WITHOUT using Sine block from sources using either Signal Builder or
Signal Generators blocks
…………………………………………………………………………………………………………………
……………………...............................................................................................................................................
................................................................................................................................................................

 If you want to send multiple signals and connect with only one block (e.g.: to the same scope), the MUX
block (signal routing section) can be used. (DEMUX block reverse the MUX block.

Explore the other blocks in Signal Routing section


…………………………………………………………………………………………………………………
………………………………………………………………………………………………………………..

3. Exercise 3: Simulink Simulation Settings and solvers.


To change simulation settings, single click on the setting button ( ) or press CTRL-E.
The screen shown in Figure 3.1 will appear.

Explore all simulation options in Configuration Simulation Parameters window


…………………………………………………………………………………………………………………
………………………………………………………………………………………………………………..

Page 15 of 25
Figure 3.1 Simulation setting and solvers screen.
 You can change simulation start time and stop time from places marked with rectangle box.
 There are two type of solvers: variable step and fixed step;

 Fixed-step solvers solve the model at step sizes from the beginning to the end of the simulation. You
can specify the step size or let the solver choose the step size. Generally, decreasing the step size
increases the accuracy of the results and increases the time required to simulate the system.
 Variable-step solvers vary the step size during the simulation. They reduce the step size to increase
accuracy when the states of a model change rapidly and during zero-crossing events. They increase
the step size to avoid taking unnecessary steps when the states of a model change slowly. Computing
the step size adds to the computational overhead at each step. However, it can reduce the total number
of steps, and hence the simulation time required to maintain a specified level of accuracy for models
with piecewise continuous or rapidly changing states.
 There are two categories in each solver type which are continuous and discrete. Figure 3.2 provides a
chart for solver classification.

Figure 3.2 Flowchart for solver classification in SIMULINK.


 AFTER setting all the parameters, CLICK the play button to run the simulation.

Page 16 of 25
Example: If x is a variable of sine wave of 10 amplitude 0.7958 Hz frequency and the output should be limited,
so that the value of x should be saturated on +8.

 Open the Simulink library > Sources > Sine Wave > Drag it to the SIMULINK desktop
 Double click on the Sin block and change its amplitude to 10 and frequency to 0.7958 Hz (you need
to convert the frequency units from Hz to rad/sec (0.7958 Hz=5rad/sec)).
 Open the Signal routing in Simulink library > switch > drag it to the SIMULINK desktop.
 Double click on the ‘switch’ block > the threshold should be equal 8

Drag a Constant block and Scope block to SIMULINK desktop. Connect the blocks as follows

Run the previous model you have created, once using fixed step and another with variable step. Comment on
the results:
Note: In fixed step try different step size (e.g.: 0.1, 0.01, 0.001 and 0.0001)
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………

Use Saturation block in Discontinuities library in Simulink library browser to saturate the Sine value at +8 by
setting upper limit to +8 and lower limit to -10 or less such as (-11, -12, etc…):
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………

Compare the results between using switch and Saturation by using Mux block and scope:
Note: use two scopes as shown in the following figure: one scope will multiplex all signals in one scope and
the other scope will generate three different plots. You can change the scope settings and display layout by
double click on the scope which will open the scope window and then click on setting button ( ).
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………

Page 17 of 25
Explorer the other blocks in Discontinuities library and their functions. These blocks can be used to model
nonlinearities behaviors of physical systems. State the other blocks which model nonlinearities in the
system
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………

4. Exercise 4: Build and Edit a Model in the Simulink Editor.


This example shows the basics of how to create a model, add blocks to it, connect blocks, and simulate the
model. You also learn how to organize your model with subsystems, name parts of a model, and modify a
model.
Start Simulink and Create a Model
1. On the MATLAB® Home tab, click Simulink.
2. In the Simulink® Start Page, click the Blank Model template.
A new model based on the template opens in the Simulink Editor.
3. Open the Library Browser so that you can access the blocks you need to create your model. In the
Simulink Editor, click the Library Browser button .
Add Blocks to the Model
A minimal model takes an input signal, operates on it, and outputs the result. In the Library Browser, the
Sources library contains blocks that represent input signals. The Sinks library has blocks that you can use to
capture and display outputs. The other libraries contain blocks you can use for a variety of purposes, such as
math operations.
In this basic model, the input is a sine wave, the operation is a gain (which increases the signal value by
multiplying), and you output the result to a scope. Try different techniques to explore the library and to add
blocks to your model.
Page 18 of 25
The Editor names blocks as you add them. For example, it names the first Gain block that you add Gain, the
next Gain1, and so on. By default, these names are hidden. However, you can see the name by selecting the
block. You can also explicitly name a block so that the name appears. You can display all names given by
the Editor by selecting Display and clearing the Hide Automatic Names check box. For more information
on displaying block names.
1. Open the Sources library. In the tree view of the Library Browser, click the Sources library.
2. In the right pane, hover over the Sine Wave block to see a tooltip describing its purpose.
3. Add a block to your model using a context menu. Right-click the Sine Wave block and select Add block
to model untitled. (To learn more about the block, select Help from the context menu.)
4. Add a block to your model by dragging. In the library tree view, click Math Operations. In the Math
Operations library, locate the Gain block and drag it to your model to the right of the Sine Wave block.
5. In the library tree view, click Simulink to view the sublibraries as icons in the right pane. This view is an
alternative way to navigate the library structure. Double-click the Sinkslibrary icon.
6. In the Sinks library, locate the Scope block and add it to your model using the context menu or by
dragging it.
The figure shows your model so far.

Align and Connect Blocks


Connect the blocks to create the relationships between model elements that you need to make the model
operate. Reading the model is easier when you line up the blocks according to how they interact with each
other. Shortcuts help you to align and connect the blocks.
1. Drag the Gain block so it lines up with the Sine Wave block. An alignment guide appears when the
blocks line up horizontally. Release the block, and a blue arrow appears as a preview of the suggested
connection. The block name appears while the block is selected.

2. To make the connection, click the end of the arrow. A solid line appears in place of the guide.
3. Line up and connect the Scope block to the Gain block using the same technique.
Tip

Use the Diagram > Arrange menu for additional alignment options.
Set Block Parameters
You can set parameters on most blocks. Parameters help you to specify how a block operates in your model.
You can use the default values or you can set values as needed. Use the Property Inspector to set parameters.
Alternatively, you can double-click most blocks to set the parameters using a block dialog box. To
understand when to use each approach.
In your model, set the sine wave amplitude and the gain value.
1. Display the Property Inspector. Select View > Property Inspector.
2. Select the Sine Wave block.
3. In the Property Inspector, set the Amplitude parameter to 2.
4. Select the Gain block and set the Gain parameter to 3. The value appears on the block.

Page 19 of 25
Add More Blocks
Suppose that you want to perform another gain but on the absolute value of the output from the Sine
Wave block. Add blocks for this purpose, trying different techniques for locating blocks in the library and
adding them to your model.
1. If you know the name of the block that you want to add, you can use a shortcut. Double-click where you
want to add the block, and type the block name, in this case Gain. A list of possible blocks appears.

2. Click the block name or, with the block name highlighted, press Enter. You can use the arrow keys to
highlight the block name if it is not first in the list.
3. Some blocks display a prompt for you to enter a value for one of the block parameters. The Gain block
prompts you to enter the Gain value. Type 3 and press Enter.
4. To get an absolute value, add an Abs block. Suppose you do not know the library a block is in or the full
name of the block. You can search for it using the search box in the Library Browser. Enter abs in the
search box and press Enter. When you find the Abs block, add it to the left of the new Gain block.
5. Add another Scope block. You can right-click the existing Scope block and drag to create the copy or
use Edit > Copy and Edit > Paste.
The figure shows the current state of your model.

Branch a Connection
The input to the second Gain block is the absolute value of the output from the Sine Wave block. To use a
single Sine Wave block as the input to both gain operations, create a branch from the Sine Wave block
output signal.
1. For the first set of blocks in your model, you used the horizontal alignment guides to help you align and
connect them. You can also use guides to align blocks vertically. Drag the second Scope block so that it
lines up under the first one. Release it when the vertical alignment guide shows that the blocks are
aligned.

2. Align and connect the Abs and Gain blocks as shown.

Page 20 of 25
3. Create a branch from the Sine Wave block output to the Abs block. With your cursor over the output
signal line from the Sine Wave block, press Ctrl and drag down. Drag the branch until the end is to next
to the Abs block.

4. Drag toward the Abs block until the line connects to it. Move the vertex as needed to straighten the line.
(A circle appears over the vertex.)
5. Name signals. Double-click the signal between the lower Gain block and the Scope block and
type Scope. Double-click the line and not a blank area of the canvas. For other techniques that you can
use with signal names.

Try these methods to connect blocks:


 Drag a connection from the output of one block to the input of the other block. Use this technique when your
blocks are already aligned, that is, no guideline appears.
 Select the first block and Ctrl+click the block you want to connect it to. This technique is useful when you
want to connect blocks that have multiple inputs and outputs, such as multiple blocks to a bus or two
subsystems with multiple ports. This technique is also useful when you do not want the blocks to align. The
connection line bends as needed to make the connection, as shown in the figure.

Page 21 of 25
To approximate a diagonal line from line segments, press Shift and drag a vertex.

Tip

To improve the shape of a signal line, select the line and, from the ellipsis menu, select Autoroute Line. The
line redraws if a better route between model elements is possible. You can select Autoroute Lines from the
ellipsis menu to improve lines with a single block selected or with multiple model elements selected by
dragging a selection box.
Organize Your Model
You can group blocks in subsystems and label blocks, subsystems, and signals. For more information about
subsystems.
1. Drag a selection box around the Abs block and the Gain block next to it.
2. Move the cursor over the ellipses that appear at the corner of the box where you ended the selection.
From the ellipsis menu, select Create Subsystem.

A subsystem block appears in the model in place of the selected blocks. The output signal name from the
Gain block becomes the name of the output port on the subsystem.
To resize the subsystem block for the best fit in your model, drag the block handles.

3. Give the subsystem a meaningful name. Select the block, double-click the name, and type Absolute
Value. Naming a block causes the name to appear in the model.
4. Open the Absolute Value subsystem by double-clicking it.
Tip

To use the Explorer Bar to navigate the model hierarchy, right-click the subsystem and select Open in
New Tab.
The subsystem contains the blocks and signal that you selected as the basis of the subsystem. They are
connected in sequence to two new blocks: an Inport block and an Outport block. Inport and Outport
blocks correspond to the input and output ports on the subsystem. Creating the subsystem from a
selection that includes a named signal adds the name of the signal to the corresponding inport or outport.

Page 22 of 25
5. Click the Up to Parent button to return to the top level of the model.
6. The figure shows the model after you create the subsystem and name it.

Simulate Model and View Results

1. You can simulate a model using the Simulation > Run command (Ctrl+T) or the Run button .
Simulate the model using the technique that you prefer.
In this example, simulation runs for 10 seconds, the default setting.
2. Double-click both Scope blocks to open them and view the results.
The figure shows the two results. In the second plot, as expected, the absolute value of the sine wave is
always positive.

Page 23 of 25
Modify the Model
You can add blocks to a signal, remove blocks from models, and redraw connections. To modify this model,
add a bias to the input to both branches of your model. Also, replace one of the scopes with a different sink.
Add more blocks to the subsystem and another output.
For some blocks, connecting a line to it adds an input port or output port. For example, a port appears on a
subsystem when you connect a line to it. Additional blocks that add ports include the Bus Creator, Scope,
and Add, Sum, and Product blocks. For more information, see Automatic Port Creation: Add inports and
outports to blocks when routing signals.
1. Add a Bias block to the model and set the Bias parameter to 2.
2. Drag the block onto the signal line after the Sine Wave block but before the branch. If you need to make
room for the block, drag the Sine Wave block to the left or move the end of the branch by dragging it to
the right.
When you drag the block onto the signal line, the block connects to the signal line at both ends. Release
the block when you are satisfied with the position.

3. Remove the top Scope block. Press Shift and drag the block if you want to disconnect it from the model
but do not want to delete it. Cut or delete it using the Edit menu commands or a keystroke. The broken
connection appears as a red dotted line.
Tip

When you delete a block that has one input and one output, a prompt appears between the broken
connection lines. Click the prompt to connect the signals.
4. Add a To Workspace block to the model at the end of the broken connection. The To Workspace block
outputs the results to a variable in the MATLAB workspace.
5. Add a Sine Wave block to the model and set the amplitude to 5. Place it to the left of the subsystem.
6. Add another input to the subsystem. Drag a line from the new Sine Wave block to the left side of the
subsystem. A new port, In2, appears on the subsystem.
7. Add an output to the subsystem. Add another To Workspace block to the model and place it to the right
of the subsystem. Drag a line from its input port to the right side of the subsystem. A new port, Out2,
appears on the subsystem.
8. Open the subsystem and rename the Out2 block Workspace. Add a Manual Switch block to the
subsystem. Resize it and connect it as shown. Branch the signal after the Gain block to direct the output
to the To Workspace block.

Page 24 of 25
Then, return to the top level of the model. The figure shows the current model.

9. Simulate the model.


o The simout and simout1 variables appear in the MATLAB workspace. Double-click each variable to
explore the results.
o If you want to use the second sine wave as input to the subsystem algorithm, open the subsystem and
double-click the switch. The input changes to In2. Simulate again.
Tip

To toggle between simulating the model with and without the effects of the Bias block, right-click
the Bias block and select Comment Through. The block stays in the model but does not affect the
operation. Right-click the Bias block and select Uncomment to enable the block. The Comment
Out command comments out the block’s output signal, so signal data does not pass through. Try each of
these commands to better understand their effects.

Page 25 of 25

You might also like