LAB - 03 - 7th Semester Notes

advertisement
Laboratory 3: Cover Sheet
Laboratory Objectives:

Introduction to Simulink

Familiarization with Model Block Diagram Semantics ,Blocks, Sources, Sink, Link

To understand generation of a Simple Model

To understand generation of common signal sequences using Simulink
Place a check mark in the Assigned column next to the exercises your instructor has
assigned to you. Attach this cover sheet to the front of the packet of materials you submit
following the laboratory.
Activities
Remarks
Signature
Pre-lab Exercises
In-lab Exercises
Take Home Exercises
Any Other
20 | P a g e
Introduction to Simulink
Simulink is a software package for modeling, simulating, and analyzing dynamical systems.
It supports linear and nonlinear systems, modeled in continuous time, sampled time, or a
hybrid of the two. Systems can also be multirate, i.e., have different parts that are sampled
or updated at different rates.
For modeling, Simulink provides a graphical user interface (GUI) for building models as
block diagrams, using click-and-drag mouse operations. With this interface, you can draw
the models just as you would with pencil and paper (or as most textbooks depict them).
Simulink includes a comprehensive block library of sinks, sources, linear and nonlinear
components, and connectors. You can also customize and create your own blocks Models
are hierarchical. This approach provides insight into how a model is organized and how its
parts interact. After you define a model, you can simulate it, using a choice of integration
methods, either from the Simulink menus or by entering commands in MATLAB's
command window. The menus are particularly convenient for interactive work, while the
command-line approach is very useful for running a batch of simulations (for example, if
you are doing Monte Carlo simulations or want to sweep a parameter across a range of
values). Using scopes and other display blocks, you can see the simulation results while the
simulation is running. In addition, you can change parameters and immediately see what
happens, for "what if" exploration.
Thousands of scientists and engineers around the world use Simulink to model and solve
real problems in a variety of industries, including:
21 | P a g e
• Aerospace and Defense
• Automotive
• Communications
• Electronics and Signal Processing
• Medical Instrumentation
How Simulink Interacts with MATLAB
Simulink is tightly integrated with MATLAB. It requires MATLAB to run, depending on
MATLAB to define and evaluate model and block parameters. Simulink can also utilize
many MATLAB features. For example, Simulink can use MATLAB to:

Define model inputs.

Store model outputs for analysis and visualization.

Perform functions within a model, through integrated calls to MATLAB operators
and functions.
What Is Model-Based Design
In Model-Based Design, a system model is at the center of the development process, from
requirements development, through design, implementation, and testing. The model is an
executable specification that is continually refined throughout the development process.
After model development, simulation shows whether the model works correctly.
Modeling Process
There are six steps to modeling any system:
1. Defining the System.
2. Identifying System Components.
3. Modeling the System with Equations.
4. Building the Simulink Block Diagram.
5. Simulating the Model.
6. Validating the Simulation Results
22 | P a g e
Section A
Understanding Simulink
Modeling Dynamic Systems
A Simulink block diagram model is a graphical representation of a mathematical model of a
dynamic system.
Blocks
The subfolders underneath the "Simulink" folder indicate the general classes of blocks
available for us to use:








Continuous: Linear, continuous-time system elements (integrators, transfer
functions, state-space models, etc.)
Discrete: Linear, discrete-time system elements (integrators, transfer functions, state
space models, etc.)
Functions & Tables: User-defined functions and tables for interpolating function
values
Math: Mathematical operators (sum, gain, dot product, etc.)
Nonlinear: Nonlinear operators (coulomb/viscous friction, switches, relays, etc.)
Signals & Systems: Blocks for controlling/monitoring signal(s) and for creating
subsystems
Sinks: Used to output or display signals (displays, scopes, graphs, etc.)
Sources: Used to generate various signals (step, ramp, sinusoidal, etc.)
Block Diagram Semantics
Blocks can be classified into:
Nonvirtual Blocks: Nonvirtual blocks represent elementary systems. Nonvirtual blocks
play an active role in the simulation of a system. If you add or remove a nonvirtual block,
you change the model's behavior.
Virtual Blocks: Virtual blocks, by contrast, play no active role in the simulation; they help
organize a model graphically. Examples of virtual blocks are the Bus Creator and Bus
Selector which are used to reduce block diagram clutter by managing groups of signals as a
"bundle." You can use virtual blocks to improve the readability of your models.
23 | P a g e
Built-in Blocks: Simulink provides libraries of blocks representing elementary systems that
can be used as building blocks. The blocks supplied with Simulink are called built-in blocks.
Simulink users can also create their own block types and use the Simulink editor to create
instances of them in a diagram.
Custom Blocks: Simulink allows you to create libraries of custom blocks that you can then
use in your models. User-defined blocks are called custom blocks.
States
Typically the current values of some system, and hence model, outputs are functions of the
previous values of temporal variables. Such variables are called states.
Two types of states can occur in a Simulink model: discrete and continuous states.
Continuous States
A continuous state changes continuously. Examples of continuous states are the position and
speed of a car.
Figure: Simulink/ Continuous
Discrete States
A discrete state is an approximation of a continuous state where the state is updated
(recomputed) using finite (periodic or aperiodic) intervals. An example of a discrete state
would be the position of a car shown on a digital odometer where it is updated every second
as opposed to continuously.
24 | P a g e
Signals
Simulink uses the term signal to refer to a time varying quantity that has values at all points
in time. The destinations of the signal are blocks that read the signal during the evaluation of
its block methods (equations). A good analogy of the meaning of a signal is to consider a
classroom. The teacher is the one responsible for writing on the white board and the students
read what is written on the white board when they choose to. This is also true of Simulink
signals, a reader of the signal (a block method) can choose to read the signal as frequently or
infrequently as so desired.
Concept of Signal and Logic Flow
In Simulink, data/information from various blocks is sent to another block by lines
connecting the relevant blocks. Signals can be generated and fed into blocks (dynamic
/static). Data can be fed into functions. Data can be dumped into sinks, which could be
virtual oscilloscopes, displays or could be saved to a file. Data can be connected from one
block to another. Can be branched, multiplexed etc. In simulation, data is processed and
transferred only at discrete times, since all computers are discrete systems.
25 | P a g e
Sources and Sinks
The sources library contains the sources of data/signals that one would use in a dynamic
system simulation. One may want to use a constant input, a sinusoidal wave, a step, a
repeating sequence such as a pulse train, a ramp etc. One may want to test disturbance
effects, and can use the random signal generator to simulate noise. The clock may be used to
create a time index for plotting purposes.
Figure: Simulink/Sources
The sinks are blocks where signals are terminated or ultimately used. In most cases, we
would want to store the resulting data in a file, or a matrix of variables. The data could be
displayed or even stored to a file. The STOP block could be used to stop the simulation if
the input to that block (the signal being sunk) is non-zero. Unused signals must be
terminated, to prevent warnings about unconnected signals.
Figure: Simulink/Sinks
26 | P a g e
Lines
Lines transmit signals in the direction indicated by the arrow. Lines must always transmit
signals from the output terminal of one block to the input terminal of another block.
Figure: Line between Blocks
Lines can never inject a signal into another line; lines must be combined through the use of
a block such as a summing junction.
A signal can be either a scalar signal or a vector signal. For Single-Input, Single-Output
systems, scalar signals are generally used. For Multi-Input, Multi-Output systems, vector
signals are often used, consisting of two or more scalar signals. The lines used to transmit
scalar and vector signals are identical. The type of signal carried by a line is determined by
the blocks on either end of the line.
A branch line is a line that starts from an existing line and carries its signal to the input port
of a block. Both the existing line and the branch line carry the same signal. Using branch
lines enables you to cause one signal to be carried to more than one block.
In this example, the output of the Product block goes to both the Scope block and the To
Workspace block.
Figure: Branch Line example
To add a branch line, follow these steps:
1 Position the pointer on the line where you want the branch line to start.
2 While holding down the Ctrl key, press and hold down the left mouse button.
3 Drag the pointer to the input port of the target block, and then release the mouse button
and the Ctrl key.
You can also use the right mouse button instead of holding down the left mouse button and
the Ctrl key.
27 | P a g e
Section B
Building a Simple Model
This example shows you how to build a model using many of the model building commands
and actions you will use to build your own models. The instructions for building this model
in this section are brief. The model integrates a sine wave and displays the result, along with
the sine wave. The block diagram of the model looks like this.
To create the model, first type “simulink” in the MATLAB command window. On
Microsoft Windows, the Simulink Library Browser appears.
Figure: Simulink Library Browser
To create a new model, select Model from the New submenu of the Simulink library
window's File menu. To create a new model on Windows, select the New Model button
28 | P a g e
on the Library Browser's toolbar.
Figure: New Model Icon
Figure: New Model Window
To create this model, you will need to copy blocks into the model from the following
Simulink block libraries:
29 | P a g e
• Sources library (the Sine Wave block)
• Sinks library (the Scope block)
• Continuous library (the Integrator block)
• Commonly Used Blocks (the Mux block)
To copy the Sine Wave block from the Library Browser, first expand the Library Browser
tree to display the blocks in the Sources library. Do this by clicking on the Sources node to
display the Sources library blocks. Finally, click on the Sine Wave node to select the Sine
Wave block.
Here is how the Library Browser should look after you have done this
Simulink Library
Sources Library
Sin Wave Block
Figure: Library Browser
Now drag the Sine Wave block from the browser and drop it in the model window.
Simulink creates a copy of the Sine Wave block at the point where you dropped the node
icon.
30 | P a g e
To copy the Sine Wave block from the Sources library window, open the Sources window
by double-clicking on the Sources icon in the Simulink library window. (On Windows, you
can open the Simulink library window by right-clicking the Simulink node in the Library
Browser and then clicking the resulting Open Library button.)
Figure : Sin Block is dragged to the Model Window
Copy the rest of the blocks in a similar manner from their respective libraries into the model
window. You can move a block from one place in the model window to another by dragging
the block. You can move a block a short distance by selecting the block, then pressing the
arrow keys.With all the blocks copied into the model window, the model should look
something like this
Figure: Model Window
If you examine the block icons, you see an angle bracket on the right of the Sine Wave
block and two on the left of the Mux block. The > symbol pointing out of a block is an
output port; if the symbol points to a block, it is an input port. A signal travels out of an
31 | P a g e
output port and into an input port of another block through a connecting line. When the
blocks are connected, the port symbols disappear.
Now it's time to connect the blocks. Connect the Sine Wave block to the top input port of
the Mux block. Position the pointer over the output port on the right side of the Sine
Wave block. Notice that the cursor shape changes to cross hairs.
Now it's time to connect the blocks. Connect the Sine Wave block to the top input port of
the Mux block. Position the pointer over the output port on the right side of the Sine Wave
block. Notice that the cursor shape changes to cross hairs.
Now release the mouse button. The blocks are connected. You can also connect the line to
the block by releasing the mouse button while the pointer is inside the icon. If you do, the
line is connected to the input port closest to the cursor's position.
If you look again at the model at the beginning of this section, you'll notice that most of
the lines connect output ports of blocks to input ports of other blocks. However, one line
connects a line to the input port of another block. This line, called a branch line, connects
32 | P a g e
the Sine Wave output to the Integrator block, and carries the same signal that passes from
the Sine Wave block to the Mux block.
Drawing a branch line is slightly different from drawing the line you just drew. To weld a
connection to an existing line, follow these steps:
1. First, position the pointer on the line between the Sine Wave and the Mux block
2. Press and hold down the Ctrl key (or click the right mouse button). Press the mouse
button, then drag the pointer to the Integrator block's input port or over the Integrator
block itself.Release the mouse button. Simulink draws a line between the starting
point and the Integrator block's input port
3. Finish making block connections. When you're done, your model should look
something like this
Now, open the Scope block to view the simulation output.
33 | P a g e
Keeping the Scope window open, set up Simulink to run the simulation for 10 seconds.
First, set the simulation parameters by choosing Configuration Parameters from the
Simulation menuof the Model window.
On the dialog box that appears, notice that the Stop time is set to 10.0 (its default value).
Close the Configuration Parametersdialog box by clicking on the OK button. Simulink
applies the parameters and closes the dialog box.
34 | P a g e
Choose Start from the Simulation menu and watch the traces of the Scope block's input.
The simulation stops when it reaches the stop time specified in the Configuration
Parametersdialog box or when you choose Stop from the Simulation menu.
To save this model, choose Save from the File menu and enter a filename and location.
That file contains the description of the model.
35 | P a g e
Generation of Common Signal Sequences
Create this model by finding the blocks in the library and linking it properly.
36 | P a g e
Section C
AssignmentTask
Simulate the equation A(t)cos(2pfct), for 0 < t < 1, unit: second where A(t) = t for t > 0, fc =
50Hz
Step 1:Find the suitable sources and tune the parameters:
37 | P a g e
38 | P a g e
39 | P a g e
40 | P a g e
41 | P a g e
LAB Assignments
Complete “Assignment Task” in Lab manual and print the results with your
1.
assignments.
2.
Generate different kinds of sources and display them using different sources. The
blocks are located in the main Simulink blockset. Simulate this task for 10 unit
time. In a single .mdl file, perform the following:
a. Periodic pulse signals having amplitude of 8, period of 2 sec, pulse width of
10. Display this signal on a scope.
b. A constant value of 4 and display it on both scope and a display unit.
c. Generate two sine signals. The first one is from the built-in Sine Wave block.
𝜋
This signal is given as: (𝑡) = 2sin⁡(2𝜋(0.1)𝑡 + 4 . The second signal is again
a sine signal from the Signal Generator with the same parameters except that
the phase is 0. Display both signal on the same scope.
d. Generate a ramp signal with a slope of 4. Display this signal on the scope and
at the same time store this signal in Matlab file with name ‘exp.mat’. Then
load this file from Matlab. Check the number of samples obtained and plot
them. Compare this plot with the scope plot.
3.
Generate the “Simple Model” given in the lab manual by only changing the
Integrator block with Discrete-Time Integrator block.
4.
What is the difference between the sources and sink?
5.
What is the difference between the continuous and discrete states?
6. What are the purposes of these blocks:
sin
mux
scope
ramp
step
42 | P a g e
Download