0% found this document useful (0 votes)
40 views

Simulink

Uploaded by

HONNEY TAAK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Simulink

Uploaded by

HONNEY TAAK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

An Introduction to Simulink

What is Simulink?
Simulink is a visual programming interface designed to make modelling systems intuitive. It
offers a way to solve equations numerically using a graphical user interface, rather than
requiring code.

Models contain blocks, signals, and annotation on a background:


1. Blocks are mathematical functions; they can have varying numbers of inputs and
outputs.
2. Signals are lines connecting blocks, transferring values between them. Signals are
different data types, for example numbers, vectors, or matrices. Signals can be
labelled.
3. Annotations of text or images can be added to the model, and while not used in the
calculations they can make it easier for others to understand design decisions in the
model.

Text Annotation

Blocks
Signal and Labels

Figure 1: Basic components of Simulink.

Simulink Block Diagrams


Simulink is a graphical modelling and simulation environment for dynamic systems. It can
create block diagrams, where blocks represent parts of a system. A block can represent a
physical component, a small system, or a function. An input/output relationship fully
characterizes a block.
Consider these examples:
• You push a cart, and it moves — The cart is the block, the force you apply is the input,
and the cart's position is the output.
• A faucet fills a bucket — Water goes into the bucket at a certain flow rate, and the
bucket gets heavier. A block can represent the bucket, with flow rate as the input and
its weight as the output.
Simulink provides block libraries that are collections of blocks grouped by functionality.
Consider an example of megaphone, a sound wave goes into the megaphone as its input, and
a louder version of the same wave comes out as its output. To model a megaphone that
multiplies its input by a constant to amplify it, use a Gain block from the Math
Operations library.

Figure 2: Gain Block

where the > signs denote the inputs and outputs of a block, which can be connected to other
blocks.

Creating a Simple Model in Simulink


Simulink is used to model a system and to simulate the dynamic behaviour of that system.
The basic techniques you use to create a simple model in this tutorial are the same as those
you use for more complex models.

1. Open Simulink from MATLAB


a) Start MATLAB. From the MATLAB toolstrip, click the Simulink button , shown in
Figure 3.
b) A new window of Simulink Start page will top up (see figure 4)

Figure 3: Open Simulink


Figure 4: Simulink start page.

c) Click the Blank Model icon, highted in figure 4. It will open the Simulink Editor.

Figure 5: Simulink editor

d) From the Simulation tab, select Save > 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.

2. Open Simulink Library Browser


Simulink provides a set of block libraries, organized by functionality in the Library Browser.

a) From the Simulation tab, click the Library Browser button . The Simulink library
browser will top up as shown in figure 6.
Figure 6: Simulink library browser.

b) To browse through the block libraries, select a category and then a functional area in
the left pane. To search all the available block libraries, enter a search term.
For example, to find the Pulse Generator block, in the search box on the browser toolbar,
enter pulse, and then press Enter. Simulink searches the libraries for blocks with pulse in their
name or description and then displays the blocks.

Figure 7: Searching pulse generator in library browser.


To get detailed information about a block. Right-click the Pulse Generator block, and then
select Help for the Pulse Generator block. The Help browser opens with the reference page
for the block. Blocks typically have several parameters. You can access all block parameters
by double-clicking the block. Some commonly used libraries are shown in Table 1.
Table 1: Description of commonly used libraries in Simulink

3. Add Blocks to a Model


To start building the model, browse the library and add the blocks to workspace.
Following the previous example, drag the Pulse Generator block to the Simulink Editor. A copy
of the Pulse Generator block appears in your model with a text box.

Figure 8: Adding a block on Simulink workspace.

Add all other required blocks to your model using the same approach. Arrange the blocks by
clicking and dragging each block. To resize a block, drag a corner.

4. Connect Blocks
Connect the blocks by creating lines between output ports and input ports.
Figure 9: Connecting blocks.

5. Run Simulation
After you define the configuration parameters, you are ready to simulate your model.
a) In the Simulation tab, set the simulation stop time (seconds) by changing the value in
the toolbar. The default stop time is 10.0 seconds. This time value could have time
units in milliseconds or years.

Figure 10: Run the simulation.

b) To run the simulation, click the Run button . The simulation runs and produces
the output in the viewer.

Example 1: Generate, amplify, and plot a sine wave

Blocks required:
• Signal generator
• Gain
• Scope
• To workspace

Step 1: Bring all required block on Simulink model workspace.


1. Open the Simulink library and search for signal generator. Select the signal generator
block and drag it to the model workspace.
2. Similarly find other required block, gain, scope and to workspace, and bring them on
the workspace.
Figure 11: Simulink Blocks

Step 1: Modifying Block Parameters


Double click on a block to edit the block parameters.

1. Signal generator: In the parameters of signal generator select the type of signal wave you
want to use. In this example, select sine wave. Then set the amplitude “3” and frequency “1”
of the signal. Select Hz as a unit of frequency. After setting all parameters, click on apply and
then OK.

Figure 12: Block parameters of signal generator.

2. Gain: This block is used to amplify the signal by multiply it with any number “n”. Double click
on the block and set the gain value at 2.
Figure 13: Block parameters of Gain.

3. Scope: As we want to plot both the original and amplified signals in scope, open the block
and select 2 for the number of input ports as shown in figure below.

Figure 14: Setting number of inputs for scope.

4. To Workspace: The use of this block is to export results to MATLAB workspace. In the block
parameters, set the variable name and the name will be exported to MATLAB workspace. In
this example, you need two (2) To Workspace blocks for the original and amplified signals. Set
the variable name for the original signal as “x” and amplified signal as “nx”.
Figure 15: Block parameters of "to workspace" block.

Step 3: Lines and Signal Labelling


Lines transmit signals in the direction indicated by the arrow as shown below. Lines must always
transmit signals from the output terminal of one block to the input terminal of another block. The
lines connecting the blocks are called signals. By double-clicking directly on a signal, you can label it.
This makes it easier to recall what the signals are and gives useful legend labels on scopes.

Figure 16: Labelling and Connecting all blocks.

Step 4: Running Simulations


To run a system, you can click on the green play button as seen on the Simulink toolbar.
Alternatively, you can press ctrl+T or click on simulation and select the green play button.

1. Specify the stop time.


2. Run the model.
3. Open the scope to analyse the signals. You can add the legends by selecting “show legends”
from the configuration properties as shown below.

Figure 17: Scope plot of “x” and “nx” signals.

Figure 18: Configuration properties of scope plot.

Step 5: Export the results to MATLAB workspace:


After running the Simulink model, you will be able to see two variables on the MATLAB workspace.
The “out” variable is a simulation output which contains both “x” and “nx” signals.
Figure 19: MATLAB workspace.

To plot the signal, use the following commands on MATALB Command Window:

>> plot (out.x)

>> hold on

>> plot (out.nx)

>> legend ("x","nx")

Figure 20: MATLAB plot for "x"and "nx" signals.

Example 2: Model a Simple Equation

To model the equation that converts Celsius temperature to Fahrenheit.


TF = 9/5(TC) + 32

First, consider the blocks needed to build the model:


• A Ramp block to input the temperature signal, from the Sources library
• A Constant block to define a constant of 32, also from the Sources library
• A Gain block to multiply the input signal by 9/5, from the Math Operations library
• A Sum block to add the two quantities, also from the Math Operations library
• A Scope block to display the output, from the Sinks library

Next, gather the blocks into your model window.

Figure 21: Gather all blocks on model window.

Assign parameter values to the Gain and Constant blocks by opening (double-clicking) each
block and entering the appropriate value. Then, click the OK button to apply the value and
close the dialog box.
Now, connect the blocks.

Figure 22: Set parameters and link the blocks.

The Ramp block inputs Celsius temperature. Open that block and change the Initial
output parameter to 0. The Gain block multiplies that temperature by the constant 9/5. The
Sum block adds the value 32 to the result and outputs the Fahrenheit temperature.

Open the Scope block to view the output. Now, choose Run from the Simulation menu to run
the simulation. The simulation runs for 10 seconds.
Some useful videos:

1) https://uk.mathworks.com/videos/getting-started-with-simulink-part-1-building-and-
simulating-a-simple-simulink-model-1508442030520.html
2) https://uk.mathworks.com/videos/getting-started-with-simulink-69027.html
3) https://uk.mathworks.com/products/simulink.html
4) https://uk.mathworks.com/videos/calling-simulink-from-matlab-97334.html?s_tid=srchtitle

You might also like