Académique Documents
Professionnel Documents
Culture Documents
ENGINEERING LABORATORY
EX -406
Electrical Engineering
Simulation Lab-1
-
CHAMELIDEVI SCHOOL OF
ENGINEERING,
1
CHAMELIDEVI GROUP OF
INSTITUTIONS,
INDORE
Fourth SEMESTER
EX-406
Electrical Engineering Simulation Lab-1
List of Experiments
1.
2.
3.
4.
INDEX
Sl.
No.
Expt.
No.
Date of
Conduction
Date of
Submission
Signature
of Staff
Experiment 1
AIM:
Introduction to Modelling and Simulation
WHAT IS MODELING?
Modeling is the process of producing a model; a model is a representation of the
construction and working of some system of interest.
One purpose of a model is to enable the analyst to predict the effect of changes to the
system.
On the one hand, a model should be a close approximation to the real system and
incorporate most of its salient features. On the other hand, it should not be so complex that
it is impossible to understand and experiment with it. A good model is a judicious tradeoff
between realism and simplicity.
Simulation practitioners recommend increasing the complexity of a model iteratively. An
important issue in modeling is model validity. Model validation techniques include
simulating the model under known input conditions and comparing model output with
system output.
Generally, a model intended for a simulation study is a mathematical model developed with
the help of simulation software.
Mathematical model classifications include deterministic (input and output variables are
fixed values) or stochastic (at least one of the input or output variables is probabilistic);
static (time is not taken into account) or dynamic (time-varying interactions among
variables are taken into account).
Typically, simulation models are stochastic and dynamic.
WHAT IS SIMULATION?
A simulation of a system is the operation of a model of the system. The model can be
reconfigured and experimented with; usually, this is impossible, too expensive or
impractical to do in the system it represents.
The operation of the model can be studied, and hence, properties concerning the behavior
of the actual system or its subsystem can be inferred. In its broadest sense, simulation is a
tool to evaluate the performance of a system, existing or proposed, under different
configurations of interest and over long periods of real time.
Simulation is used before an existing system is altered or a new system built, to reduce the
chances of failure to meet specifications, to eliminate unforeseen bottlenecks, to prevent
under or over-utilization of resources, and to optimize system performance.
Figure 1 is a schematic of a simulation study. The iterative nature of the process is
indicated by the system under study becoming the altered system which then becomes the
system under study and the cycle repeats.
In a simulation study, human decision making is required at all stages, namely, model
development, experiment design, output analysis, conclusion formulation, and making
decisions to alter the system under study. The only stage where human intervention is not
required is the running of the simulations, which most simulation software packages
perform efficiently.
The important point is that powerful simulation software is merely a hygiene factor - its
absence can hurt a simulation study but its presence will not ensure success. Experienced
5
problem formulators and simulation modelers and analysts are indispensable for a
successful simulation study.
Step 3. Collect and process real system data. Collect data on system specifications,
input variables, as well as performance of the existing system. Identify sources of
randomness in the system, i.e., the stochastic input variables. Select an appropriate input
probability distribution for each stochastic input variable and estimate corresponding
parameter(s).
Step 4. Formulate and develop a model. Develop schematics and network diagrams of the
system (How do entities flow through the system?). Translate these conceptual models to
simulation software acceptable form. Verify that the simulation model executes as intended.
Verification techniques include traces, varying input parameters over their acceptable range
and checking the output, substituting constants for random variables and manually
checking results, and animation.
Step 5. Validate the model. Compare the model's performance under known conditions with
the performance of the real system. Perform statistical inference tests and get the model
examined by system experts. For major simulation studies, experienced consultants
advocate a structured presentation of the model by the simulation analyst(s) before an
audience of management and system experts.
Step 6. Document model for future use. Document objectives, assumptions and input
variables in detail.
Step 7. Select appropriate experimental design. Select a performance measure, a few input
variables that are likely to influence it, and the levels of each input variable. When the
number of possible configurations is large and the simulation model is complex, common
second-order design classes should be considered.
Step 8. Establish experimental conditions for runs. Address the question of obtaining
accurate information and the most information from each run. Determine if the system is
stationary (performance measure does not change over time) or non-stationary
(performance measure changes over time). Generally, in stationary systems, steady-state
7
behavior of the response variable is of interest. Alternately, use common random numbers
to compare alternative configurations by using a separate random number stream for each
sampling process in a configuration. Identify output data most likely to be correlated.
Step 9. Perform simulation runs. Perform runs according to steps 7-8 above.
Step 10. Interpret and present results. Compute numerical estimates (e.g., mean, confidence
intervals) of the desired performance measure for each configuration of interest. To obtain
confidence intervals for the mean of auto-correlated data, the technique of batch means can
be used. In batch means, original contiguous data set from a run is replaced with a smaller
data set containing the means of contiguous batches of original observations.
The assumption that batch means are independent may not always be true; increasing total
sample size and increasing the batch length may help. Test hypotheses about system
performance. Construct graphical displays (e.g., pie charts, histograms) of the output data.
Document results and conclusions.
Step 11. Recommend further course of action. This may include further experiments to
increase the precision and reduce the bias of estimators, to perform sensitivity analyses, etc.
SUITABLE
FOR
10
Develop well designed and robust systems and reduce system development
time.
11
13
Experiment 2
AIM:
Generation of Basic signals on Matlab
(i)
To procure sufficient knowledge in MATLAB to solve the power system
Problems.
(ii)
SOFTWARE REQUIRED
(i)
1.
MATLAB
INTRODUCTION TO MATLAB
MATLAB is a widely used tool in electrical engineering community. It can be used for
simple mathematical manipulation with matrices for understanding and teaching
basic
14
mathematical and engineering concepts and even for studying and simulating actual power system
and electrical system in general. The original concept of a small and handy tool has evolved to
become an engineering work house. It is now accepted that MATLAB and its numerous tool boxes
replace and/or enhance the usage of traditional simulation tool for advanced engineering
applications.
Engineering personnel responsible for studies of electrical power system, control system
and power electronics circuits will benefit from the MATLAB. To expertise in Electrical System
Simulation one should have a basic understanding of electric circuits, power system and power
electronics.
1.2.
To open the MATLAB applications double click the Matlab icon on the desktop. This will
open the MATLAB window space with Matlab prompt as shown in the fig.1.
These M-files of commands must be given the file extension of .m. However M-files are
not limited to being a series of commands that you dont want to type at the MATLAB window,
they can also be used to create user defined function. It turns out that a MATLAB tool box is
usually nothing more than a grouping of M-files that someone created to perform a special type of
analysis like control system design and power system analysis. Any of the matlab commands (eg:
sqrt) is really an M-file.
One of the more generally useful matlab tool boxes is simulink a drag and-drop dynamic
system simulation environment. This will be used extensively in laboratory, forming the heart of
the computer aided control system design (CACSD) methodology that is used.
>>simulink
At the matlab prompt type simulink and brings up the Simulink Library Browser. Each of
the items in the Simulink Library Browser are the top level of a hierarchy of palette of elements
that you can add to a simulink model of your own creation. At this time expand the simulink
pallete as it contains the majority of the elements you will use in this course. Simulink has built
into it a variety of integration algorithm for integrating the dynamic equations. You can place the
dynamic equations of your system into simulink in four ways.
1 Using integrators
1. Using transfer functions.
2. Using state space equations.
3. Using S- functions (the most versatile approach)
Once you have the dynamics in place you can apply inputs from the sources palettes and
look at the results in the sinks palette.
Finally the most important MATLAB features are its help. At the MATLAB Prompt
simply typing helpdesk gives you access to searchable help as well as all the MATLAB manuals.
>>helpdesk
To get the details about the command name sqrt, just type
>>help sqrt
Where sqrt is the command name and you will get pretty good description in the MATLAB
window as follows.
/SQRT Square root.
SQRT(X) is the square root of the elements of X. Complex
results are produced if X is not positive.
See also SQRTM.
Overloaded methods
help sym/sqrt.m
1.3
MATLAB WORKSPACE
The workspace is the window where you execute MATLAB commands (Ref. figure-1). The
best way to probe the workspace is to type whos. This command shows you all the variables that
16
are currently in workspace. You should always change working directory to an appropriate
location under your user name.
Another useful workspace-like command is
>>clear all
It eliminates all the variables in your workspace. For example start MATLAB and execute
the following sequence of commands
>>a=2;
>>b=5;
>>whos
>>clear all
The first two commands loaded the two variables a and b to the workspace and assigned
value of 2 and 5 respectively. The clear all command clear the variables available in the work
space. The arrow keys are real handy in MATLAB. When typing in long expression at the
command line, the up arrow scrolls through previous commands and down arrow advances the
other direction. Instead of retyping a previously entered command just hit the up arrow until you
find it. If you need to change it slightly the other arrows let you position the cursor anywhere.
Finally any DOS command can be entered in MATLAB as long as it is preceded by any
exclamination mark.
>>!dir
1.4
MATLAB Data Types
The most distinguishing aspect of MATLAB is that it allows the user to manipulate vectors
(like 5+j8) and matrices with the same ease as manipulating scalars (like5,8). Before diving into
the actual commands everybody must spend a few moments reviewing the main MATLAB data
types. The three most common data types you may see are,
1) arrays 2) strings
3) structures.
As for as MATLAB is concerned a scalar is also a 1 x 1 array. For example clear your
workspace and execute the commands.
>>a=4.2:
>>A=[1 4;6 3];
>>whos
Two things should be evident. First MATLAB distinguishes the case of a variable name
and that both a and A are considered arrays. Now lets look at the content of A and a.
>>a
>>A
Again two things are important from this example. First anybody can examine the
contents of any variables simply by typing its name at the MATLAB prompt. Second, when typing
in a matrix space between elements separate columns, whereas semicolon separate rows. For
practice create the matrix in your workspace by typing it in all the MATLAB prompt.
>>B= [3 0 -1; 4 4 2;7 2 11];
(use semicolon(;) to represent the end of a row)
>>B
17
Arrays can be constructed automatically. For instance to create a time vector where the
time points start at 0 seconds and go up to 5 seconds by increments of 0.001
>>mytime =0:0.001:5;
Automatic construction of arrays of all ones can also be created as follows,
>>myone=ones (3,2)
Note:
Any MATLAB command can be terminated by a semicolon, which suppressed any
echo information to the screen.
1.5
scalars.
Example:
>>clear all
>> a=4;
>> A=7;
>>alpha=a+A;
>>b= [1 2; 3 4];
>>B= [6 5; 3 1];
>>beta=b+B
Of course cannot violate the rules of matrix algebra which can be understood from the following
example.
>>clear all
>>b=[1 2;3 4];
>>B=[6 7];
>>beta=b*B
In contrast to matrix algebra rules, the need may arise to divide, multiply, raise to a
power one vector by another, element by element. The typical scalar commands are used for this
+,-,/, *, ^ except you put a . in front of the scalar command. That is, if you need to multiply the
elements of [1 2 3 4] by [6 7 8 9], just type...
>>[1 2 3 4].*[6 7 8 9]
1.6
Conditional Statements
18
Looping :
1.7
>>for n=1:2:10
>>s=s+n^2
>>end
- Yields the sum of 1^2+3^2+5^2+7^2+9^2
PLOTTING
MATLABs potential in visualizing data is pretty amazing. One of the nice features is that
with the simplest of commands you can have quite a bit of capability.
Graphs can be plotted and can be saved in different formulas.
>>clear all
>>t=0:10:360;
>>y=sin (pi/180 * t);
To see a plot of y versus t simply type,
>>plot(t,y)
To add label, legend, grid and title use
>>xlabel (Time in sec);
>>ylabel (Voltage in volts)
>>title (Sinusoidal O/P);
>>legend (Signal);
The commands above provide the most plotting capability and represent several
shortcuts to the low-level approach to generating MATLAB plots, specifically the use of handle
graphics. The helpdesk provides access to a pdf manual on handle graphics for those really
interested in it.
1.8
Functions
As mentioned earlier, a M-file can be used to store a sequence of commands or a userdefined function. The commands and functions that comprise the new function must be put in a
file whose name defines the name of the new function, with a filename extension of '.m'.A function
is a generalized input/output device. That is you can give some input.(arguments) and provides
some output. MATLAB functions allow you much capability to expand MATLABs usefulness.
We will just touch on function here as you may find them beneficial later.
We will start by looking at the help on functions :
>>help function
We will create our own function that given an input matrix returns a vector containing the
admittance matrix(y) of given impedance matrix(z)
z=[5 2 4;
1 4 5]
19
To perform the same name the function admin and noted that admin must be
stored in a function M-file named admin.m. Using an editor, type the following commands and
save as admin.m.
admin.m :
function y = admin(z)
y = 1./z
return
Simply call the function admin from the workspace as follows,
>>z=[5 2 4;
1 4 5]
>>admin(z)
20
Experiment 3
AIM:
Generation of Basic signals on Matlab.
REQUIREMENT:
Matlab software.
THEORY :
Simple Waveforms
Frequency is the number of cycles per second and is measured in Hertz (Hz).
The general form of the sine wave we shall use (quite a lot of) is as follows:
y = A*sin(2n*Fw/Fs)
Where:
A is the amplitude of the wave,
21
PROGRAMS ON MATLAB
PROGRAM 1:
PERIOD 1 SIMPLE SINE WAVE
% Basic 1 period Simple Sine wave
i=0:0.2:2*pi;
y = sin(i);
figure(1)
plot(y);
Title(Simple 1 Period Sine Wave);
OUTPUT OF THE PROGRAM
PROGRAM 2:
SineWave Amplitude is -1 to +1.
To change amplitude multiply by some gain (amp):
% Now Change amplitude
amp = 2.0;
y = amp*sin(i);
figure(2)
plot(y);
title(Simple 1 Period Sine Wave Modified Amplitude);
OUTPUT OF THE PROGRAM :
22
2
1.5
1
0.5
0
-0.5
-1
-1.5
-2
10
15
20
25
PROGRAM 3:
% To plot n cycles of a waveform
ncyc = 2;
n=0:floor(ncyc*F_s/F_w);
y = amp*sin(2*pi*n*F_w/F_s);
figure(4)
plot(y);
title(N Cycle Duration Sine Wave);
OUTPUT OF THE PROGRAM
N Cycle Duration Sine Wave
5
4
3
2
1
0
-1
-2
-3
-4
-5
10
20
30
40
50
60
PROGRAM 4 :
% Cosine is same as Sine (except 90 degrees out of phase)
clear all
amp=2;
ncyc=1
23
30
35
F_s = 11025;
F_w = 440;
n=0:floor(ncyc*F_s/F_w);
yc = amp*cos(2*pi*n*F_w/F_s);
y = amp*sin(2*pi*n*F_w/F_s);
figure(5);
hold on
plot(yc,'b');
plot(y,'r');
title('Cos (Blue)/Sin (Red) Plot (Note Phase Difference)');
hold off;
OUTPUT OF THE PROGRAM:
Cos (Blue)/Sin (Red) Plot (Note Phase Difference)
2
1.5
1
0.5
0
-0.5
-1
-1.5
-2
10
15
24
20
25
30
Experiment 4
AIM:
Plot a sinusoidal Waveform (1 Peak & 1 rad/sec), Differentiate it & observe both the waveform on
scope
REQUIREMENT:
Matlab software.
THEORY:
Step1:
Open a new model. Open the simulink library browser. On clicking the same library a set of box
will appear. Click on the sine wave block and drag it to the model window to add a source in your
model.
Step2:
Save the model by .mdl extension.
Step 3:
Add more blocks as shown in table below.
Block
Location
Sine wave
Source
Derivative
Continous
Multiplexer
Commonly used blocks
Scope
Sink
Step 4:
Make a connection between blocks according to the required condition.
BLOCK DIAGRAM:
Step 5:
Edit the block parameter. To edit a particular block parameter double click on it a new box will
open. We can edit amplitude, frequency and phase.
Step 6:
Running simulation and viewing output. After making a model and adding parameters we can run
simulation in following way.
By play button.
Selecting start from simulation menu.
25
RESULT : WAVEFORM
26
Experiment 5
AIM:
Use Simulink to solve the following differential equation.
dy
=10 sint , y (0) =0
dt
REQUIREMENT:
Matlab software.
THEORY:
Step1:
Open a new model. Open the simulink library browser. On clicking the same library a set of box
will appear. Click on the sine wave block and drag it to the model window to add a source in your
model.
Step2:
Save the model by .mdl extension.
Step 3:
Add more blocks as shown in table below.
Block
Location
Sine wave
Source
Integrator
Continous
Gain
Commonly used blocks
Scope
Sink
Step 4:
Make a connection between blocks according to the required condition.
BLOCK DIAGRAM:
Step 5:
Edit the block parameter. To edit a particular block parameter double click on it a new box will
open. We can edit amplitude, frequency and phase.
Step 6:
Running simulation and viewing output. After making a model and adding parameters we can run
simulation in following way.
By play button.
Selecting start from simulation menu.
27
RESULT:
28
BLOCK DIAGRAM:
Step 5:
Edit the block parameter. To edit a particular block parameter double click on it a new box will
open. We can edit amplitude, frequency and phase.
Step 6:
Running simulation and viewing output. After making a model and adding parameters we can run
simulation in following way.
By play button.
Selecting start from simulation menu.
RESULT:
29
Experiment 6
AIM:
Develop a simulink model to generate sine & cosine waveform of magnitude 5 and frequency 50
Hz using sine & cosine trigonometric function
REQUIREMENT:
Matlab software.
THEORY:
Step1:
Open a new model. Open the simulink library browser. On clicking the same library a set of box
will appear. Click on the sine wave block and drag it to the model window to add a source in your
model.
Step2:
Save the model by .mdl extension.
Step 3:
Add more blocks as shown in table below.
Block
Location
Sine wave
Source
Cosine wave
Source
Multiplexer
Commonly used blocks
Constant
Commonly used blocks
Constant
Commonly used blocks
Constant
Commonly used blocks
Clock
Source
Product
Commonly used blocks
Gain
Commonly used blocks
Product
Commonly used blocks
Scope
Sink
Product
Commonly used blocks
Step 4:
Make a connection between blocks according to the required condition.
BLOCK DIAGRAM:
30
Step 5:
Edit the block parameter. To edit a particular block parameter double click on it a new box will
open. We can edit amplitude, frequency and phase.
Step 6:
Running simulation and viewing output. After making a model and adding parameters we can run
simulation in following way.
By play button.
Selecting start from simulation menu.
RESULT:
31
Experiment 7
AIM:
Introduction to simulink & study of various blocksets
THEORY:
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, we can
draw the models just as we would with pencil and paper.
Simulink includes a comprehensive block library of sinks, sources, linear and
nonlinear components, and connectors. We can also customize and create our own blocks Models
are hierarchical. This approach provides insight into how a model is organized and how its parts
interact. After define a model, & we 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. Using scopes and other display blocks, we can see the
simulation results while the simulation is running. In addition, we can change parameters and
immediately see what happens, for "what if" exploration. The simulation results can be put in the
MATLAB workspace for post processing and visualization. And because MATLAB and Simulink
are integrated, we can simulate, analyze, and revise our models in either environment at any point.
Now step by step will see the process.
STEP1How to Build 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.
32
To create the model, first type simulink in the MATLAB command window. On Microsoft
Windows, the Simulink Library Browser appears.
33
To create a new model, select Model from the new submenu of the Simulink library Windows File
menu. To create a new model on Windows, select the New Model button on the Library Browser's
toolbar.
To create this model, you will need to copy blocks into the model from the following
block libraries:
Sources library (the Sine Wave block)
Sinks library (the Scope block)
Continuous library (the Integrator block)
34
Simulink
Signals
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.
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. 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.) Simulink displays the Sources library window.
35
Now drag the Sine Wave block from the Sources window to your 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.
36
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
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.
Hold down the mouse button and move the cursor to the top input port of the Mux block.Notice
that the line is dashed while the mouse button is down and that the cursor shape changes to doublelined cross hairs as it approaches the Mux block.
37
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 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.
3. Release the mouse button. Simulink draws a line between the starting point and the Integrator
block's input port.
38
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. Keeping the Scope window open, set up
Simulink to run the simulation for 10 seconds. First, set the simulation parameters by choosing
Simulation Parameters from the Simulation menu. On the dialog box that appears, notice that the
Stop time is set to 10.0 (its default value).
Close the Simulation Parameters dialog box by clicking on the OK button. Simulink applies the
parameters and closes the dialog box. Choose Start from the Simulation menu and watch the traces
of the Scope block's input.
39
The simulation stops when it reaches the stop time specified in the Simulation Parameters dialog
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.
RESULTStudied simulation & its blockset
40