ASSIGNMENT #1
I’ve updated Chapter 16 from MATLAB for Engineers to match a more recent
version of Simulink, which of course is being constantly updated. Only the
portions of the chapter that you need for this assignment are repeated here.
CHAPTER 16
Simulink—A Brief Introduction
Objectives
After reading this chapter you should be able to:
Understand how Simulink uses blocks to represent common mathematical processes
Create and run a simple Simulink Model
Import Simulink results into MATLAB
INTRODUCTION
Simulink is an interactive, graphics-based program that allows you to solve problems by creating
models using a set of built-in “blocks”. It is part of the MATLAB software suite, and requires
MATLAB to run. Simulink is included with the student edition of the software, but is not part of
the standard installation of the professional edition; this means that it may or may not be
included on your version of MATLAB. LabView, produced by National Instruments, is
Simulink’s biggest competitor.
16.1 APPLICATIONS
Simulink is designed to provide a convenient method for analyzing dynamic systems, i.e.,
systems that change with time. In particular, it found early acceptance in the signal processing
community, and is reminiscent of the approach used to program analog computers. In fact, one
way to think of Simulink is as a virtual analog computer. Analog computers required the user to
make actual physical connections between electrical components that acted as adders,
multipliers, integrators etc. Output from the computer was viewed on an oscilloscope. This is
reflected in both the names of the blocks used in Simulink, and in the icons used to represent
various operations.
One shouldn’t jump to the conclusion that Simulink is only useful for analyzing electrical
systems. Similar mathematical equations describe the behavior of dynamic mechanical systems,
reactive chemical systems, and dynamic fluid systems. In fact, it is common to introduce
students to the behavior of electricity through analogy with pipe flow problems.
Simulink’s strength is its ability to model dynamic systems—which are modeled mathematically
as differential equations. Usually these systems change with time, but the independent variable
could also be location. Differential equations can be solved numerically in MATLAB by making
use of functions such as ode45, which utilizes Runge–Kutta techniques. They can also be solved
analytically using the symbolic algebra toolbox, which utilizes the MuPad engine. Simulink uses
similar methods, but they are transparent to the user. Instead of programming equations directly,
a visual model is created by collecting appropriate Simulink blocks and connecting them
together, using a graphical user interface. (Note: in ENGR 1030 and ENGR 1035 we will not be
addressing the parts of this chapter related to differential equations. Please refer to the complete
chapter in your textbook if you are interested)
16.2 GETTING STARTED
To start Simulink, open MATLAB and type
simulink
into the command window. (Or select Simulink Library from the tool strip as shown in Figure
16.1).
Figure 16.1 Access Simulink either from the command window, or by selecting the Simulink
Library icon from the tool strip.
The Simulink Library Browser opens, showing the available libraries of blocks used to create a
Simulink model (Figure 16.2). The browser is the location where you’ll select blocks and drag
them into the model workspace. Spend a few minutes exploring the browser. To view the blocks
available in each library, either select the library from the left-hand pane or double click on the
icons in the right-hand pane. In particular, take a look at the Commonly Used Blocks library—
the Source and Sink libraries and the Math Operations library.
Simulink’s strength is in solving complex dynamic systems, but before we try to work on a
complex system, it would be better to build some very simple static models to demonstrate the
problem-solving process. To create a new model, select the new model icon from the browser
window. (Figure 16.2) The model window opens on top of the library browser (Figure 16.3). For
convenience, resize the library browser window and the model window so that you can see both
on the computer screen. You’ll also want to keep the MATLAB desktop open, but resize it so
that it also fits on your computer screen without overlapping the other windows. See for example
Figure 16.4.
New Model icon
Double-click on a
library name to see
the available blocks
Figure 16.2 The Simulink Library Browser contains numerous blocks that are used to create a
Simulink model.
Drag blocks into the
model window to
solve problems
Figure 16.3 The model window is the workspace where Simulink models are created and
executed.
Figure 16.4 Simulink uses multiple windows. Arrange them on your computer desktop so that
you can easily drag blocks from the Simulink Library Browser to the model window.
Our first model will simply add two numbers. From either the Source library or the Commonly
Used Blocks library, click and drag the constant block into the model window. Repeat the
process, so that you have two copies of the constant block in the model, as shown in Figure 16.5
Figure 16.5 Two copies of the constant block were added to the model.
Now drag the sum block into the model. It is found both in the Commonly Used Blocks library
and the Math Operations library. Notice that the sum block has two “ports.” You can draw
connections between the constants and the sum block by clicking and dragging between the
ports, as shown in Figure 16.6. You should notice that the cursor changes to a cross-hair as you
connect the ports. The model we’ve created thus far just adds 1 + 1, and doesn’t display the
answer. We’ll need to modify the constant blocks to specify a value different from the default,
which in this case is 1. Double click on each constant block, and change the “constant value”
field, for example, to 5 in the top block and 6 in the bottom block.
Figure 16.6 The constants are connected to the sum block. Change the values in the constant
blocks by double clicking and modifying the “constant value” field.
To add a display option, look in the sink library. For this case, the display block is all we need,
so drag it to the model and connect it to the output port of the sum block. The last thing we need
to do before running the model is to adjust the simulation time, from the box on the menu bar
(see Figure 16.7). Since nothing in this calculation will change with time, we can change the
value to zero. Run the simulation by selecting the run button on the toolbar, (the black triangle)
or by selecting Simulation → Start from the menu bar.
Simulation time
Run the simulation
Result
s
Figure 16.7 (a) The completed model. (b) Results are shown in the display block.
a. Save this model in the usual way, by selecting File → Save and adding an appropriate
name. The files are stored with the extension, .slx. Save your model
as your_name_first_model.slx and submit it as part of assignment #1.
As the sum block serves both the addition and subtraction functions, you could use this same
model to perform subtraction operations. Double click the sum block in the model and the block
parameter window opens, as shown in Figure 16.8
Figure 16.8 The sum block can be used to perform subtraction operations, as well as for adding
more than two input values.
The block description is located near the top of the window, and provides information on how to
use the block—in this case the sum block. This description includes instructions to change the
block into a “subtraction block” by changing the input from |++ to |+. We could also adjust the
block to add three inputs by changing the list of signs field to the number 3. Adjust your model
and run it several more times as you explore the possibilities for the sum block. (Note: the bar
symbol, | , affects the spacing of the input ports on the block – experiment with adding additional
bars… for example +|+)
Hint: Simulink includes a “subtraction” block, but if you open its block parameter window
you’ll notice the block title is “sum.”
The previous example was trivial. A slightly more complex model, with results that change with
time, is described in Example 16.1
______________________________________________________________________________
EXAMPLE 16.1
Random Numbers
As we saw in Example 3.5, random numbers can be used to simulate the noise we hear on the
radio as static. Although we could solve a similar problem in MATLAB, let’s use Simulink. In
this case, instead of a music file use a sine wave as the input to which we want to add the noise,
using the following equation:
y 5*sin(2t ) noise
The noise should be the result of a uniform random number generator, with a range of 0 to 1.
1. State the Problem
Create a Simulink model of the equation
y 5*sin(2t ) noise
where the noise is based on a random number.
2. Describe the Input and Output
Use Simulink’s built-in sine wave generator to provide the sine wave.
Input
Use Simulink’s built-in random number generator to simulate the noise.
Output
View the results using the Simulink Scope block.
3. Develop a Hand Example
In this case, since we are well versed in MATLAB, a MATLAB solution will substitute
for a hand example.
t=0:0.1:10;
noise = rand(size(t));
y=5*sin(2*t)+noise;
plot(t,y)
title('A sine wave with noise added'), xlabel('time,s'), ylabel('function value')
which results in the plot shown in Figure 16.9.
A sine wave with noise added
6
function value
4
2
0
-2
-4
-6
0
2
4
6
8
10
time,s
Figure 16.9 Adding noise to a sine wave can be accomplished using MATLAB, as well as
Simulink.
4. Develop a Simulink Solution
Simulink includes blocks for creating both sine waves, and for uniform random number
generators. You can find both in the Source Library. You’ll also need to include an add block.
Finally, add a scope (the name comes from the word “oscilloscope”) to view the plotted result.
Your model should resemble the one shown in Figure 16.10. Notice that the time field in the
upper right corner of the model is set to 10 seconds, and that two additional scopes were added
so that we can observe the behavior of the sine wave generator, the random number generator,
and the combined output.
Figure 16.10 Simulink model to add noise to a sine wave.
The model specifies only a sine wave, not the entire sine portion of the expression, 5*sin(2t ) .
Open the Sine Wave block by double clicking on the icon inside the model. The Source Block
Parameters window opens (as shown in Figure 16.11), allowing us to specify the amplitude, the
frequency and additional parameters as needed. By changing the amplitude to 5 and the
frequency to 2, the block now represents the first term in our equation.
Figure 16.11 (a) The Sine Wave parameter window. (b) The Uniform Random Number
parameter window. The Source Block Parameter window for each Simulink block allows the
user to modify the default values of the input parameters. Access the parameter window by
double clicking on the block in the model window.
Similarly, the random number generator parameter window can be modified to specify a
minimum value of 0 and a maximum value of 1. Run the model by selecting the start simulation
triangle, or by selecting Simulation → Run. To view the output, double click on each of the
scopes. Scale the images by selecting the autoscale icon as shown in Figure 16.12, which shows
the results of the combined inputs.
Autoscale icon used to
resize the plotting window
Figure 16.12 The scope output from the three oscilloscopes specified in the Simulink model.
5. Test the Solution
Compare the results to those found with the MATLAB solution. We could also revise the
model, so that the results are sent to MATLAB by replacing the scope for the combined
output with the ‘To workspace’ block, as shown in Figure 16.13. The ‘To workspace’
block is found in the sinks library. Before running the model, you’ll need to modify the
block parameters (double click on the block to open the window). Change the Save
format from Structure to Array. Re-execute the model, and observe that two new arrays
have appeared in the MATLAB workspace window, simout and tout, both of which are
101x1 double precision arrays. The values in the arrays can now be used for plotting, or
in other calculations.
Save your model as your_name_example_16_1.slx and submit it as part of
assignment #1.
Figure 16.13 The simout block sends simulation results to the MATLAB workspace, where they
can be used in other calculations as needed.
I’ve deleted content on differential equations – if you are interested please refer to
Chapter 16 in your textbook.
SUMMARY
Simulink is part of the MATLAB family of programs. It uses a graphical user
interface to facilitate the development of models that represent real systems. Simulink
is especially useful for modeling dynamic systems––those that can be mathematically
described as differential equations.
Simulink relies on a large library of blocks, which can be combined to solve a wide
variety of problems. Its visual approach offers an alternative to building m-file
programs using the numerical techniques described in earlier chapters. However,
these same techniques (for example, ode45) are used by Simulink when its models are
executed.
The MATLAB help function includes an extensive tutorial on using Simulink,
including many examples.
Command and Function
simulink
opens the Simulink library browser
KEY TERMS
dynamic systems
analog computers
differential equations
model
block
PROBLEMS
16.1 The sinc function is often used in electrical engineering applications. It is defined as
sinc( x)
sin( x)
x
b. Use Simulink to model the behavior of the sinc function, from -20 to 20 seconds. Display
your results using Simulink’s scope block. To adjust the simulation time, in the model
window menu bar select Simulation → Configuration Parameters. (Note: In this
problem time is represented as x.) You may get an error message telling you that an
undefined result occurs… you can ignore it.) Use the clock function to generate the x
values and use the sine wave source function to generate the sin(x) values.
c. Repeat the problem, but this time use the clock function to generate x values, and use the
trigonometric function from the Math Operations library. (You’ll have to split the output
from the clock function.)
d. Save your model as your_name_problem_16_1.slx and submit it as part of assignment
#1.
16.2 The equation of a circle can be represented parametrically as
x = sin(t)
y = cos(t)
where t varies from 0 to 2*pi. Create a Simulink model to parametrically graph a circle using the
xy graph block found in the sink library. To model cosine, you will need to modify the trig
function block. (Hint: use the clock function as your source and the trig function block to model
sin and cos… do not use the sin source block.)
Save your model as your_name_problem_16_2.slx and submit it as part of assignment
#1.
16.3 The multiplexer block (Mux) accepts multiple inputs that can then be sent to a scope block
to create a graph with multiple signal plots. Use two sine blocks to create a signal representing
the sin(t) and the cos(t). Combine the signals with the Mux block (found in the Commonly Used
Blocks library), and plot the results from 0 to 20 seconds, using a Scope block.
Save your model as your_name_problem_16_3.slx and submit it as part of assignment
#1.
© Copyright 2025 Paperzz