You are on page 1of 40

ELECTRICAL AND ELECTRONICS

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.

INTRODUCTION TO MODELLING AND SIMULATION


INTRODUCTION TO MATLAB.
GENERATION OF BASIC SIGNALS ON MATLAB.
PLOT A SINUSOIDAL WAVEFORM (1 PEAK & 1 RAD/SEC), DIFFERENTIATE IT &
OBSERVE BOTH THE WAVEFORM ON SCOPE
5. USE SIMULINK TO SOLVE THE FOLLOWING DIFFERENTIAL EQUATION.
6. DEVELOP A SIMULINK MODEL TO GENERATE SINE & COSINE WAVEFORM OF
MAGNITUDE 5 AND FREQUENCY 50 HZ USING SINE & COSINE
TRIGONOMETRIC FUNCTION
7. INTRODUCTION TO SIMULINK & STUDY OF VARIOUS BLOCKSETS

INDEX
Sl.
No.

Expt.
No.

Date of
Conduction

Name of the Experiment

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.

STEPS INVOLVED IN SIMULATION AND MODELING


Modeling The steps involved in developing a simulation model, designing a simulation
experiment, and performing simulation analysis are:
Step 1. Identify the problem.
Step 2. Formulate the problem.
Step 3. Collect and process real system data.
Step 4. Formulate and develop a model.
Step 5. Validate the model.
Step 6. Document model for future use.
Step 7. Select appropriate experimental design.
Step 8. Establish experimental conditions for runs.
6

Step 9. Perform simulation runs.


Step 10. Interpret and present results.

Step 11. Recommend further course of action

HOW TO DEVELOP A SIMULATION MODEL?


Simulation models consist of the following components: system entities, input variables,
performance measures, and functional relationships.
Almost all simulation software packages provide constructs to model each of the above
components. Modeling is arguably the most important part of a simulation study. Indeed, a
simulation study is as good as the simulation model.
Simulation modeling comprises the following steps:
Simulation Step 1. Identify the problem. Enumerate problems with an existing system.
Produce requirements for a proposed system.
Step 2. Formulate the problem. Select the bounds of the system, the problem or a part
thereof, to be studied. Define overall objective of the study and a few specific issues to be
addressed. Define performance measures - quantitative criteria on the basis of which
different system configurations will be compared and ranked. Identify, briefly at this stage,
the configurations of interest and formulate hypotheses about system performance. Decide
the time frame of the study. Identify the end user of the simulation model. Problems must
be formulated as precisely as possible.

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.

HOW TO DESIGN A SIMULATION EXPERIMENT?


A simulation experiment is a test or a series of tests in which meaningful changes are made
to the input variables of a simulation model so that we may observe and identify the
reasons for changes in the performance measures.
The number of experiments in a simulation study is greater than or equal to the number of
questions being asked about the model (e.g., Is there a significant difference between the
mean delay in communication networks A and B?, Which network has the least delay: A,
B, or C? How will a new routing algorithm affect the performance of network B?).
Design of a simulation experiment involves answering the question: what data need to be
obtained, in what form, and how much? The following steps illustrate the process of
designing a simulation experiment.
Most simulation packages provide run statistics (mean, standard deviation, minimum value,
maximum value) on the performance measures, e.g., wait time (non-time persistent
statistic), inventory on hand (time persistent statistic).
Notwithstanding the facts that there are no data collection errors in simulation, the
underlying model is fully known, and replications and configurations are user controlled,
simulation results are difficult to interpret.
An observation may be due to system characteristics or just a random occurrence.
Normally, statistical inference can assess the significance of an observed phenomenon, but
most statistical inference techniques assume independent, Most types of simulation data are
autocorrelated, and hence, do not satisfy this assumption. Analysis of simulation output
data consists of the following steps.
HOW TO PERFORM SIMULATION ANALYSIS?

Step 1. Identify the problem


Step 2. Formulate the problem
Step 3. Collect and process real system data
Step 4. Formulate and develop a model
Step 5. Validate the model
Step 6. Document model for future use
Step 7. Select appropriate experimental design
Step 8. Establish experimental conditions for runs
8

Step 9. Perform simulation runs


Step 10. Interpret and present results
Step 11. Recommend further course of action
WHAT
MAKES
A
PROBLEM
SIMULATION MODELING AND ANALYSIS?

SUITABLE

FOR

In general, whenever there is a need to model and analyze randomness in a system,


simulation is the tool of choice. More specifically, situations in which simulation modeling
and analysis is used include the following:
It is impossible or extremely expensive to observe certain processes in the real
world,
Problems in which mathematical model can be formulated but analytic solutions are
either impossible or too complicated,
It is impossible or extremely expensive to validate the mathematical model
describing the system, e.g., due to insufficient data.
Applications of simulation abound in the areas of government, defense, computer and
communication systems, manufacturing, transportation (air traffic control), health care, ecology
and environment, sociological and behavioral studies, biosciences, epidemiology, services (bank
teller scheduling), economics and business analysis.
HOW TO SELECT SIMULATION SOFTWARE?
Although a simulation model can be built using general purpose programming languages
which are familiar to the analyst, available over a wide variety of platforms, and less
expensive, most simulation studies today are implemented using a simulation package.
The advantages are reduced programming requirements; natural framework for simulation
modeling; conceptual guidance; automated gathering of statistics; graphic symbolism for
communication; animation; and increasingly, flexibility to change the model.
There are hundreds of simulation products on the market, many with price tags. Naturally,
the question of how to select the best simulation software for an application arises. Metrics
for evaluation include modeling flexibility, ease of use, modeling structure (hierarchical v/s
flat; object-oriented v/s nested), code reusability, graphic user interface, animation,
dynamic business graphics, hardware and software requirements, statistical capabilities,
output reports and graphical plots, customer support, and documentation.
The two types of simulation packages are simulation languages and application-oriented
simulators (Table 2).
Simulation languages offer more flexibility than the application-oriented simulators.
On the other hand, languages require varying amounts of programming expertise.
Application-oriented simulators are easier to learn and have modeling constructs closely
related to the application.
Most simulation packages incorporate animation which is excellent for communication and
can be used to debug the simulation program; a "correct looking" animation, however, is
not a guarantee of a valid model. More importantly, animation is not a substitute for output
analysis.

10

BENEFITS OF SIMULATION MODELING AND ANALYSIS


According to practitioners, simulation modeling and analysis is one of the most frequently
used operations research techniques. When used judiciously, simulation modeling and
analysis makes it possible to:
Obtain a better understanding of the system by developing a mathematical model of
a system of interest, and observing the system's operation in detail over long periods
of time.
Test hypotheses about the system for feasibility.
Compress time to observe certain phenomena over long periods or expand time to
observe a complex phenomenon in detail.
Study the effects of certain informational, organizational, environmental and policy
changes on the operation of a system by altering the system's model; this can be
done without disrupting the real system and significantly reduces the risk of
experimenting with the real system.
Experiment with new/unknown situations about which only weak information is
available.
Identify the "driving" variables - ones that performance measures are most sensitive
to - and the inter-relationships among them.
Identify bottlenecks in the flow of entities (material, people, etc.) or information.
Use multiple performance metrics for analyzing system configurations.
Employ a systems approach to problem solving.

Develop well designed and robust systems and reduce system development
time.

11

WHAT ARE SOME PITFALLS TO GUARD AGAINST IN SIMULATION?


Simulation can be a time consuming and complex exercise, from modeling through output
analysis that necessitates the involvement of resident experts and decision makers in the
entire process. Following is a checklist of pitfalls to guard against.
Unclear objective.
Using simulation when an analytic solution is appropriate.
Invalid model.
Simulation model too complex or too simple.
Erroneous assumptions.
Undocumented assumptions. This is extremely important and it is strongly
suggested that assumptions made at each stage of the simulation modeling and
analysis exercise be documented thoroughly.
Using the wrong input probability distribution.
Replacing a distribution (stochastic) by its mean (deterministic).
Using the wrong performance measure.
Bugs in the simulation program.
Using standard statistical formulas that assume independence in simulation output
analysis.
Initial bias in output data.
Making one simulation run for a configuration.
Poor schedule and budget planning.
Poor communication among the personnel involved in the simulation study.
References
Banks, J., J. S. Carson, II, and B. L. Nelson. 1996. Discrete-Event System Simulation,
Second Edition, Prentice Hall.
Bratley, P., B. L. Fox, and L. E. Schrage. 1987. A Guide to Simulation, Second Edition,
Springer-Verlag.
Fishwick, P. A. 1995. Simulation Model Design and Execution: Building Digital Worlds,
Prentice-Hall.
Freund, J. E. 1992. Mathematical Statistics, Fifth Edition, Prentice-Hall.
Hogg, R. V., and A. T. Craig. 1995. Introduction to Mathematical Statistics, Fifth Edition,
Prentice-Hall.
Kleijnen, J. P. C. 1987. Statistical Tools for Simulation Practitioners, Marcel Dekker, New
York.
Law, A. M., and W. D. Kelton. 1991. Simulation Modeling and Analysis, Second Edition,
McGraw-Hill.
Law, A. M., and M. G. McComas. 1991. Secrets of Successful Simulation Studies,
Proceedings of the 1991 Winter Simulation Conference, ed. J. M. Charnes, D. M. Morrice,
D. T. Brunner, and J. J.
Swain, 21-27. Institute of Electrical and Electronics Engineers, Piscataway, New Jersey.
Maria, A., and L. Zhang. 1997. Probability Distributions, Version 1.0, July 1997,
Monograph, Department of Systems Science and Industrial Engineering, SUNY at
Binghamton, Binghamton, NY 13902.
Montgomery, D. C. 1997. Design and Analysis of Experiments, Third Edition, John Wiley.
Naylor, T. H., J. L. Balintfy, D. S. Burdick, and K. Chu. 1966. Computer Simulation
Techniques, John Wiley.
Nelson, B. L. 1995. Stochastic Modeling: Analysis and Simulation, McGraw-Hill.
12

13

Experiment 2
AIM:
Generation of Basic signals on Matlab
(i)
To procure sufficient knowledge in MATLAB to solve the power system
Problems.
(ii)

To write a MATLAB program.

SOFTWARE REQUIRED
(i)
1.

MATLAB

INTRODUCTION TO MATLAB

MATLAB is a high performance language for technical computing. It integrates


computation, visualization and programming in an easy-to-use environment where problems and
solutions are expressed in familiar mathematical notation.
MATLAB is numeric computation software for engineering and scientific calculations.
MATLAB is primary tool for matrix computations. MATLAB is being used to simulate random
process, power system, control system and communication theory.
MATLAB comprising lot of optional tool boxes and block set like control system,
optimization, and power system and so on.
1.1.

TYPICAL USES INCLUDE


Math and computation.
Algorithm development.
Modeling, simulation and prototype.
Data analysis, exploration and Visualization.
Scientific and engineering graphics.
Application development, including graphical user interface building.

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.

GETTING STARTED WITH MATLAB

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.

Fig-1: MATLAB window space


To quit from MATLAB type
>> quit
(Or)
>>exit
To select the (default) current directory click ON the icon [] and browse for the folder
named D:\SIMULAB\xxx, where xxx represents roll number of the individual candidate in
which a folder should be created already.
When you start MATLAB you are presented with a window from which you can enter
commands interactively. Alternatively, you can put your commands in an M- file and execute it at
the MATLAB prompt. In practice you will probably do a little of both. One good approach is to
incrementally create your file of commands by first executing them.
M-files can be classified into following 2 categories,
Script M-files Main file contains commands and from which functions can also be called
.
Function M-files Function file that contains function command at the first line of the M-file.
M-files to be created by you should be placed in your default directory. The M-files
developed can be loaded into the work space by just typing the M-file name.
To load and run a M-file named ybus.m in the workspace.
>>ybus
15

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

Scalar versus Array Mathematical Operation


Since MATLAB treats everything as an array, you can add matrices as easily as

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

Like most Programming languages, MATLAB supports a variety of conditional statements


and looping statements. To explore these simply type
>>help if
>>help for
>>help while
Example :
>>if z=0
>>y=0
>>else
>>y=1/z
>>end

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]

as input, the output would be,

y=[0.2 0.5 0.25;


1 0.25 0.2] which is the reciprocal of each elements.

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)

The output will be,


ans = 0.2 0.5 0.25
1
0.25 0.2
Otherwise the same function can be called for any times from any script file provided the function
M-file is available in the current directory.
With this introduction anybody can start programming in MATLAB and can be
updated themselves by using various commands and functions available. Concerned with the
Power System Simulation Laboratory, initially solve the Power System Problems manually, list
the expressions used in the problem and then build your own MATLAB program or function.

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).

Wavelength is inversely proportional to frequency i.e. Wavelength varies as 1/Frequency

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,

Fw is the frequency of the wave,

Fs is the sample frequency,

n is the sample index.

MATLAB function: sin() usedworks in radians

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

Simple 1 Period Sine Wave Modified Amplitude

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

RESULTBasic signals are generated in MATLAB

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

Hence the response is studied.

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:

Hence the response is studied.


EXAMPLES :
dy
=10 y + f (t) , where f(t)=2sin 4t & initial condition y(0)=1
dt
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
Sum
Commonly used blocks
Step 4:
Make a connection between blocks according to the required condition.

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

Hence the response is studied.

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

Hence the response is studied.

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.

Simulink opens a new model window.

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

& Systems library (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.

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

You might also like