You are on page 1of 184

Basic Simulation Lab

Department of ECE

Geethanjali
College of Engineering & Technology
Cheeryal(V),R.R(Dist)

Basic Simulation Lab


ECE II Year - I semester
[2015 -2016]
Department of Electronics and Communication Engineering
Geethanjali College of Engineering & Technology
Cheeryal (V), R.R.(Dist)

In-charge
Mr.R.Odaiah

HOD-ECE
Prof.

Assoc. Professor

Geethanjali College of Engineering & Technology

Page 0

Basic Simulation Lab

Department of ECE

BASIC SIMULATION LAB


CONTENTS
S.No
1.
2.

3.

4.
5.
6.
7.
8.

9.
10.
11.
12.

13.
14.
15.
16.
17.
18.

LIST OF EXPERIMENTS:

a) Introduction,
b) Basic operations on matrices.
Generation on various signals and Sequences
(periodic and aperiodic), such as unit impulse, unit step,
square, sawtooth, triangular, sinusoidal, ramp, sinc.
Operations on signals and sequences such as addition,
multiplication, scaling, shifting, folding, computation of
energy and average power.
Finding the even and odd parts of signal/sequence
and real and imaginary part of signal.
Convolution between signals and sequences.
Auto correlation and cross correlation between signals
Verification of linearity and time invariance
properties of a given continuous /discrete system and sequences.
Computation of unit sample, unit step and sinusoidal
response of the given LTI system and verifying its
physical Realizability and stability properties.
Gibbs phenomenon.
Finding the Fourier transform of a given Signal and plotting
its magnitude and phase spectrum.
Waveform synthesis using Laplace Transform.
Locating the zeros and poles and plotting the
pole zero maps in s-plane and z-plane for the given
transfer function.
Generation of Gaussian Noise(real and complex),
computation of its mean,
Sampling theorem verification .
Removal of noise by auto correlation/cross correlation.
Extraction of periodic signal masked by noise
using correlation.
Verification of Weiner-Khinchine relations
Checking a random process for stationarity in wide sense.

Geethanjali College of Engineering & Technology

Page No
08
16
22

31

38
43
46
49
53

55
56
59
62

64
66
71
75
78
80

Page 1

Basic Simulation Lab

Department of ECE

CYCLE I
1. Introduction about MATLAB/Scilab. Basic operations on Matrices.
2. Generation on various signals and Sequences
(Periodic and a periodic), such as unit impulse, unit step,
Square, saw tooth, triangular, sinusoidal, ramp, sinc.
3. Operations on signals and sequences such as addition,
Multiplication, scaling, shifting, folding, computation of
Energy and average power.
4. Finding the Even and Odd parts of signal/sequence
And real and imaginary part of signal.
5. Convolution between signals and sequences.
6. Auto correlation and cross correlation between signals and sequences.
7. Verification of linearity and time invariance properties of a given
Continuous /discrete system.
8. Computation of unit sample, unit step and sinusoidal
Response of the given LTI system and verifying its physical Realizability
and stability properties.
9 . Gibbs phenomenon.
10. Finding the Fourier transform of a given Signal and plotting its
magnitude and phase spectrum.
CYCLE II
11. Waveform synthesis using Laplace Transform.
12. Locating the zeros and poles and plotting the pole zero maps in
S-plane and z-plane for the given transfer function.
13. Generation of Gaussian Noise (real and complex), computation of
its mean, M.S value and its Skew, Kurtosis and PSD, Probability Distribution
Function.
14. Sampling theorem verification.
15. Removal of noise by auto correlation/cross correlation.
16. Extraction of periodic signal masked by noise using Correlation.
17. Verification of Weiner-Khinchine relations.
18. Checking a random process for stationarity in wide sense.

Geethanjali College of Engineering & Technology

Page 2

Basic Simulation Lab

Department of ECE

II . Additional Experiments:
19. To find the mean and variance of discrete random variable.
20. To find a moment generating function of a discrete random variable.
III . Design experiments:
21. To Design Half wave rectifier
22. To Design Zener break down characteristics
IV . Open experiments:
23. Implementation of Decimation Process.
24. Implementation of Interpolation Process.

Geethanjali College of Engineering & Technology

Page 3

Basic Simulation Lab

Department of ECE

GEETHANJALICOLLEGEOFENGINEERINGANDECHNOLOGY
DEPARTMENTOFElectronicsandCommunicationEngineering
(NameoftheLAB):BasicSimulationLab
Programme:UG
Branch:
ECE
VersionNo:03
Year:
II
Updatedon:10/06/2015
Semester:
I
No.of pages:86
Classificationstatus(Unrestricted/Restricted)
DistributionList:
Preparedby:
1)Name :Dr.P.SriHari
2)Sign :
3)Design:Professor
4)Date :01062015
Verifiedby:
1)Name:L.Kavya
2)Sign:
3)Design:
Date:07/07/2014

1)Name:
2)Sign:
3)Design:Assoc.Prof
4)Date
:30/06/2014
*ForQ.COnly:
1) Name:S.Vijayalakshmi
2) Sign:
3) Design:

4)Date:07/08/2014
Approved By: 1)Name:Dr.P.SriHari
2)Designation:HODECE

3)Sign:
4)Date:

Geethanjali College of Engineering & Technology

Page 4

Basic Simulation Lab

Department of ECE

ECE DEPARTMENT
Vision of the Department
To impart quality technical education in Electronics and Communication Engineering
emphasizing analysis, design/synthesis and evaluation of hardware/embedded software
using various Electronic Design Automation (EDA) tools with accent on creativity,
innovation and research thereby producing competent engineers who can meet global
challenges with societal commitment.
Mission of the Department
i. To impart quality education in fundamentals of

basic sciences, mathematics,

electronics and communication engineering through innovative teaching-learning


processes.
ii. To facilitate Graduates define, design, and solve engineering problems in the field of
Electronics and Communication Engineering using various Electronic Design
Automation (EDA) tools.
iii. To encourage research culture among faculty and students thereby facilitating them to
be creative and innovative through constant interaction with R & D organizations and
Industry.
iv. To inculcate teamwork, imbibe leadership qualities, professional ethics and social
responsibilities in students and faculty.
Program Educational Objectives of B. Tech (ECE) Program:
I.

To prepare students with excellent comprehension of basic sciences, mathematics


and engineering subjects facilitating them to gain employment or pursue

II.

postgraduate studies with an appreciation for lifelong learning.


To train students with problem solving capabilities such as analysis and design
with adequate practical skills wherein they demonstrate creativity and innovation
that would enable them to develop state of the art equipment and technologies of

III.

multidisciplinary nature for societal development.


To inculcate positive attitude, professional ethics, effective communication and
interpersonal skills which would facilitate them to succeed in the chosen
profession exhibiting creativity and innovation through research and development
both as team member and as well as leader.

Geethanjali College of Engineering & Technology

Page 5

Basic Simulation Lab

Department of ECE

Program Outcomes of B.Tech ECE Program:


1. An ability to apply knowledge of Mathematics, Science, and Engineering to solve
complex engineering problems of Electronics and Communication Engineering
systems.
2. An ability to model, simulate and design Electronics and Communication
Engineering systems, conduct experiments, as well as analyze and interpret data
and prepare a report with conclusions.
3. An ability to design an Electronics and Communication Engineering system,
component, or process to meet desired needs within the realistic constraints such
as economic, environmental, social, political, ethical, health and safety,
manufacturability and sustainability.
4. An ability to function on multidisciplinary teams involving interpersonal skills.
5. An ability to identify, formulate and solve engineering problems of
multidisciplinary nature.
6. An understanding of professional and ethical responsibilities involved in the
practice of Electronics and Communication Engineering profession.
7. An ability to communicate effectively with a range of audience on complex
engineering problems of multidisciplinary nature both in oral and written form.
8. The broad education necessary to understand the impact of engineering solutions
in a global, economic, environmental and societal context.
9. A recognition of the need for, and an ability to engage in life-long learning and
acquire the capability for the same.
10. A knowledge of contemporary issues involved in the practice of Electronics and
Communication Engineering profession
11. An ability to use the techniques, skills and modern engineering tools necessary for
engineering practice.
12. An ability to use modern Electronic Design Automation (EDA) tools, software
and electronic equipment to analyze, synthesize and evaluate Electronics and
Communication Engineering systems for multidisciplinary tasks.
13. Apply engineering and project management principles to one's own work and also
to manage projects of multidisciplinary nature.

INSTRUCTIONS TO THE STUDENTS :


1) Attend Laboratory in-time with formal dress and ID Card.
2) Must come with completed observation and record.
3) Cell-Phones are strictly prohibited in the laboratory.
4) Ready for viva-voice of the completed experiments.
Geethanjali College of Engineering & Technology

Page 6

Basic Simulation Lab

Department of ECE

5) Must take signature of lab-in charge on observation, after the completion of


experiment on the same day.
6) Completed records must sign with lab-in charge within six working days.
Programme Educational Objectives of ECE Programme:
PEO 1. Graduates will excel in professional career and/or higher education by
acquiring
knowledge
in Mathematics, Science, Engineering principles and
Computational skills.
PEO 2. Graduates will analyze real life problems, design Electronic systems
appropriate to the requirement that are technically sound, economically feasible and
socially acceptable in all signal processing application areas.
PEO 3.Graduates will exhibit professionalism, ethical attitude, communication skills,
team work in their profession, adopt to current trends by engaging in lifelong learning
and participate in Research & Development.
Programme Outcomes of ECE Programme:
PO 1. An ability to apply the knowledge of Mathematics, science and engineering in
Electronics and Communications.
PO 2. An ability to Analyze signals and develop programming skills, as well as analyze
& Interpret Data .
PO 3. An ability to develop a program or process to meet desired needs with in
realistic constraints such as economic, environmental, social, defense, health
and safety, manufacturability.
PO 4. An ability to identify different sampling rates such as multi- rate signal processing.
PO 5. An ability to Identify, Formulate & Solve problems in the areas of signal
Processing Applications in Electronics and Communication Engineering.
PO 6. An understanding of professional and ethical responsibility.
PO 7. An ability to communicate effectively with satellite communication systems.

OBJECTIVES AND OUT COMES:


1. Basic operations on matrices.
Objective: To generate basic matrix of the order n/n in MATLAB and perform basic
operations on matrices Using MATLAB Software.

Geethanjali College of Engineering & Technology

Page 7

Basic Simulation Lab

Department of ECE

Outcome: The Students will able to understand the process of generating various
Matrices and performing various operations such as addition, subtraction, multiplication
on Matrices using MATLAB/SCILAB
2. Generation on various signals and Sequences (Periodic and aperiodic),
Such as unit impulse, unit step, square, saw tooth, triangular, sinusoidal, ramp, sinc.
Objective: To generate different types of signals and Sequences Using MATLAB
Software.
Outcome: The Student able to understand how to draw different signals in MATLAB.
3. Operations on signals and sequences such as addition, Multiplication, scaling,
shifting, folding, computation of Energy and Average power.
Objective: To perform arithmetic operations different types of signals Using MATLAB
Software.
Outcome: The Student must be able to understand how to operate signals and how to use
signal operations using the properties
4. Finding the Even and Odd parts of signal/sequence and Real and imaginary part
of signal.
Objective: To generate even and odd parts of signals Using MATLAB Software.
Outcome: The Student must be able to understand how to draw even and odd signals.
5.

Convolution between signals and sequences.

Objective: To find the output with linear convolution operation Using MATLAB
Software.
Outcome: The Student must be able to understand how two signals are multiplied in time
domain and the same two signals are how convolved in frequency domain Using
MATLAB.
6. Auto correlation and cross correlation between signals and sequences.
Objective: To compute auto correlation and cross correlation between signals and
sequences Using MATLAB Software.
Outcome: The Student must be able to understand the similarity between two signals of
the same and different Using MATLAB.
7. Verification of linearity and time invariance properties of a given
Continuous /discrete system
Objective: To compute linearity and time invariance properties of a given continuous
/discrete system.
Geethanjali College of Engineering & Technology

Page 8

Basic Simulation Lab

Department of ECE

Outcome: The Student must be able to understand how to test a given signal linearity and
non linearity in MATLAB.
8. Computation of unit sample, unit step and sinusoidal response of the given LTI
system and verifying its physical reliability and stability properties.
Objective: To perform computation of LTI systems.
Outcome: The Student must be able to understand the realization LTI systems of basic
signals and sequences using MATLAB.
9. Gibbs phenomenon.
Objective: To verify the Gibbs Phenomenon.
Outcome: The Student must be able to understand application of Gibbs phenomenon
using MATLAB
10. Finding the Fourier transform of a given Signal and plotting its magnitude and
phase spectrum.
Objective: To find the Fourier transform of a given signal and plotting its magnitude and
phase spectrum
Outcome: The Student must be able to understand domain transformation from time to
frequency in imaginary i.e. w-plane using MATLAB.
11. Waveform synthesis using Laplace Transform.
Objective: To perform waveform synthesis using Laplace Transform of a given signal.
Outcome: The Student must be able to understand the time domain to frequency domain
in s-plan using MATLAB
12. Locating the zeros and poles and plotting the pole zero maps in s-plane and zplane for the given transfer function.
Objective: To plot the zeros and poles in s-plane and z-plane for the given transfer
function.
Outcome: The Student must be able to understand plotting and difference between s- and
z- plane plotting using MATLAB.
13. Generation of Gaussian Noise (real and complex), computation of its mean, M.S
value and its Skew, Kurtosis and PSD, Probability Distribution Function.
Objective: To analyze the Gaussian density and Distribution Functions.
Outcome: The Student must be able to understand the edge for single observed image
using sobel edge detection and canny edge is detected.
14. Sampling theorem verification.

Geethanjali College of Engineering & Technology

Page 9

Basic Simulation Lab

Department of ECE

Objective: To verify sampling theorem.


Outcome: The Student must be able to understand sampling rate changes and minimum
sampling rate using MATLAB.
15. Removal of noise by auto correlation/cross correlation.
Objective: Removal of Noise by auto correlation/cross correlation.
Outcome: The Student must be able to understand this experiment that the removal of
noise by auto correlation/cross correlation using MATLAB.
16. Extraction of periodic signal masked by noise using correlation.
Objective: To extract a periodic signal masked by noise using correlation.
Outcome: The Student must be able to understand the experiment that the Extraction of
periodic signal masked by noise using correlation using MATLAB.
17. Verification of Weiner-Khinchine relations.
Objective: To verify of Wiener Khinchine relation.
Outcome: The Student must be able to understand the Weiner-Khinchine Relation using
MATLAB.
18. Checking a random process for stationary in wide sense.
Objective: Checking a random process for stationary in wide sense.
Outcome: The Student must be able to understand the experiment of checking a random
process for stationary in wide sense using MATLAB.

INTRODUCTION
The tutorials are independent of the rest of the document. The primarily objective is to
help you learn quickly the first steps. The emphasis here is learning by doing. Therefore,
the best way to learn is by trying it yourself. Working through the examples will give you a
feel for the way that MATLAB operates. In this introduction we will describe how
MATLAB handles simple numerical expressions and mathematical formulas.
The name MATLAB stands for MATrix LABoratory. MATLAB was written
originally to provide easy access to matrix software developed by the LINPACK (linear

Geethanjali College of Engineering & Technology

Page 10

Basic Simulation Lab

Department of ECE

system package) and EISPACK (Eigen system package) projects.


MATLAB [1] is a high-performance language for technical computing. It integrates
computation, visualization and programming environment. Furthermore, MATLAB is a
modern programming language environment: it has sophisticated
data structures contains built-in editing and debugging tools , and supports object-oriented
programming These factors make MATLAB an excellent tool for teaching and research.
MATLAB has many advantages compared to conventional computer languages
(e.g., C, FORTRAN) for solving technical problems. MATLAB is an interactive system
whose basic data element is an array that does not require dimensioning. The software
package has been commercially available since 1984 and is now considered as a standard
tool at most universities and industries worldwide.
It has powerful built-in routines that enable a very wide variety of computations. It
also has easy to use graphics commands that make the visualization of results immediately
available. Specific applications are collected in packages referred to as
toolbox. There are toolboxes for signal processing, symbolic computation, control theory,
simulation, optimization, and several other fields of applied science and engineering.
BASIC FEATURES
As we mentioned earlier, the following tutorial lessons are designed to get you started
quickly in MATLAB. The lessons are intended to make you familiar with the basics of
We urge you to complete the exercises given at the end of each lesson.
A minimum MATLAB session
The goal of this minimum session (also called starting and exiting sessions) is to learn the
first steps:
How to log on
Invoke MATLAB
Do a few simple calculations
How to quit MATLAB

Starting MATLAB:
After logging into your account, you can enter MATLAB by double-clicking on the
MATLAB shortcut icon (MATLAB 7.0.4) on your Windows desktop. When you start
MATLAB, a special window called the MATLAB desktop appears. The desktop is a
window that contains other windows. The major tools within or accessible from the
desktop are:

The Command Window


The Command History
The Workspace
The Current Directory
The Help Browser

Geethanjali College of Engineering & Technology

Page 11

Basic Simulation Lab

Department of ECE

The Start button

Figure 1.1: The graphical interface to the MATLAB workspace


When MATLAB is started for the first time, the screen looks like the one that shown
in the Figure 1.1. This illustration also shows the default configuration of the MATLAB
desktop. You can customize the arrangement of tools and documents to suit your needs.

Geethanjali College of Engineering & Technology

Page 12

Basic Simulation Lab

Department of ECE

Now, we are interested in doing some simple calculations. We will assume that you have
sufficient understanding of your computer under which MATLAB is being run. You are
now faced with the MATLAB desktop on your computer, which contains the prompt (>>)
in the Command Window. Usually, there are 2 types of prompt:
>> for full version
EDU> for educational version

Note: To simplify the notation, we will use this prompt, >>, as a standard prompt sign,
though our MATLAB version is for educational purpose.
Using MATLAB as a calculator
As an example of a simple interactive calculation, just type the expression you want to
evaluate. Lets start at the very beginning. For example, lets suppose you want to calculate
the expression, 1 + 2 3. You type it at the prompt command (>>) as follows,
>> 1+2*3
ans = 7
You will have noticed that if you do not specify an output variable, MATLAB uses a
default variable ans, short for answer, to store the results of the current calculation. Note
that the variable ans is created (or overwritten, if it is already existed). To avoid this,
youmay assign a value to a variable or output argument name. For example
>> x = 1+2*3
x =7
will result in x being given the value 1 + 2*3=7. This variable name can always
be used to refer to the results of the previous computations. Therefore, computing 4
result in
>> 4*x
ans =28.0000
Before we conclude this minimum session, Table 1.1 gives the partial list of arithmetic
Operators.
Basic arithmetic operators
Symbol Operation Example
+ Addition
2+3
- Subtraction 2 - 3
* Multiplication 2*3
/ Division
2/3
3 Quitting MATLAB
To end your MATLAB session, type quit in the Command Window, or select File
MATLAB in the desktop main menu.

Geethanjali College of Engineering & Technology

Page 13

Basic Simulation Lab

Department of ECE

Getting started
After learning the minimum MATLAB session, we will now learn to use some additional
operations.
1 Creating MATLAB variables
MATLAB variables are created with an assignment statement. The syntax of variable
assignment is
variable name = a value (or an expression)
For example,
>> x = expression
where expression is a combination of numerical values, mathematical operators, variables,
and function calls. On other words, expression can involve:

manual entry
built-in functions
user-defined functions

Overwriting variable
Once a variable has been created, it can be reassigned. In addition, if you do not wish to
see the intermediate results, you can suppress the numerical output by putting a semicolon
(;) at the end of the line. Then the sequence of commands looks like this:
>> t = 5;
>> t = t+1
t =6
Error messages
If we enter an expression incorrectly, MATLAB will return an error message. For example,
in the following, we left out the multiplication sign, *, in the following expression
>> x = 10;
>> 5x
??? 5x
Error: Unexpected MATLAB expression
Geethanjali College of Engineering & Technology

Page 14

Basic Simulation Lab

Department of ECE

Making corrections
To make corrections, we can, of course retype the expressions. But if the expression is
lengthy, we make more mistakes by typing a second time. A previously typed command
can be recalled with the up-arrow key When the command is displayed at the command
prompt, it can be modified if needed and executed.
Controlling the hierarchy of operations or precedence
Lets consider the previous arithmetic operation, but now we will include
example, 1 + 23 will become (1 + 2) 3
>> (1+2)*3
ans =9
and, from previous example
>> 1+2*3
ans =7
By adding parentheses, these two expressions give di errant results: 9 and 7 The order in
which MATLAB performs arithmetic operations is exactly that taught
in high school algebra courses Exponentiations are done first, followed by multiplications
and
divisions, and finally by additions and subtractions. However, the standard order of
precedence of arithmetic operations can be changed by inserting parentheses. For
example, the result of 1 +23 is quite deferent than the similar expression with
parentheses (1+2) 3. The results are 7 and 9 respectively. Parentheses can always be used
to overrule priority and their use is recommended in some complex expressions to avoid
ambiguity.
Therefore, to make the evaluation of expressions unambiguous, MATLAB has established
a series of rules. The order in which the arithmetic operations are evaluated is given in
Table 1.2. MATLAB arithmetic operators obey the same precedence rules as those in
Hierarchy of arithmetic operations Precedence Mathematical operations
First The contents of all parentheses are evaluated first, starting from the innermost
parentheses and working outward Second All exponentials are evaluated, working from
left to right Third All multiplications and divisions are evaluated, working
from left to right Fourth All additions and subtractions are evaluated, starting
from left to rightmost computer programs. For operators of equal precedence, evaluation is
from left to right Now, consider another example:
?
?
?
In MATLAB, it becomes
>> 1/(2+3^2)+4/5*6/7
ans =0.7766.
or, if parentheses are missing,
Geethanjali College of Engineering & Technology

Page 15

Basic Simulation Lab

Department of ECE

>> 1/2+3^2+4/5*6/7
ans =10.1857.
So here what we get: two different results. Therefore, we want to emphasize the
importance of precedence rule in order to avoid ambiguity.
Controlling the appearance of floating point number
MATLAB by default displays only 4 decimals in the result of the calculations, for example
-163. 6667, as shown in above examples. However, MATLAB does numerical calculations
in double precision, which is 15 digits. The command format controls how the results of
computations are displayed. Here are some examples of the different formats together with
the resulting outputs
>> format short
>> x=-163.6667
If we want to see all 15 digits, we use the command format long
>> format long
>> x= -1.636666666666667e+002
To return to the standard format, enter format short, or simply format There are several
other formats. For more details, see the MATLAB documentation, or type help format
Note - Up to now, we have let MATLAB repeat everything that we enter at the prompt
(>>). Sometimes this is not quite useful, in particular when the output is pages en length.
To prevent MATLAB from echoing what we type, simply enter a semicolon (;) at the end
of the command. For example,
>> x=-163.6667;
and then ask about the value of x by typing,
>> x
x =-163.6667
Managing the workspace
The contents of the workspace persist between the executions of separate commands.
There-fore, it is possible for the results of one problem to have aneect on the next one. To
avoid this possibility, it is a good idea to issue a clear command at the start of each new
independent calculation
>> clear
The command clear or clear all removes all variables from the workspace. This
frees up system memory. In order to display a list of the variables currently in the memory
type
>> who
while, whos will give more details which include size, space allocation, and class of the
variables
Keeping track of your work session
Geethanjali College of Engineering & Technology

Page 16

Basic Simulation Lab

Department of ECE

It is possible to keep track of everything done during a MATLAB session with the
diary command.
>> diary
or give a name to a created file
>> diary Filename
where Filename could be any arbitrary name you choose
The function diary is useful if you want to save a complete MATLAB session. They
save all input and output as they appear in the MATLAB window. When you want to stop
the recording, enter diary off. If you want to start recording again, enter diary on. The file
that is created is a simple text file. It can be opened by an editor or a word processing
program and edited to remove extraneous material, or to add your comments. You can use
the function type to view the diary file or you can edit in a text editor or print. This
command is useful, for example in the process of preparing a homework or lab
submission.
Entering multiple statements per line
It is possible to enter multiple statements per line. Use commas (,) or semicolons (;) to
Enter more than one statement at once. Commas (,) allow multiple statements per line
Without suppressing output
>> a=7; b=cos(a), c=cash (a)
b =0.6570
c =548.3170
Miscellaneous commands
Here are few additional useful commands:
To clear the Command Window, type clc
To abort a MATLAB computation, type ctrl-c
To continue a line, type . . .
Getting help
To view the online documentation, select MATLAB Help from Help menu or MATLAB
Help directly in the Command Window. The preferred method is to use the Help Browser.
The Help Browser can be started by selecting the? icon from the desktop toolbar. On the
other hand, information about any command is available by typing
>> help Command
Another way to get help is to use the look for command. The look for commandeers
from the help command. The help command searches for an exact function name match,
while the look for command searches the quick summary information in each function for
a match. For example, suppose that we were looking for a function to take
Geethanjali College of Engineering & Technology

Page 17

Basic Simulation Lab

Department of ECE

the inverse of a matrix. Since MATLAB does not have a function named inverse, the
command help inverse will produce nothing. On the other hand, the command look for
inverse will produce detailed information, which includes the function of interest, inv
>> look for inverse
Note - At this particular time of our study, it is important to emphasize one main point.
Because MATLAB is a huge program; it is impossible to cover al l the details
of each function one by one. However, we will give you information how to get help. Here
are some examples
Use on-line help to request info on a specific function
>> help sqrt
In the current version (MATLAB version 7), the doc function opens the on-line version
of the help manual. This is very helpful for more complex commands
>> doc plot
Use look for to find functions by keywords. The general form is
>>lookfor Function Name

***Common Procedure to all Programs in MATLAB


1. Click on the MATLAB Icon on the desktop.
2. MATLAB window open .
3. Click on the FILE Menu on menu bar.
4. Click on NEW M-File from the file Menu.
5. An editor window open, start typing commands.
6. Now SAVE the file in directory.
7. Then Click on DEBUG from Menu bar and Click Run.

Geethanjali College of Engineering & Technology

Page 18

Basic Simulation Lab

Department of ECE

EXP.NO: 1
BASIC OPERATIONS ON MATRICES
Aim: To generate matrix and perform basic operation on matrices Using MATLAB
Software.
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
MATLAB on Matrices
//This Program explains about various One-Dimensional array/Matrix
//Operations:
//Creating a One-Dimensional Array/Vector:
//Creating a vector from a Known list of numbers:
A=input('enter the Matrix/Vector Elements')
enter the Matrix/Vector Elements
A = 1. 2. 3. 4.
//Creating a vector with constant spacing by specifying the first
//term, spacing and the last term:
m=input('enter the first term')
q=input('enter the spacing')
//Default value of q is 1
n=input('enter the last term')
B=[m:q:n]
Geethanjali College of Engineering & Technology

Page 19

Basic Simulation Lab

Department of ECE

enter the first term


m =2
enter the spacing
q = 0.1000
enter the last term
n =4
B =
column 1 to 12
2.

2.1

2.2

2.3

2.4

2.5

2.6

2.7

2.8

2.9

3.

3.1

column 13 to 21
3.2

3.3

3.4

3.5

3.6

3.7

3.8

3.9

4.

//Creating a vector with constant spacing by specifying the first and


the last terms, and the number of terms:
a=input('enter the first element')
b=input('enter the last element')
c=input('enter the number of elements')
C=linspace (a,b,c)
enter the first element
a =3.
enter the last element6
b =6.
enter the number of elements5
c =5.
C = 3. 3.75 4.5 5.25 6.
//creating an All Zero Vector
m=input('enter the number of terms in the vector')
D=zeros(1,m)
enter the number of terms in the vector
m =5.
D =0.
0.
0.
0.
0.
//creating a Vector consisting of all Ones
n=input('enter the number of terms in the vector')
E=ones(1,n)
Geethanjali College of Engineering & Technology

Page 20

Basic Simulation Lab

Department of ECE

enter the number of terms in the vector6


n =6.
E =1.
1.
1.
1.
1.
1.
//Measuring the size(number of elements) of the vector
A=[1 2 3 4]
l=length(A)
A =1.
2.
3.
4.
l = 4.
//Measuring the order of the vector
D=[1 1 1 1 1]
p=size(D)
D =1.
1.
1.
1.
1.
p =1.
5.
disp('The number of rows is')
The number of rows is
disp(p(1))
1.
disp('The number of columns is')
The number of columns is
disp(p(2))
5.
//Transpose of a Matrix
A=[1 2 3 4]
A1=A'
A=
1.
2.
3.
4.
A1 =
1.
2.
3.
4.

//Multiplying each element of the vector/Matrix with a constant


k=input('enter the value of the Multiplying Constant')
B=[3 4 5 6]

Geethanjali College of Engineering & Technology

Page 21

Basic Simulation Lab

Department of ECE

B1=k*B
k =3.
B =3.
4.
5.
6.
B1 =9. 12. 15. 18.
%The above Multiplication operation can be done also as follows:
B11=k.*B
//Finding the sum of elements of a Matrix
A=[1 2.1 3.3 4]
S=sum(A)
A =1. 2.1 3.3 4.
S =10.4
B =
1. 2. 3.
4. 5. 6.
7. 8. 9.
S1=sum(B)
S1 = 45.
//Finding the sum of each row and displaying in a column
S2=sum(B, 'c')
S2 =
6.
15.
24.
//Finding the sum of each column and displaying in a row
S3=sum(B, 'r')
S3 =
12. 15. 18.
//Finding the average of the elements of Matrix
B=[2 3 4 5]
Ave=mean(B)
B =2.
3.
4.
5.
Ave =3.5
//Finding the maximum and minimum values of a vector
A=[1 2 3 10.1 -1]
Geethanjali College of Engineering & Technology

Page 22

Basic Simulation Lab

A1=max(A)
A2=min(A)
A =1. 2. 3.
A1 =10.1
A2= -1

Department of ECE

10.1 - 1.

//Finding the product of the elements of a Matrix


A=[1 2 3 4]
P=prod(A)
A =1.
2.
3.
4.
P =24.
//Checking the sign of the elements of a Matrix
B=[-1 -2 3 4 -5 0]
S=sign(B)
//sign(B) returns 1 if the element of B is +ve, -1 if the element is ve and
zero if the element is zero
B =
- 1. - 2. 3. 4. - 5. 0.
S =
- 1. - 1. 1. 1. - 1. 0.
//Finding the non zero elements of the Matrix
A=[-1 2 0 0 2 3]
S=find(A)
//find(A) returns the indices of the non- zero elements of A
A = -1.
2.
0.
0.
2.
3.
S =1.
2.
5.
6.
//Arranging the elements of a Matrix in ascending/descending order
A=[1 23 45 6 73]
A1=gsort(A,r)
A =1. 23. 45.
6. 73.
A1 =1. 6. 23. 45. 73.
//mtlb_sort(A) also will do the same
A2=sort(A, c)
A1 = 73. 45. 23.
6.
1.
//Reshaping the Matrix
A=[1 2 3 4]
Geethanjali College of Engineering & Technology

Page 23

Basic Simulation Lab

Department of ECE

A1=matrix(A,4,1)
A2=A(:)
A3=matrix(A,2,2)
A =1.
2.
3.
4.
A1 =A2=
1.
2.
3.
4.
A3 =
1.
3.
2.
4.
//Extending the Dimension of the Matrix
A=[1 2 3]
//Appending a Row
A(2,:)=[4 5 6]
A =1.
2.
3.
A =1.
2.
3.
4.
5.
6.
//Appending a Column
A=[1 2 3]
A(:,4)= 10
A = 1.
2.
3. 10.
//Deleting
A=[1 2 3 4]
A =1.
2.
//Deleting
A(4)=[ ]
A =1.
2.

the elements of a Matrix


3.
4.
the 4th column element
3.

//Arithmetic operations
//Addition of Two row matrices
A=[1 2 3]
B=[5 6 7]
S=A+B
D=A-B
A =1.
2.
3.
B =5.
6.
7.
S =6.
8. 10.
Geethanjali College of Engineering & Technology

Page 24

Basic Simulation Lab

Department of ECE

D = -4. -4. -4.


//Multiplication of Two Matrices
A=[1 2 3]
B=[2;3;4]
C=A*B
A =1.
2.
3.
B=
2.
3.
4.
C =20
//Element wise Multiplication
A=[1 2 3]
B=[3 4 5]
C=A.*B
A =1.
2.
3.
B =3.
4.
5.
C =3.
8. 15.
//Element wise Division
A=[1 2 3]
B=[3 4 5]
C=A./B
A =1.
2.
3.
B =4.
4.
6.
C =0.25 0.4 0.5
C1=A.\B
C1=3. 2. 1.6666667
//Raising each element of the matrix to 3rd power
A=[2 5 8]
B=A.^3
A =2.
5.
8.
B =8. 125. 512.
//Relational Operators
A=[1 2 3]
B=[5 3 1]
K=A>B
K1=A<B
A =1.
2.
3.
B =5.
3.
1.
K=F
F
T

Geethanjali College of Engineering & Technology

Page 25

Basic Simulation Lab

K1=T

Department of ECE

A=[1 2 3]
B=[1 3 3]
K=A<=B
K1=A>=B
K2=A==B
A =1.
2.
3.
B =1.
3.
3.
K=T T
T
K1=T F
T
K2=T F
T
A=[1 2 3]
B=[1 3 3]
K=A~=B( not equal to)
A = 1. 2. 3.
B = 1. 3. 3.
K = FTF

//Logical Operators
A=[1 2 3]
B=[2 0 4]
K=A|B
K1=A&B
A =1.
2.
3.
B =2.
0.
4.
x =T
T
T
y =T
F
T
A=[1 0 3]
K=~A
A=1.
0.
K =F T

3.
F

//These Programs explain various (MxN) Matrix Operations:


//Creating a One-Dimensional Array/Vector:

Geethanjali College of Engineering & Technology

Page 26

Basic Simulation Lab

Department of ECE

A=input('enter the Matrix Elements')


enter the Matrix Elements[1 2 3;4 5 6;7 8 9]
A=
1.
2.
3.
4.
5.
6.
7.
8.
9.
//creating a Matrix consisting of all zeros
A=zeros(3,2)
A=
0.
0.
0.
0.
0.
0.
//creating a Matrix consisting of all Ones
B=ones(4,2)
B=
1.
1.
1.
1.
1.
1.
1.
1.
//Creating an Identity Matrix
A=eye(3,3)
A=
1. 0.
0.
0. 1.
0.
0. 0.
1.
//Measuring the order of the vector
A=[1 2 3;4 5 6;2 3 -1]
p=size(A)
A=
1.
2.
3.
4.
5.
6.
2.
3. -1.
p= 3.
3.
disp('The number of rows is')
The number of rows is
disp(p(1))
3.
disp('The number of columns is')
The number of columns is
Geethanjali College of Engineering & Technology

Page 27

Basic Simulation Lab

Department of ECE

disp(p(2))
3.
//Transpose of a Matrix
A=[1 2 3 ;10 11 12; 34 45 89]
A1=A'
A=
1.
2.
3.
10. 11. 12.
34. 45. 89.
A1 =
1. 10. 34.
2. 11. 45.
3. 12. 89.
//Multiplying each element of the Matrix with a constant
k=input('enter the value of the Multiplying Constant')
B=[3 4 5 6;2 4 6 8]
B1=k*B
enter the value of the Multiplying Constant
k =4
B=
3.
4.
5.
6.
2.
4.
6.
8.
B1 =
12. 16. 20. 24.
8. 16. 24. 32.
//The above Multiplication operation can be done also as follows:
B11=k.*B

//Finding the sum of element of a Matrix


A=[1 2 ;3 4;5 6]
S=sum(A)
A=
1.
2.
3.
4.
5.
6.
S =21.

Geethanjali College of Engineering & Technology

Page 28

Basic Simulation Lab

Department of ECE

//Finding the average of the elements of Matrix


B=[2 3 4;4 5 6]
Ave=mean(B)
B=
2.
3.
4.
4.
5.
6.
Ave =
4.
//Finding the maximum and minimum values of a vector
A=[1 2 3; 10 2 -1]
A1=max(A)
A2=min(A)
P=prod(A)
A=
1.
2.
3.
10.
2. -1.
A1 =10.
A2 = -1.
P = -120.
%Checking the sign of the elements of a Matrix
B=[-1 -2 3;4 -5 0]
S=sign(B)
//sign(B) returns 1 if the element of B is +ve, -1 if the element is
ve and zero if the element is zero
B=
-1. -2.
3.
4. -5.
0.
S=
-1. -1.
1.
1. -1.
0.
//Finding the non zero elements of the Matrix
A=[-1 2 0; 0 2 3]
S=find(A)
//find(A) returns the indices of the non- zero elements of A

A=
-1.
0.
S = 1.

2.
2.
3.

0.
3.
4. 6.

Geethanjali College of Engineering & Technology

Page 29

Basic Simulation Lab

Department of ECE

// checking a matrix whether is empty or not


A=[1 2 3 0]
K= isempty(A)
//isempty() returns a true value for an empty matrix
A =
1. 2. 3. 0.
K =F
//Arranging the elements of a Matrix in ascending/descending order
A=[1 23 45; 6 7 3]
A1=gsort(A,r)
//each column of A is sorted
A=
1. 23. 45.
6.
7.
3.
A1 =
6. 23. 45.
1. 7.
3.
A1=gsort(A, c)
//each row of A is sorted
A1=
45. 23. 1.
7.
6.
3.
A1=gsort(A,'g','i')
//all the elements of A are sorted in increasing order
A1 =
1. 6. 23.
3. 7. 45.
A1=gsort(A,'g','d')
// all the elements of A are sorted in decreasing order
A1 =
45. 7. 3.
23. 6. 1.
//Reshaping the Matrix
A=[1 2 3 4;3 5 6 7]
A1=matrix(A,4,2)
A2=matrix(A,1,8)
A=
1.
2.
3.
4.
3.
5.
6.
7.
Geethanjali College of Engineering & Technology

Page 30

Basic Simulation Lab

Department of ECE

A1 =
1.
3.
3.
6.
2.
4.
5.
7.
A2 =
1.
3.
2.
5.
3.
6.
4.
7.
//Extending the Dimension of the Matrix
A=[1 2 3;4 5 6]
//Appending a Row
A(3,:)=[10 15 26]
A= 1. 2. 3.
4. 5. 6.
A =
1.
2.
3.
4.
5.
6.
10. 15. 26.
//Appending a Column
A(:,4)=[10;20;87]
A= 1.
2.
3.
10.
4.
5.
6.
20.
10. 15. 26. 87.
//Appending an Intermediate row
A=[1 2 3;4 5 6;7 8 9]
A=
1.
2.
3.
4.
5.
6.
7.
8.
9.
//Appending a row between 1st and 2nd rows
A=[A(1,:); 10 11 12;A(2,:);A(3,:)]
A=
1.
2.
3.
10. 11. 12.
4.
5.
6.
7.
8.
9.
//Appending a column between 2nd and 3rd column
A=[A(:,1) A(:,2) [10;12;15;16] A(:,3)]
A=
1.
2. 10.
3.
10. 11. 12. 12.
Geethanjali College of Engineering & Technology

Page 31

Basic Simulation Lab

4.
7.

5.
8.

15.
16.

Department of ECE

6.
9.

//Deleting the row/column of a Matrix


A=[1 2 3; 4 5 6]
//Deleting the 2nd row
A(2,:)=[ ]
A=
1.
2.
3.
4.
5.
6.
A=
1.
2.
3.
//Deleting the 2nd column
A=[1 2 3; 4 5 6]
A(:,2)=[ ]
A=
1.
2.
3.
4.
5.
6.
A=
1.
3.
4.
6.
//Arithmetic operations
//Addition of Two row matrices
A=[1 2 3;4 5 6]
B=[5 6 7;10 11 12]
S=A+B
D=A-B
A=
1.
4.
B=
5.
10.
S=
6.
14.
D=

2.
5.

3.
6.

6.
11.

7.
12.

8. 10.
16. 18.

Geethanjali College of Engineering & Technology

Page 32

Basic Simulation Lab

Department of ECE

-4. -4. -4.


-6. -6. -6.
//Multiplication of Two Matrices
A=[1 2 3;4 5 6]
B=[5 6 3;10 11 12;3 4 6]
C=A*B
A=
1.
2.
3.
4.
5.
6.
B=
5.
6.
3.
10. 11. 12.
3.
4.
6.
C=
34. 40. 45.
88. 103. 108.
//Element wise Multiplication
A=[1 2 3;4 5 6]
B=[3 4 5;3 2 1]
C=A.*B
A=
1.
2.
3.
4.
5.
6.
B=
3.
4.
5.
3.
2.
1.
C=
3.
8. 15.
12. 10.
6.
//Element wise Division
C=A./B
C=
0.3333 0.5000 0.6000
1.3333 2.5000 6.0000

//Raising each element of the matrix to 4th power


A=[2 5 8;4 5 6]
B=A.^4
A=

Geethanjali College of Engineering & Technology

Page 33

Basic Simulation Lab

2.
4.
B=

5.
5.
16.
256.

Department of ECE

8.
6.
625.
625.

4096.
1296.

//Relational Operators
A=[1 2 3;10 3 5]
B=[5 3 1;0 3 6]
K=A>B
x=A<B
y=A<=B
K1=A>=B
K2=A==B
K3=A~=B
A=
1.
2.
3.
10.
3.
5.
B=
5.
3.
1.
0.
3.
6.
K=
F
F
T
T
F
F
x=
T
T
F
F
F
T
y=
T
T
F
F
T
T
K1 =
F
F
T
T
T
F
K2 =
F
F
F
F
T
F
K3 =
T
T
T
T
F
T
//Logical Operators
A=[1 2 3;0 0 1;1 -1 0]
Geethanjali College of Engineering & Technology

Page 34

Basic Simulation Lab

Department of ECE

B=[2 0 4;-1 2 -3;9 8 0]


K=A|B
K1=A&B
A=
1.
2.
3.
0.
0.
1.
1. -1.
0.
B=
2.
0.
4.
-1.
2. -3.
9.
8.
0.
K=
T T T
T T T
T T F
K1 =
T F T
F F T
T T F
A=[1 0 3;2 -1 0;3 2 -1]
K=~A/k=not(A)
A=
1
0
3
2 -1
0
3
2 -1
K=
F T F
F F T
F F F

Viva Questions:
1. Create a 3x4 Matrix and append a (i) row and (ii) column to the matrix
2. Create a 4x4 matrix and change its dimensions in to (i) 16x1 (ii)2x8 (iii) 8x2
3. Create a 5x6 Matrix and (i) find the number of elements of the matrix (ii) address
all the elements of 4th column (iii) address all the elements of the 3rd row.

Geethanjali College of Engineering & Technology

Page 35

Basic Simulation Lab

Department of ECE

EXP.NO: 2
GENERATION ON VARIOUS SIGNALS AND SEQUENCES
(PERIODIC AND APERIODIC), SUCH AS UNIT IMPULSE, UNIT STEP,
SQUARE, SAWTOOTH, TRIANGULAR, SINUSOIDAL, RAMP, SINC.
Aim: To generate different types of signals Using MATLAB Software.
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
THEORY

If the amplitude of the signal is defined at every instant of time


then it is called continuous signal. If the amplitude of the signal is
defined at only at some instants of time then, it is called discrete signal.
If the signal repeats itself at regular intervals of time, then it is called
periodic signal. Otherwise,they are called aperiodic signals.

Geethanjali College of Engineering & Technology

Page 36

Basic Simulation Lab

UNIT IMPULSE:

Department of ECE

a) Continous signal:

(t )

And

t0
t0

(t ) dt 1

Also called unit impulse function.The value of delta function can also be defined
in the sense of generalized function
(t): Test Function
b) Unit Sample sequence: (n)={ 1,
0,
i.e

n=0
n0

//Plotting an Unit Impulse Function


//This program plots unit Impulse function bounded between n1 and n2
n1=input('enter the value of n1')
n2=input('enter the value of n2')
t=[n1:n2];
i=find(t==0);
x=zeros(1,length(t));
x(i)=1;
plot2d3(t, x, style=4,rect=[-6 0 6 2])
Geethanjali College of Engineering & Technology

Page 37

Basic Simulation Lab

Department of ECE

xlabel('time')
ylabel('Stength')
legend('Delta function')
title('Plotting an unit impulse function')
xgrid
(OR)
n1=input('enter the value of n1')
n2=input('enter the value of n2')
t=[n1:n2];
x=zeros(1,length(t));
i=find(t==0);
x(i)=1;
plot2d3(t, x, style=5,rect=[-6 0 6 2])
xtitle("plot of an unit impulse", "time", "strength")
xgrid
legend('Delta function')

Geethanjali College of Engineering & Technology

Page 38

Basic Simulation Lab

Department of ECE

2)Unit Step Function u(t):


1
0

u (t )

b)Unit Step Sequence u(n): )={1,


0,

t0
t0

n0
n< 0

fs=input('enter the sampling frequency')


T=1/fs;
t=-1*T:T/fs: T;
Geethanjali College of Engineering & Technology

Page 39

Basic Simulation Lab

Department of ECE

x=zeros(1,length(t));
i=find(t==0);
x(i:length(x))=1;
plot2d2(t, x, style=5,rect=[-T 0 1.5*T 2])
xtitle("plot Unit Step Signal fs=500", "time", "amplitude")
xgrid
legend(' Unit Step Signal')
\

//This Program generates a Unit Step Sequence


fs=input('enter the sampling frequency')
T=1/fs;
t=-1*T:T/fs: T;
x=zeros(1,length(t));
i=find(t==0);

Geethanjali College of Engineering & Technology

Page 40

Basic Simulation Lab

Department of ECE

x(i:length(x))=1;
plot2d3(t, x, style=5,rect=[-T 0 1.5*T 2])
xtitle("plot Unit Step sequence fs=10", "time", "amplitude")
xgrid
legend(' Unit Step Sequence')

Square waves:Like sine waves, square waves are described in terms of period,
frequency and amplitude:

//This Program generates a Square Wave


fs=input('enter the sampling frequency')
T=1/fs;
c=input('enter the number of cycles to be plotted')
t=0:T/fs:T;
x=zeros(1,length(t));

Geethanjali College of Engineering & Technology

Page 41

Basic Simulation Lab

Department of ECE

if modulo(length(t),2)==0
for i=1:length(t)/2
x(i)=1;
x(i+length(t)/2)=-1;
end
else
for i=1:(length(t)-1)/2
x(i)=1;
x(i+(length(t)-1)/2)=-1;
x(length(t))=-1;
end
end
t1=0:T/fs:c*T;
y=x;
x(1)=[];
for i=1:c-1
y=[y x]
end
plot2d1(t1,y,style=5,rect=[0 -2 max(t1) 2])
xtitle("",'time','amplitude')
xgrid
legend('Symmetrical square pulse/wave with fs=1000, No.of cycles=3')

Geethanjali College of Engineering & Technology

Page 42

Basic Simulation Lab

Department of ECE

SAW TOOTH:
It is defined as x(t)=t for 0<t<T;
=0 elsewhere.
//This program generates a Saw tooth pulse
fs=input('enter the value of sampling frequency')
T=1/fs;
t=0:T/fs:T;
p=zeros(1,length(t));
c=input('enter the duration of the pulse interms of number of time
instances to be included')
for i=2:c
p(i)=p(i-1)+1;
end
plot2d1(t,p,style=5,rect=[0 0 T max(p)+100])
xtitle("plot of sawtooth pulse;fs=1000; c=500", "time", "amplitude")
legend('Sawtooth Pulse ')

//This program generates a Discrete Saw tooth pulse


Geethanjali College of Engineering & Technology

Page 43

Basic Simulation Lab

Department of ECE

fs=input('enter the value of sampling frequency')


T=1/fs;
t=0:T/fs:T;
p=zeros(1,length(t));
c=input('enter the duration of the pulse in terms of number of time
instances to be included')
for i=2:c
p(i)=p(i-1)+1;
end
plot2d3(t,p,style=-4,rect=[0 0 T max(p)+10])
xtitle("plot of Discrete sawtooth pulse;fs=100; c=50", "time", "amplitude")
legend(discrete sawtooth pulse)

//This program generates Saw tooth pulse Train


fs=input('enter the value of sampling frequency')
T=1/fs;
t=0:T/fs:T;
p=zeros(1,length(t));
k=input('enter the number of cycles to be plotted')
c=input('enter the duration of the pulse interms of number of time
instances to be included')
for i=2:c
p(i)=p(i-1)+1;
end
t1=0:T/fs:k*T;
p1=zeros(1,length(t1));

Geethanjali College of Engineering & Technology

Page 44

Basic Simulation Lab

Department of ECE

p1(1:length(p)-1)=p(1:length(p)-1);
p(1)=[];
for i=1:k-1
p1(i*length(p)+2:(i+1)*length(p)+1)=p
end
plot2d1(t1,p1,style=5,rect=[0 0 k*T max(p)+1])
xtitle("plot of Sawtooth pulse Train;fs=100; c=50; 3 cycles", "time",
"amplitude")
legend('Sawtooth Pulse Train')

//This program generates Discrete Saw tooth pulse Train


s=input('enter the value of sampling frequency')
k=input('enter the number of cycles to be plotted')
T=1/fs;
t=0:T/fs:k*T;
p=zeros(1,length(t));
x=length(t);
disp(x)
c=input('enter the duration of the pulse in each cycle interms of
number of time instances to be included such that k.c<x')

Geethanjali College of Engineering & Technology

Page 45

Basic Simulation Lab

Department of ECE

for i=1:k
for j=2+(i-1)*c:(i-1)*c+c
p(j)=p(j-1)+1;
end
end
plot2d3(t,p,style=-4,rect=[0 0 k*T max(p)+1])
xtitle("plot of Discrete Sawtooth pulse Train;fs=10; c=100; 3 cycles",
"time", "amplitude")
legend('Discrete Sawtooth Pulse Train')

Triangle wave:

Geethanjali College of Engineering & Technology

Page 46

Basic Simulation Lab

Department of ECE

//This program generates a Triangular Pulse


fs=input('enter the sampling frequency')
T=1/fs;
t=0:T/fs:T;
p=zeros(1,length(t));
for i=2:((length(t)-1)/2)+1
p(i)=p(i-1)+1;
p(length(t)-(i-1))=p(i);
end
plot2d1(t,p,style=5,rect=[0 0 T max(p)+1])
xtitle("plot of triangular pulse fs=10", "time", "amplitude")
xgrid
legend('Triangular Pulse')

//This program generates a Discrete Triangular Pulse


fs=input('enter the sampling frequency')
T=1/fs;
t=0:T/fs:T;
p=zeros(1,length(t));
for i=2:((length(t)-1)/2)+1
Geethanjali College of Engineering & Technology

Page 47

Basic Simulation Lab

Department of ECE

p(i)=p(i-1)+1;
p(length(t)-(i-1))=p(i);
end
plot2d3(t, p, style=-4,rect=[0 0 T max(p)+1])
xtitle("plot of triangular pulse fs=10", "time", "amplitude")
legend('Triangular Pulse'

//This program generates a Triangular Pulse Train


fs=input('enter the sampling frequency')
k=input('enter the number of cycles to be plotted')
T=k/fs;
t=0:T/fs:T;
p=zeros(1,length(t));
for i=2:((length(t)-1)/2)+1
p(i)=p(i-1)+1;
p(length(t)-(i-1))=p(i);
end
t1=0:T/fs:k*T;
p1=zeros(1,length(t1));
p1(1:length(p)-1)=p(1:length(p)-1);

Geethanjali College of Engineering & Technology

Page 48

Basic Simulation Lab

Department of ECE

p(1)=[];
for i=1:k-1
p1(i*length(p)+2:(i+1)*length(p)+1)=p
end
plot2d1(t1,p1,style=5,rect=[0 0 k*T max(p)+1])
xtitle("plot of triangular pulse Train;fs=10;3 cycles", "time", "amplitude")
xgrid
legend('Triangular Pulse Train')

//This program generates a

Discrete Triangular Pulse Train

fs=input('enter the sampling frequency')


k=input('enter the number of cycles to be plotted')
T=k/fs;
t=0:T/fs:T;
p=zeros(1,length(t));
for i=2:((length(t)-1)/2)+1
p(i)=p(i-1)+1;
p(length(t)-(i-1))=p(i);
end
t1=0:T/fs:k*T;
p1=zeros(1,length(t1));
Geethanjali College of Engineering & Technology

Page 49

Basic Simulation Lab

Department of ECE

p1(1:length(p)-1)=p(1:length(p)-1);
p(1)=[];
for i=1:k-1
p1(i*length(p)+2:(i+1)*length(p)+1)=p
end
plot2d3(t1,p1,style=5,rect=[0 0 k*T max(p)+1])
xtitle("plot of triangular pulse Train;fs=10;3 cycles", "time", "amplitude")
xgrid
legend('Triangular Pulse Train')

Ramp Signal:
It is defined as x(t)=t for t0
= 0 elsewhere
//This program generates ramp Signal
t=0:0.1:1;
x=0;
for i=2:length(t)
x(i)=x(i-1)+2;
end
plot2d1(t, x, style=5,rect=[0 0 max(t) max(x)])
xgrid
xtitle("plot of Ramp Signal", "time", "amplitude")

Geethanjali College of Engineering & Technology

Page 50

Basic Simulation Lab

Department of ECE

legend(' Ramp Signal ')

//This program generates discrete ramp signal


t=0:0.1:1;
x=0;
for i=2:length(t)
x(i)=x(i-1)+2;
end
plot2d3(t, x, style=-4,rect=[0 0 max(t) max(x)])
xgrid
xtitle("plot of Discrete Ramp Signal", "time", "amplitude")
legend(' Discrete Ramp Signal ')

Geethanjali College of Engineering & Technology

Page 51

Basic Simulation Lab

Department of ECE

Sinusoidal Signal Generation


The sine wave or sinusoid is a mathematical function that describes a smooth repetitive
oscillation. Its most basic form as a function of time (t) is x(t)=A.sin(wt+)
where:

A, the amplitude, is the peak deviation of the function from its center position.
, the angular frequency, specifies how many oscillations occur in a unit time
interval, in radians per second
, the phase, specifies where in its cycle the oscillation begins at t = 0.

//This program generates a Sinusoidal Pulse/Sinusoidal Pulse


Train
f=input('enter the frequency of the signal')
i=input('enter the no. of cycles to be plotted')
Geethanjali College of Engineering & Technology

Page 52

Basic Simulation Lab

Department of ECE

T=i/f;
t=0:T/f:T;
x=sin(2*%pi*f*t);
plot2d1(t, x, style=5,rect=[0 -2 T 2])
xtitle("plot of an sinusoidal pulse Train fs=1000,i=3", "time",
"amplitude")
xgrid
legend(' Sinusoidal Pulse Train')

//This program generates a Discrete Sinusoidal Pulse / Discrete


Sinusoidal Pulse Train
f=input('enter the frequency of the signal');
i=input('enter the no.of cycles to be plotted')
T=i/f;
t=0:T/f:T;
x=sin(2*%pi*f*t);
plot2d3(t, x, style=5,rect=[0 -2 T 2])

Geethanjali College of Engineering & Technology

Page 53

Basic Simulation Lab

Department of ECE

xtitle("plot of Discrete sinusoidal pulse Train fs=50,i=2", "time",


"amplitude")
xgrid
legend(' Discrete Sinusoidal Pulse Train')

SINC FUNCTION:
The sinc function computes the mathematical sinc function for an input vector or
matrix x. Viewed as a function of time, or space, the sinc function is the inverse Fourier
transform of the rectangular pulse in frequency centered at zero of width 2 and height
1. The following equation defines the sinc function:

The sinc function has a value of 1 when x is equal to zero.

Geethanjali College of Engineering & Technology

Page 54

Basic Simulation Lab

Department of ECE

//This program generates sinc waveform


f=input('enter the frequency')
i=input('enter the number of cycles to be plotted')
T=i/f;
t=-T:T/f:T;
i=find(t==0);
x1=sin(2*%pi*f*t);
x1(i)=1;
x2=2*%pi*f*t;
x2(i)=1;
x=x1./x2;
plot2d1(t,x,style=-4,rect=[-T -max(x)-0.5 T max(x)+0.5])
xgrid
xtitle("plot of sampling function f=500 ; 5 cycles", "time", "amplitude")
legend(' Sampling Function ')

Geethanjali College of Engineering & Technology

Page 55

Basic Simulation Lab

Department of ECE

CONCLUSION: In this experiment, various basic signals are generated.


Exersize questions:Generate the following signals:
1.x(t)=e-t
2.x(t)= t 2 / 2
3. Rectangular Pulse
4. signum function

sgn(t)=

t>0

t=0

-1

t<0

5.Complex exponential signal x(t)= exp(-jwt)

VIVA QUESTIONS
1. What is a singular Function
2. Define deterministic and Random Signal
3. Define Delta Function
4. Define Periodic and Aperiodic Signal
5. Explain about sifting property of Impulse function.

Geethanjali College of Engineering & Technology

Page 56

Basic Simulation Lab

Department of ECE

EXP.NO: 3
OPERATIONS ON SIGNALS AND SEQUENCES SUCH AS ADDITION,
MULTIPLICATION, SCALING, SHIFTING, FOLDING, COMPUTATION OF
ENERGY AND AVERAGE POWER
Aim: To perform arithmetic operations different types of signals Using MATLAB
Software.
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
Geethanjali College of Engineering & Technology

Page 57

Basic Simulation Lab

Department of ECE

MATLAB Software
Basic Operation on Signals:
Time Shifting:
1.//This function generates the Advanced/Delayed unit impulse
function
n1=input('enter the value of n1<0')
n2=input('enter the value of n2>0')
n=input('enter the value of n lying between n1 and n2 and not equal to
zero')
t=[n1:n2];
x=zeros(1,length(t));
y=x;
i=find(t==0);
x(i)=1;
i=find(t==n);
y(i)=1;
subplot(2,1,1)
plot2d3(t,x,style=-4,rect=[n1 0 n2 2])
xtitle("", "time", "amplitude")
legend('Unit Impulse function')
subplot(2,1,2)
plot2d3(t,y,style=-4,rect=[n1 0 n2 2])
xtitle("", "time", "amplitude")
if n>0
legend('Delayed Unit Impulse by 3 units')
else
legend('Advanced Unit Impulse by 3 units ')
end

Geethanjali College of Engineering & Technology

Page 58

Basic Simulation Lab

Geethanjali College of Engineering & Technology

Department of ECE

Page 59

Basic Simulation Lab

Department of ECE

2.//This Program generates a shifted Unit Step Signal


fs=input('enter the sampling frequency')
T=1/fs;
t=-1*T:T/fs:T;
x=zeros(1,length(t));
x1=x;
x2=x;
i=find(t==0);
x(i:length(x))=1;
k=input('enter the amount of positive shift required in between -T and
+T')
i=find(t==k);
x1(i:length(x))=1;
j=input('enter the amount of negative shift required in between -T and
+T')
i=find(t==j);
x2(i:length(x))=1;
subplot(3,1,1)
plot2d1(t,x,style=2,rect=[-T 0 T 2])
xtitle("", "time", "amplitude")
legend('Unit Step signal with fs=1000')
subplot(3,1,2)
plot2d1(t,x1,style=2,rect=[-T 0 T 2])
xtitle("", "time", "amplitude")
legend('Unit Step sgnal delayed by 0.0005sec')
subplot(3,1,3)
plot2d1(t,x2,style=2,rect=[-T 0 T 2])
xtitle("", "time", "amplitude")
legend('Unit Step sgnal advanced by 0.0005sec')

Geethanjali College of Engineering & Technology

Page 60

Basic Simulation Lab

Department of ECE

3.//This program generates a shifted sinusoidal pulse


f=input('enter the sampling frequency')
T=1/f
t=0:T/f:T;
x=sin(2*%pi*f*t);
b= input('select a value for b which is greater than one')
t1=-1*b*T:T/f:b*T;
p=zeros(1,length(t1));
q=p;
i=find(t1==0);
p(i:i+length(t)-1)=x;
k=input('enter the amount of shift required which is bounded by -b.T
and +b.T')
j=find(t1==k)
q(j:j+length(t)-1)=x;
if k<0
subplot(2,1,1)
plot2d1(t1,p,style=2,rect=[min(t1),min(p),max(t1),max(p)])
xtitle("", "time", "amplitude")
legend('sinusoidal pulse with f=500,b=2')
Geethanjali College of Engineering & Technology

Page 61

Basic Simulation Lab

Department of ECE

subplot(2,1,2)
plot2d1(t1,q,style=2,rect=[min(t1),min(p),max(t1),max(p)])
xtitle("", "time", "amplitude")
legend('sinusoidal pulse advanced by 0.002sec')
else
subplot(2,1,1)
plot2d1(t1,p,style=2,rect=[min(t1),min(p),max(t1),max(p)])
xtitle("", "time", "amplitude")
legend('sinusoidal pulse with f=500,b=2')
subplot(2,1,2)
plot2d1(t1,q,style=2,rect=[min(t1),min(p),max(t1),max(p)])
xtitle("", "time", "amplitude")
legend('sinusoidal pulse delayed by 0.002sec')
end

Geethanjali College of Engineering & Technology

Page 62

Basic Simulation Lab

Department of ECE

Signal Addition and Multiplication :


Addition: any two signals can be added to form a third signal,
z (t) = x (t) + y (t)

1.//This program adds two sinusoidal signals of different duration


f1=input('enter the frequency of the first signal')
i=input('enter the no.of cycles of the first signal to be plotted')
T1=i/f1;
t1=0:T1/f1:T1;
p1=sin(2*%pi*f1*t1);
subplot(3,1,1)
plot2d1(t1,p1,style=5,rect=[0 -max(p1)-0.5 T1 max(p1)+0.5])
xtitle( "","time", "amplitude")
legend('f=10 Hz, 1 cycle')
f2=input('enter the frequency of the second signal');
Geethanjali College of Engineering & Technology

Page 63

Basic Simulation Lab

Department of ECE

j=input('enter the no.of cycles of the second signal to be plotted')


T2=j/f2;
t2=0:T2/f2:T2;
p2=sin(2*%pi*f2*t2);
subplot(3,1,2)
plot2d1(t2,p2,style=5,rect=[0 -max(p2)-0.5 T2 max(p2)+0.5])
xtitle("","time", "amplitude")
legend('f=20 Hz, 2 cycles')
t=[t1 t2];
t=gsort(t,'g','increase')
for i=2:length(t)
if t(i)==t(i-1)
t(i)=%pi
end
end
x=find(t==%pi);
t(x(1:length(x)))=[];
if length(t1)>length(t2)
p=zeros(1,length(t1))
for i=1:length(t1)
for j=1:length(t2)
if t1(i)==t2(j)
p(i)=p2(j);
end
end
end
p(length(p)+1:length(t))=p2(flipdim(length(p2):-1:length(p2)-(length(t)length(p)-1),2));
p1(length(p1)+1:length(p))=0;
P=p+p1;
else
p=zeros(1,length(t2))
for i=1:length(t2)
for j=1:length(t1)
if t2(i)==t1(j)
p(i)=p1(j);
end
end
end
p(length(p)+1:length(t))=p1(flipdim(length(p1):-1:length(p1)-(length(t)length(p)-1),2));
p2(length(p2)+1:length(p))=0;

Geethanjali College of Engineering & Technology

Page 64

Basic Simulation Lab

Department of ECE

P=p+p2;
end
subplot(3,1,3)
plot2d1(t,P, style=5,rect=[0 -max(P)-0.5 max(t) max(P)+0.5])
xtitle("", "time", "amplitude")
legend('Sum of two Sinusoidal Signals')

2.//This Program adds to step signals of same duration


fs=input('enter the sampling frequency')
T=1/fs;
t=-1*T:T/fs: T;
x1=zeros(1,length(t));
x2=x1;
i=find(t==0);

Geethanjali College of Engineering & Technology

Page 65

Basic Simulation Lab

Department of ECE

x1(i:length(x1))=1;
x2(i:length(x2))=2
subplot(3,1,1)
plot2d1(t, x1, style=5,rect=[-T 0 1.5*T 2])
xtitle("", "time", "amplitude")
xgrid
legend(' Unit Step Signal with fs=500')
subplot(3,1,2)
plot2d1(t, x2, style=5,rect=[-T 0 1.5*T 3])
xtitle("", "time", "amplitude")
xgrid
legend(' Step Signal height 2 and fs=500')
subplot(3,1,3)
plot2d1(t, x1+x2, style=5,rect=[-T 0 1.5*T 4])
xtitle("", "time", "amplitude")
xgrid
legend('sum of 2 Step Signals')

3.//This Program adds two Discrete Triangular pulses of different


duration
fs1=input('enter the sampling frequency')
T1=1/fs1;
Geethanjali College of Engineering & Technology

Page 66

Basic Simulation Lab

Department of ECE

t1=0:T1/fs1:T1;
p1=zeros(1,length(t1));
for i=2:((length(t1)-1)/2)+1
p1(i)=p1(i-1)+1;
p1(length(t1)-(i-1))=p1(i);
end
subplot(3,1,1)
plot2d3(t1, p1, style=-4,rect=[0 0 T1 max(p1)+1])
xtitle("", "time", "amplitude")
legend('Triangular Pulse fs=10')
fs2=input('enter the sampling frequency')
T2=1/fs2;
t2=0:T2/fs2:T2;
p2=zeros(1,length(t2));
for i=2:((length(t2)-1)/2)+1
p2(i)=p2(i-1)+1;
p2(length(t2)-(i-1))=p2(i);
end
subplot(3,1,2)
plot2d3(t2, p2, style=-4,rect=[0 0 T2 max(p2)+1])
xtitle("", "time", "amplitude")
legend('Triangular Pulse fs=20')
t=[t1 t2];
t=gsort (t,'g', 'increase')
for i=2:length(t)
if t(i)==t(i-1)
t(i)=%pi
end
end
x=find(t==%pi);
t(x(1:length(x)))=[];
if length(t1)>length(t2)
p=zeros(1,length(t1))
for i=1:length(t1)
for j=1:length(t2)
if t1(i)==t2(j)
p(i)=p2(j);
end
end
end
p(length(p)+1:length(t))=p2(flipdim(length(p2):-1:length(p2)-(length(t)length(p)-1),2));

Geethanjali College of Engineering & Technology

Page 67

Basic Simulation Lab

Department of ECE

p1(length(p1)+1:length(p))=0;
P=p+p1;
else
p=zeros(1,length(t2))
for i=1:length(t2)
for j=1:length(t1)
if t2(i)==t1(j)
p(i)=p1(j);
end
end
end
p(length(p)+1:length(t))=p1(flipdim(length(p1):-1:length(p1)-(length(t)length(p)-1),2));
p2(length(p2)+1:length(p))=0;
P=p+p2;
end
subplot(3,1,3)
plot2d3(t,P, style=-4,rect=[0 0 max(t) max(P)+1])
xtitle("", "time", "amplitude")
legend('Sum of two Triangular Pulses')

Multiplication of Signals
Multiplication of two signals can be obtained by multiplying their values
at every respective time instants.
z (t) = x (t) .y (t)
Geethanjali College of Engineering & Technology

Page 68

Basic Simulation Lab

Department of ECE

1.//This program multiplies two discrete ramp signals of unequal


Duration
t1=0:0.1:1;
p1=zeros(1,length(t1));
for i=2:length(t1)
p1(i)=p1(i-1)+2;
end
subplot(3,1,1)
plot2d3(t1,p1,style=-3,rect=[0 0 max(t1) max(p1)])
xgrid
xtitle ("", "time", "amplitude")
legend('Discrete Ramp Signal-1 ')
t2=0:0.1:2;
p2=zeros(1,length(t2));
for i=2:length(t2)
p2(i)=p2(i-1)+2;
end
subplot(3,1,2)
plot2d3(t2,p2,style=-3,rect=[0 0 max(t2) max(p2)])
xgrid
xtitle ("", "time", "amplitude")
legend('Discrete Ramp Signal-2 ')
t=[t1 t2];
t=gsort (t, 'g', 'increase')
for i=2:length(t)
if t(i)==t(i-1)
t(i)=%pi
end
end
x=find(t==%pi);
t(x(1:length(x)))=[ ];
if length(t1)>length(t2)
p=zeros(1,length(t1))
for i=1:length(t1)
for j=1:length(t2)
if t1(i)==t2(j)
p(i)=p2(j);
end
end

Geethanjali College of Engineering & Technology

Page 69

Basic Simulation Lab

Department of ECE

end
p(length(p)+1:length(t))=p2(flipdim(length(p2):-1:length(p2)-(length(t)length(p)-1),2));
p1(length(p1)+1:length(p))=0;
P=p.*p1;
else
p=zeros(1,length(t2))
for i=1:length(t2)
for j=1:length(t1)
if t2(i)==t1(j)
p(i)=p1(j);
end
end
end
p(length(p)+1:length(t))=p1(flipdim(length(p1):-1:length(p1)-(length(t)length(p)-1),2));
p2(length(p2)+1:length(p))=0;
P=p.*p2;
end
subplot(3,1,3)
plot2d3(t, P, style=-3,rect=[0 0 max(t) max(P)])
xtitle("", "time", "amplitude")
legend('Product of Two ramp signals')

Geethanjali College of Engineering & Technology

Page 70

Basic Simulation Lab

Department of ECE

//2.This Program multiplies two step signals of equal duration


fs=input('enter the sampling frequency')
T=1/fs;
t=-1*T:T/fs: T;
x1=zeros(1,length(t));
x2=x1;
i=find(t==0);
x1(i:length(x1))=2;
x2(i:length(x2))=4;
subplot(3,1,1)
plot2d1(t, x1, style=-4,rect=[-T 0 1.5*T 3])
xtitle("", "time", "amplitude")
xgrid
legend(' Step Signal with height 2 and fs=500')
subplot(3,1,2)
plot2d1(t, x2, style=-4,rect=[-T 0 1.5*T 5])
xtitle("", "time", "amplitude")
xgrid
legend(' Step Signal with height 4 and fs=500')
subplot(3,1,3)
plot2d1(t, x1.*x2, style=-4,rect=[-T 0 1.5*T 10])
Geethanjali College of Engineering & Technology

Page 71

Basic Simulation Lab

Department of ECE

xtitle("", "time", "amplitude")


xgrid
legend('Product of 2 Step Signals')

Time reversal(Folding about Y-axis):


Time reversal of a signal x(t) can be obtained by folding the signal about t=0 i.e. Y-axis.
y(t)=x(-t)
1.//This Program generates a Unit Step Signal Folded about y-axis
fs=input('enter the sampling frequency')
T=1/fs;
t=-1*T:T/fs:T;
x=zeros(1,length(t));
i=find(t==0);
x(i:length(x))=1;
subplot(2,1,1)
plot2d1(t,x,style=2,rect=[min(t),0,max(t),2])
xtitle("", "time", "amplitude")
legend('Unit Step signal with fs=1000')
x=zeros(1,length(t));
j=find(t==min(t));
x(j:i)=1;
subplot(2,1,2)
plot2d1(t,x,style=2,rect=[min(t),0,max(t),2])
Geethanjali College of Engineering & Technology

Page 72

Basic Simulation Lab

Department of ECE

xtitle("", "time", "amplitude")


legend('Unit Step signal folded about Y-axis')

2.//This program generates a saw Tooth pulse folded about y-axis


fs=input('enter the sampling frequency')
T=1/fs;
t= -1*T:T/fs: T;
p=zeros(1,length(t));
c=input('enter the number of samples to be included')
i=find(t==0);
for j=i+1:i+c
p(j+1)=p(j)+1;
end
subplot(2,1,1)
plot2d1(t,p,style=2,rect=[min(t),0,max(t),max(p)+3])
xtitle("", "time", "amplitude")
legend('Sawtooth pulse with fs=1000, c=200')
p1=zeros(1,length(t));
p1(i-c:i-1)=flipdim(p(i+1:i+c),2)
subplot(2,1,2)
Geethanjali College of Engineering & Technology

Page 73

Basic Simulation Lab

Department of ECE

plot2d1(t,p1,style=2,rect=[min(t),0,max(t),max(p1)+3])
xtitle("", "time", "amplitude")
legend('Sawtooth pulse folded about Y-axis')

Signal Amplification/Attuation : Y(n)=ax(n) if a < 1 attnuation


a >1 amplification

% Amplitude scaling
clc;
clear all;
close all;
t = [0:.01:1];
% independent (time) variable
A = 8;
% amplitude
f1 = 2;
% create a 2 Hz sine wave lasting 1 sec
s1 = A*sin(2*pi*f1*t);
subplot(3,1,1);
plot(s1);
xlabel('t');ylabel('amplitude');
title('input signal');
s2=2*s1;
subplot(3,1,2);
plot(s2);
xlabel('t');ylabel('amplitude');
title('amplified input signal');
Geethanjali College of Engineering & Technology

Page 74

Basic Simulation Lab

Department of ECE

s3=s1/2;
subplot(3,1,3);
plot(s3);
xlabel('t');ylabel('amplitude');
title('atteniated input signal');
% Amplitude scaling for sequences
clc;
clear all;
close all;
n=0:1:6;
s1 = [1 2 3 3 1 1 1];
subplot(3,1,1);
stem(n,s1);
xlabel('n');
ylabel('amplitude');
title('input signal');
s2=4*s1;
subplot(3,1,2);
stem(n,s2);
xlabel('t');
ylabel('amplitude');
title('amplified input signal');
s3=s1/4;
subplot(3,1,3);
stem(n,s3);
xlabel('t');
ylabel('amplitude');
title('atteniatedinput signal');
Time scalling:
The Time scalling of a signal x(t) can be accomplished by replacing t by at where a
is a scaling factor.
Y(t)=x(at)
; a= arbitrary constant
If a<1 the signal y(t) is expanded x(t)
If a>1 the signal y(t) is compressed x(t)
1.// This program generates Time scaled version of a Triangular
Pulse
fs=input('enter the sampling frequency')
T=1/fs;
t=0:T/fs:T;
p=zeros(1,length(t));
p1=p;
for i=2:((length(t)-1)/2)+1
p(i)=p(i-1)+1;

Geethanjali College of Engineering & Technology

Page 75

Basic Simulation Lab

Department of ECE

p(length(t)-(i-1))=p(i);
end
c=input('enter the scaling factor')
t1=t./c;
if c<1
subplot(2,1,1)
plot2d1(t,p,style=1,rect=[0 0 1+T/c max(p)+1])
xtitle("plot of triangular pulse fs=10", "time", "amplitude")
xgrid
legend('Triangular Pulse')
subplot(2,1,2)
plot2d1(t1,p,style=1,rect=[0 0 1+T/c max(p)+1])
xtitle("plot of triangular pulse fs=10", "time", "amplitude")
xgrid
legend('c=0.2,Expanded Triangular Pulse')
else
subplot(2,1,1)
plot2d1(t,p,style=1,rect=[0 0 T max(p)+1])
xtitle("plot of triangular pulse fs=10", "time", "amplitude")
xgrid
legend('Triangular Pulse')
subplot(2,1,2)
plot2d1(t1,p,style=1,rect=[0 0 T max(p)+1])
xtitle("plot of triangular pulse fs=10", "time", "amplitude")
xgrid
legend('c=2, Compressed Triangular Pulse')
end

Geethanjali College of Engineering & Technology

Page 76

Basic Simulation Lab

Department of ECE

2.// This program generates Time scaled version of a Sawtooth


Geethanjali College of Engineering & Technology

Page 77

Basic Simulation Lab

Department of ECE

Pulse
fs=input('enter the sampling frequency')
T=1/fs;
t=0:T/fs:T;
p=zeros(1,length(t));
k=input('enter the duration of the pulse interms of number of time
instances to be included')
for i=2:k
p(i)=p(i-1)+1;
end
c=input('enter the scaling factor')
t1=t./c;
if c<1
subplot(2,1,1)
plot2d1(t,p,style=1,rect=[0 0 0.001+T/c max(p)+1])
xtitle("", "time", "amplitude")
xgrid
legend('Sawtooth Pulse with with fs=100,k=50')
subplot(2,1,2)
plot2d1(t1,p,style=1,rect=[0 0 0.001+T/c max(p)+1])
xtitle("", "time", "amplitude")
xgrid
legend('c=0.2,Expanded Sawtooth Pulse')
else
subplot(2,1,1)
plot2d1(t,p,style=1,rect=[0 0 T max(p)+1])
xtitle("", "time", "amplitude")
xgrid
legend('Sawtooth Pulse with fs=100,k=50')
subplot(2,1,2)
plot2d1(t1,p,style=1,rect=[0 0 T max(p)+1])
xtitle("", "time", "amplitude")
xgrid
legend('c=2, Compressed Triangular Pulse')
end

Geethanjali College of Engineering & Technology

Page 78

Basic Simulation Lab

Department of ECE

ENERGY AND POWER SIGNA L:A signal can be categorized into energy signal or
power signal:
Geethanjali College of Engineering & Technology

Page 79

Basic Simulation Lab

Department of ECE

energy signal has a finite energy, 0 < E < . And Power=0


Energy signals have values only in the limited time duration.
Energy of Continuous Signals

Energy of Discrete Signals

power signal has a finite Power, 0 < P< . And Energy =


Power of Continuous Signals

Power of Discrete Signals

Computation of Energy:
1.//This program generates a sinusoidal Pulse and computes its
Energy
f=input('enter the value of the frequency')
T=1/f;
t=0:T/f:T;
x=(sin(2*%pi*f*t));
x1=abs(x);
E1=x1.*x1;
E=sum(E1);
plot2d3(t,x,style=2,rect=[0,-1,T,1])
xtitle("", "time", "amplitude")
legend('Discrete Sinusoidal Pulse with fs=10 and its energy is 5 joules')
disp('Energy of the generated signal in joules is')
disp(E)

Geethanjali College of Engineering & Technology

Page 80

Basic Simulation Lab

Department of ECE

2.//This Program generates a rectangular pulse and finds its


energy
f=input('enter the sampling frequency')
T=1/f;
t=-T:T/f:T;
x=zeros(1,length(t));
c=input('enter the duration of the rectangular pulse in therms of
number of samples to included')
i=find(t==0);
x(i:i+c-1)=0.25;
E=sum(x.*x);
plot2d(t,x,style=2,rect=[-T 0 T 0.5])
xtitle("", "time", "amplitude")
legend('Rectangular Pulse with fs=100, c=50 and with energy=3.125
Joules')
disp('Energy of the generated signal measured in joules is')
disp(E)

Geethanjali College of Engineering & Technology

Page 81

Basic Simulation Lab

Department of ECE

Energy of the generated signal measured in joules is 3.125


Computation of Average Power:
1.//This program generates a Periodic sinusoidal signal and
computes its average power
f=input('enter the frequency of the signal');
i=input('enter the no.of cycles to be plotted')
T=i/f;
t=0:T/f:T;
x=sin(2*pi*f*t);
y=input('enter the number of cycles(<=i) over which average power is to
be computed')
%z is the length of one cycle
z=(length(t)-1)/i;
x1=abs(x);
x2=x1.*x1;
p=(1/(y*z))*sum(x2(1:y*z));
disp('The average power of the generated signal measured in watts is ')
disp(p)

CONCLUSION: In this experiment the various operations on signals have been


implemented.

Geethanjali College of Engineering & Technology

Page 82

Basic Simulation Lab

Department of ECE

Exercise questions: Sketch the following questions using MATLAB


1. x(t)= u(-t+1)
2. x(t)=3r(t-1)
3. x(t)=U(n+2-u(n-3)
4. x(n)=x1(n)+x2(n)where x1(n)={1,3,2,1},x2(n)={1,-2,3,2}
5. x(t)=r(t)-2r(t-1)+r(t-2)
6. x(n)=2(n+2)-2(n-4), -5 n 5.
7. X(n)={1,2,3,4,5,6,7,6,5,4,2,1} determine and plot the following sequence
a. x1(n)=2x(n-5-3x(n+4))
b. x2(n)=x(3-n)+x(n)x(n-2)
VIVA QUESTIONS
1.Differentiate between Energy and Power of a signal
2.Define Continuous and Discrete Time Signals
3.Classify the following in to energy or power signals
(i) x(t)=exp(-at).u(t) (ii) x(t)=u(t) (iii) x(t)=exp(at)
4.What are the Different operations performed on the independent variable of a
Signal?

Geethanjali College of Engineering & Technology

Page 83

Basic Simulation Lab

Department of ECE

EXP.NO: 4
FINDING THE EVEN AND ODD PARTS OF SIGNAL/SEQUENCE AND REAL
AND IMAGINARY PART OF SIGNAL
Aim: Program for finding even and odd parts of signal.
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB/Scilab Software
THEORY :
Even and Odd Signal.

Even Signal: A signal is referred to as an even if it is identical to


its time-reversed counterpart; x(t) = x(-t).
Odd Signal: A signal is odd if x(t) = -x(-t).
An odd signal will be 0 at t=0, in other words, odd signal
passes the origin.
Even signals are symmetric around vertical axis, and Odd signals
are symmetric about origin
Any signal may be decomposed into a sum of its even part,
xe(t), and its odd part, xo(t), as follows:

//This program finds the even and odd part of a given sequence
1.x(n)=(n)+2(n-1)+3(n-2)+4(n-3)
x=input('enter the sequence')
n=input('enter the time indices')
n1=-flipdim(n,2);
m=[min(n1):max(n)];
x1=zeros(1,length(m));
k=find(m==min(n));
x1(k:length(m))=x;
Geethanjali College of Engineering & Technology

Page 84

Basic Simulation Lab

Department of ECE

x2=flipdim(x1,2);
xe=0.5*(x1+x2);
xo=0.5*(x1-x2);
subplot(3,1,1)
plot2d3(n,x,style=-4,rect=[min(n)-1 min(x)-1 max(n)+1 max(x)+1])
xtitle("", "time", "amplitude")
legend(' The given sequence x(n)= [1 2 3 4] at n=[0 1 2 3]')
xgrid
subplot(3,1,2)
plot2d3(m,xe,style=-4,rect=[min(m)-1 min(xe)-1 max(m)+1 max(xe)+1])
xtitle("", "time", "amplitude")
legend('Even part of the given sequence')
xgrid
subplot(3,1,3)
plot2d3(m,xo,style=-4,rect=[min(m)-1 min(xo)-1 max(m)+1 max(xo)+1])
xtitle("", "time", "amplitude")
legend('Odd part of the given sequence')
xgrid

2.x(t)= Sin(2000t)
f=input('enter the frequency')
T=1/f;
Geethanjali College of Engineering & Technology

Page 85

Basic Simulation Lab

Department of ECE

t=0:T/f:T;
x=sin(2*%pi*f*t);
t1=-flipdim(t,2);
t2=[min(t1):T/f:max(t)];
x1=zeros(1,length(t2));
k=find(t2==min(t));
x1(k:length(t2))=x;
x2=flipdim(x1,2);
xe=0.5*(x1+x2);
xo=0.5*(x1-x2);
subplot(3,1,1)
plot2d(t,x,style=-4,rect=[min(t) min(x)-0.5 max(t) max(x)+0.5])
xtitle("", "time", "amplitude")
xgrid
legend('Sinusoidal pulse with fs=500')
subplot(3,1,2)
plot2d(t2,xe,style=-4,rect=[min(t2) min(xe)-0.5 max(t2) max(xe)+0.5])
xtitle("", "time", "amplitude")
xgrid
legend('Even part of the given sinusoidal pulse')
subplot(3,1,3)
plot2d(t2,xo,style=-4,rect=[min(t2) min(xo)-0.5 max(t2) max(xo)+0.5])
xtitle("", "time", "amplitude")
xgrid
legend('Odd part of the given sinusoidal pulse')

Geethanjali College of Engineering & Technology

Page 86

Basic Simulation Lab

Department of ECE

Conclusion:
The even and odd parts of signal/sequence signal are computed and plotted.
VIVA QUESTIONs.
1.Define even and odd symmetry of a signal.
2.Plot the even and odd parts of a unit step signal

Geethanjali College of Engineering & Technology

Page 87

Basic Simulation Lab

Department of ECE

EXP.NO: 5
LINEAR CONVOLUTION
Aim: To implement linear convolution of two signals/sequences.
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB /Scilab Software
Theory:

If x(n)=(n), then output y(n) is known as impulse response of the system.


y(n)=T[x(n)]==T[(n)]=h(n) . For a time invariant system, T[ (n-k)]= h(n-k).
x(n) can represented as weighted sum of impulses such as

Geethanjali College of Engineering & Technology

Page 88

Basic Simulation Lab

Department of ECE

For an LSI system,


y(n)=T[x(n)]
=
--- Linear Convolution equation
Linear Convolution involves the following operations.
1. Folding
2. Multiplication
3. Addition
4. Shifting
These operations can be represented by a Mathematical Expression as follows:

x[ ]= Input sequence
h[n ]= unit sample response of the system.
y[ ]= Convoluted sum.
1.//This Program finds the convolution between two sequences
x=input('Enter the sequence x(n)')
n1=input('Enter the time indices of x(n)')
y=input('Enter the sequence y(n)')
n2=input('Enter the time indices of y(n)')
n=min(n1)+min(n2):max(n1)+max(n2);
A=zeros(min(length(x),length(y)),length(x)+length(y)-1);
if length(x)<length(y)
for i=1:length(x)
A(i,i:i+length(y)-1)=y(1,:);
A(i,:)=x(i).*A(i,:);
end
else
for i=1:length(y)
A(i,i:i+length(x)-1)=x(1,:);
A(i,:)=y(i).*A(i,:);
end
end
c=zeros(1,length(x)+length(y)-1);
for i=1:min(length(x),length(y))
c(1,:)=c(1,:)+A(i,:);
end
Geethanjali College of Engineering & Technology

Page 89

Basic Simulation Lab

Department of ECE

disp('The convolution of the given sequences is')


disp(c)
disp( The Time index of the convolved sum is)
disp(n)
subplot(3,1,1)
plot2d3(n1,x,style=-4,rect=[min(n1)-1 min(x)-1 max(n1)+1 max(x)+1])
xtitle("", "time", "amplitude")
xgrid
legend('Given sequence x(n)')
subplot(3,1,2)
plot2d3(n2,y,style=-4,rect=[min(n2)-1 min(y)-1 max(n2)+1 max(y)+1])
xtitle("", "time", "amplitude")
xgrid
legend('Given sequence y(n)')
subplot(3,1,3)
plot2d3(n,c,style=-4,rect=[min(n)-1 min(c)-1 max(n)+1 max(c)+5])
xtitle("", "time", "amplitude")
xgrid
legend('Convolution of x(n) and y(n)')
conv(a,b)- Returns the Convolution of two vectors a and b.

1.x(n)=(n)+(n-1)+(n-2) ; y(n)= (n)+(n-1)+(n-2)+ (n-3)


Enter the sequence x(n)
x=
1
2 3
Enter the time indices of x(n)
n1=
0 1
2
Enter the sequence y(n)
y=
1 2 3 4
'Enter the time indices of y(n)
n2=
0 1 2 3
The convolution of the given sequences is
1. 4. 10. 16. 17. 12.

Geethanjali College of Engineering & Technology

Page 90

Basic Simulation Lab

Department of ECE

2. Enter the sequence x(n)


x=
-1
2
3 -1
Enter the sequence y(n)
y=
2
5
4 -9
The convolution of the given sequences is
-2 -1 12 30 -11 -31
9
The Time index of the convolved sum is
n=
0 1 2 3 4 5

2.//This Program finds the convolution between two rectangular


Pulses of equal duration
f1=input('enter the sampling frequency of the first signal')
T1=1/f1;
t1=0:T1/f1:T1;
x1=zeros(1,length(t1));
j=input('enter the duration of the rectangular pulse in therms of
number of samples to included')
Geethanjali College of Engineering & Technology

Page 91

Basic Simulation Lab

Department of ECE

x1(1:j)=0.25;
f2=input('enter the sampling frequency of the second signal')
T2=1/f2;
t2=0:T2/f2:T2;
x2=zeros(1,length(t2));
k=input('enter the duration of the rectangular pulse in therms of
number of samples to included ')
x2(1:k)=0.5;
t=0:(t1(j)+t2(k))/(j+k):t1(j)+t2(k);
A=zeros(min(j,k),j+k-1);
if j<k
for i=1:j
A(i,i:i+k-1)=x2(1,1:k);
A(i,:)=x1(i).*A(i,:);
end
else
for i=1:k
A(i,i:i+j-1)=x1(1,1:j);
A(i,:)=x2(i).*A(i,:);
end
end
c=zeros(1,j+k-1);
for i=1:min(j,k)
c(1,:)=c(1,:)+A(i,:);
end
c(j+k)=0;
for i=length(c)+1:length(t)
c(i)=0;
end
subplot(3,1,1)
plot2d(t1,x1,style=5,rect=[0 min(x1) T1 max(x1)+0.5])
xtitle("", "time", "amplitude")
xgrid
legend('Rectangular Pulse with fs=1000,j=750')
subplot(3,1,2)
plot2d(t2,x2,style=5,rect=[0 min(x2) T2 max(x2)+0.5])
xtitle("", "time", "amplitude")
xgrid
legend('Rectangular Pulse with fs=1000,k=750')
subplot(3,1,3)
plot2d(t,c,style=5,rect=[0 0 max(t)+1000*((t1(j)+t2(k))/(j+k)) max(c)+25])
xtitle("", "time", "amplitude")

Geethanjali College of Engineering & Technology

Page 92

Basic Simulation Lab

Department of ECE

xgrid
legend('Convolution of rectangular pulses of same duration')

3.// Convolution between two rectangular Pulses of


unequal duration

Geethanjali College of Engineering & Technology

Page 93

Basic Simulation Lab

Department of ECE

CONCLUSION: In this experiment Linear convolution between signals/sequences


have been implemented.
Applications: Convolution is used to obtain the response of an LTI system to an
arbitrary input signal.
VIVA QUESTIONS:
1.Explain about the Graphical Interpreation of Convolution
2. What is the result of f(t)*(t).
3.If two sequences of length L amd M respectively are linearly convoled, what is the
length of the linearly convolved sum of the two sequences?
4. x(n) is extending from L to M and y(n) is extending from P to Q. Then, x(n)*y(n)
extends from ------------Exercise questions: perform convolution between the following signals
1. x(n)=[1 -1 4 ], h(n) = [ -1 2 -3 1]
2 x(t)=e-3t{u(t)-u(t-2)} , y(t)= e -3t for 0 t 2

Geethanjali College of Engineering & Technology

Page 94

Basic Simulation Lab

Department of ECE

EXP.NO: 6
AUTO CORRELATION AND CROSS CORRELATION BETWEEN SIGNALS
AND SEQUENCES.

Aim: To compute auto correlation and cross correlation between signals and sequences
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB/Scilab Software
Theory:
Correlations of sequences:
It is a measure of the degree to which two sequences are similar.
Cross correlation between two sequences x(n)and y(n) is defined as
rx , y (l )

x ( n) y ( n l )

The index l is called the shift or lag parameter


Autocorrelation is correlation of a signal with itself.
rx , x (l )

x (n) x (n l )

//This program finds the Auto/Cross Correlation between the


given
two sequences
**Cross correlation between two signals x(n) and y(n) is same as
convolution between x(n) and y(-n).
Cross Correlation:
x=input('Enter the sequence x(n)')
n1=input('Enter the time indices of x(n)')
y=input('Enter the sequence y(n)')
n2=input('Enter the time indices of y(n)')
n22=-flipdim(n2,2);
y1=flipdim(y,2);
n=min(n1)+min(n22):max(n1)+max(n22);
A=zeros(min(length(x),length(y1)),length(x)+length(y1)-1);
if length(x)<length(y1)
for i=1:length(x)
A(i,i:i+length(y1)-1)=y1(1,:);
Geethanjali College of Engineering & Technology

Page 95

Basic Simulation Lab

Department of ECE

A(i,:)=x(i).*A(i,:);
end
else
for i=1:length(y1)
A(i,i:i+length(x)-1)=x(1,:);
A(i,:)=y1(i).*A(i,:);
end
end
c=zeros(1,length(x)+length(y1)-1);
for i=1:min(length(x),length(y1))
c(1,:)=c(1,:)+A(i,:);
end
disp('The Cross correlation between the given sequences is')
disp(c)
disp('The Time index of the Cross correlation is')
disp(n)
subplot(3,1,1)
plot2d3(n1,x,style=-2,rect=[min(n1)-1 min(x)-1 max(n1)+1 max(x)+1])
xtitle("", "time", "amplitude")
xgrid
legend('Given sequence x(n)',2)
subplot(3,1,2)
plot2d3(n22,y1,style=-2,rect=[min(n22)-1 min(y1)-1 max(n22)+1
max(y1)+1])
xtitle("", "time", "amplitude")
xgrid
legend(' sequence y(-n)',3)
subplot(3,1,3)
plot2d3(n,c,style=-2,rect=[min(n)-1 min(c)-2 max(n)+1 max(c)+2])
xtitle("", "time", "amplitude")
xgrid
legend('Cross correlation of x(n) and y(n)',3)

1.Enter the sequence x(n)


x =1
3
5
7
Enter the time indices of x(n)
0 1
2
3
Enter the sequence y(n)
y =5
7
1
3
Enter the time indices of y(n)
0 1
2
3

Geethanjali College of Engineering & Technology

Page 96

Basic Simulation Lab

Department of ECE

The Time index of the Cross correlation is


- 3. - 2. - 1. 0. 1. 2. 3.
The Cross correlation of the given sequences is
3 10 25 52 57 74 35

2. Enter the sequence x(n)


x = -1 -2
0
5
Enter the time indices of x(n)
0 1
2
3
Enter the sequence y(n)
y = -5
2
0
1
Enter the time indices of y(n)
0 1
2
3
The Time index of the Cross correlation is
- 3. - 2. - 1. 0. 1. 2. 3.
The Cross correlation of the given sequences is
-1 -2 -2
6 10 10 -25

Geethanjali College of Engineering & Technology

Page 97

Basic Simulation Lab

Department of ECE

Auto Correlation:
**The correlation of a sequence with itself is referred to as Auto
correlation
**To find the Autocorrelation of a sequence x(n), in the above
program, in the place of y(n), enter x(n).
x=input('Enter the sequence x(n)')
n1=input('Enter the time indices of x(n)')
y=input('Enter the sequence y(n)=x(n)')
n2=input('Enter the time indices of y(n)=n1')
//y=x; n2=n1
n22=-flipdim(n2,2);
y1=flipdim(y,2);
n=min(n1)+min(n22):max(n1)+max(n22);
A=zeros(min(length(x),length(y1)),length(x)+length(y1)-1);
if length(x)<length(y1)
for i=1:length(x)
A(i,i:i+length(y1)-1)=y1(1,:);
A(i,:)=x(i).*A(i,:);
Geethanjali College of Engineering & Technology

Page 98

Basic Simulation Lab

Department of ECE

end
else
for i=1:length(y1)
A(i,i:i+length(x)-1)=x(1,:);
A(i,:)=y1(i).*A(i,:);
end
end
c=zeros(1,length(x)+length(y1)-1);
for i=1:min(length(x),length(y1))
c(1,:)=c(1,:)+A(i,:);
end
disp('The Autocorrelation of the given sequence x(n) is')
disp(c)
disp('The Time index of Auto correlation is')
disp(n)
subplot(3,1,1)
plot2d3(n1,x,style=-2,rect=[min(n1)-1 min(x)-1 max(n1)+1 max(x)+1])
xtitle("", "time", "amplitude")
xgrid
legend('Given sequence x(n)',2)
subplot(3,1,2)
plot2d3(n22,y1,style=-2,rect=[min(n22)-1 min(y1)-1 max(n22)+1
max(y1)+1])
xtitle("", "time", "amplitude")
xgrid
legend(' sequence x(-n)',3)
subplot(3,1,3)
plot2d3(n,c,style=-2,rect=[min(n)-1 min(c)-2 max(n)+1 max(c)+10])
xtitle("", "time", "amplitude")
xgrid
legend('Auto correlation of x(n)',2)
1.Enter the sequence x(n)
x =1
3
5
7
Enter the time indices of x(n)
0 1
2
3
Enter the sequence y(n)=x(n)
y=1
3
5
7
Enter the time indices of y(n)=n1
0 1
2
3
The Time index of the correlation is
- 3. - 2. - 1. 0. 1. 2. 3.

Geethanjali College of Engineering & Technology

Page 99

Basic Simulation Lab

Department of ECE

The Autocorrelation of the given sequence x(n) is


7. 26. 53. 84. 53. 26. 7.

//This program finds the Auto/Cross Correlation between the


given
two Sinusoidal signals
Cross Correlation:
f1=input('enter the frequency of signal1')
T1=1/f1;
t1=0:T1/f1:T1;
x=sin(2*%pi*f1*t1);
f2=input('enter the frequency of signal2')
T2=1/f2;
t2=0:T2/f2:T2;
y=sin(2*%pi*f2*t2);
t22=-flipdim(t2,2);
y1=flipdim(y,2);
A=zeros(min(length(x),length(y1)),length(x)+length(y1)-1);
if length(x)<length(y1)
for i=1:length(x)
Geethanjali College of Engineering & Technology

Page 100

Basic Simulation Lab

Department of ECE

A(i,i:i+length(y1)-1)=y1(1,:);
A(i,:)=x(i).*A(i,:);
end
else
for i=1:length(y1)
A(i,i:i+length(x)-1)=x(1,:);
A(i,:)=y1(i).*A(i,:);
end
end
c=zeros(1,length(x)+length(y1)-1);
for i=1:min(length(x),length(y1))
c(1,:)=c(1,:)+A(i,:);
end
t=linspace(min(t1)+min(t22),max(t1)+max(t22),length(c));
subplot(3,1,1)
plot2d3(t1,x,style=-2,rect=[min(t1) -1.1 max(t1) 1.1])
xtitle("", "time", "amplitude")
xgrid
legend('Given signal x(t) with f=100')
subplot(3,1,2)
plot2d3(t22,y1,style=-2,rect=[min(t22) min(y1)-0.1 max(t22)
max(y1)+0.1])
xtitle("", "time", "amplitude")
xgrid
legend(' signal y(-t) with f=150',2)
subplot(3,1,3)
plot2d3(t,c,style=-2,rect=[min(t) min(c)-5 max(t) max(c)+5])
xtitle("", "time", "amplitude")
xgrid
legend('Cross correlation of x(t) and y(t)',2)

Geethanjali College of Engineering & Technology

Page 101

Basic Simulation Lab

Department of ECE

Auto Correlation:
**The correlation of a signal with itself is referred to as Auto
correlation
**To find the Autocorrelation of a signal x(t), in the above program,
in the place of y(t), enter x(t).
f1=input('enter the frequency of signal1')
T1=1/f1;
t1=0:T1/f1:T1;
x=sin(2*%pi*f1*t1);
f2=input('enter the frequency of signal2=f1')
T2=1/f2;
t2=0:T2/f2:T2;
y=sin(2*%pi*f2*t2);
t22=-flipdim(t2,2);
y1=flipdim(y,2);
A=zeros(min(length(x),length(y1)),length(x)+length(y1)-1);
Geethanjali College of Engineering & Technology

Page 102

Basic Simulation Lab

Department of ECE

if length(x)<length(y1)
for i=1:length(x)
A(i,i:i+length(y1)-1)=y1(1,:);
A(i,:)=x(i).*A(i,:);
end
else
for i=1:length(y1)
A(i,i:i+length(x)-1)=x(1,:);
A(i,:)=y1(i).*A(i,:);
end
end
c=zeros(1,length(x)+length(y1)-1);
for i=1:min(length(x),length(y1))
c(1,:)=c(1,:)+A(i,:);
end
t=linspace(min(t1)+min(t22),max(t1)+max(t22),length(c));
subplot(3,1,1)
plot2d(t1,x,style=5,rect=[min(t1) -1.1 max(t1) 1.1])
xtitle("", "time", "amplitude")
xgrid
legend('Given signal x(t) with f=100')
subplot(3,1,2)
plot2d(t22,y1,style=5,rect=[min(t22) min(y1)-0.1 max(t22) max(y1)+0.1])
xtitle("", "time", "amplitude")
xgrid
legend(' signal x(-t)',2)
subplot(3,1,3)
plot2d(t,c,style=5,rect=[min(t) min(c)-5 max(t) max(c)+5])
xtitle("", "time", "amplitude")
xgrid
legend('Auto correlation of x(t)',2)

Geethanjali College of Engineering & Technology

Page 103

Basic Simulation Lab

Department of ECE

CONCLUSION: In this experiment correlation(Auto/Cross) between signals/sequences


have been implemented .
Applications: 1. Autocorrelation of a signal is used to find the Mean square value of a
signal.
2.Autocorrelation is used in signal estimation in the presence of Noise.
VIVA QUESTIONS
1.For what value of lag , Auto correlation of a signal is maximum and cross
correlation
of two signals is minimum.
2.Define Power spectral density of a signal. How it is related to Autocorrelation of the
Signal?
3.What is the symmetry possessed by Auto correlation function of a signal?
4.What is the relation between cross correlation Rxy() and Ryx()?

EXP.NO: 7
VERIFICATION OF LINEARITY AND TIME INVARIANCE PROPERTIES OF
A GIVEN CONTINUOUS /DISCRETE SYSTEM.

Geethanjali College of Engineering & Technology

Page 104

Basic Simulation Lab

Department of ECE

Aim: To compute linearity and time invariance properties of a given continuous


/discrete system
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB/Scilab Software
THEORY:
LINEARITY PROPERTY :
Any system is said to be linear if it satisfies the superposition principal
superposition principal state that Response to a weighted sum of input signal equal to
the corresponding weighted sum of the outputs of the system to each of the individual
input signals

Linearity:
//This program checks the given system represented by its
difference equation for Linearity
a=input('enter the coefficient vector of input starting from the
coefficient of x(n) term')
b=input('enter the coefficient vector of output starting from the
coefficient of y(n) term')
x1=rand(1,10);
x2=rand(1,10);
i=input('enter the amplitude scaling factor for x1(n)')
j=input('enter the amplitude scaling factor for x2(n)')
h1=filter(a,b,i*x1);
h2=filter(a,b,j*x2);
h=h1+h2;
h3=filter(a,b,i*x1+j*x2);
error=max(abs(h-h3));
//The limited numerical precision of MATLAB is %eps = 2.220D-16
if error<%eps
disp('The system is linear')
else
disp('The system is non-linear')
end

Geethanjali College of Engineering & Technology

Page 105

Basic Simulation Lab

Department of ECE

y = filter(b,a,X) filters the data in vector X with the filter described


by numerator coefficient vector b and denominator coefficient
vector a

1) The system is represented as y(n)=x(n)+x(n-1).


enter the coefficient vector of input starting from the coefficient of x(n)
term
a =1
1
enter the coefficient vector of output starting from the coefficient of
y(n) term
b =1
enter the amplitude scaling factor for x1(n)
i =2
enter the amplitude scaling factor for x2(n)
j =3
The system is linear

2)The system is represented as y(n)=x2(n)


a=input('enter the coefficient vector of input starting from the
coefficient of x(n) term')
b=input('enter the coefficient vector of output starting from the
coefficient of y(n) term')
x1=rand(1,10);
x2=rand(1,10);
i=input('enter the amplitude scaling factor for x1(n)')
j=input('enter the amplitude scaling factor for x2(n)')
h1=filter(a,b,(i*x1).^2);
h2=filter(a,b,(j*x2).^2);
h=h1+h2;
h3=filter(a,b,(i*x1+j*x2).^2);
error=max(abs(h-h3));
if error<%eps
disp('The system is linear')
else
disp('The system is non-linear')
end
enter the coefficient vector of input starting from the coefficient of x(n)
term
Geethanjali College of Engineering & Technology

Page 106

Basic Simulation Lab

Department of ECE

a =1
enter the coefficient vector of output starting from the coefficient of
y(n) term
b =1
enter the amplitude scaling factor for x1(n)
i =2
enter the amplitude scaling factor for x2(n)
j =3
The system is non-linear
rand(m1,m2,uniform) - generates arrays of random numbers
whose elements are uniformly distributed in the interval (0,1).
Time Invariance:

//This program checks the given system for Time invariance


a=input('enter the coefficient vector of input starting from the
coefficient of x(n) term')
b=input('enter the coefficient vector of output starting from the
coefficient of y(n) term')
n=input('enter the duration of the input')
k=input('enter the amount of shift i.e a number between 1 and n
required for the input')
x=rand(1,n);
x1=[x zeros(1,k)];
x2=[zeros(1,k) x];
y1=filter(a,b,x1);
y2=filter(a,b,x2);
y11=[zeros(1,k) y1];
y11(length(y2)+1:length(y11))=[];
error=max(abs(y2-y11));
if error==0
disp('The system is Time invariant')
else
disp('The system is not Time Invariant')
end
1. The system is y(n)= x(n)-3x(n-1)+x(n-2)
enter the coefficient vector of input starting from the coefficient of x(n)
term
Geethanjali College of Engineering & Technology

Page 107

Basic Simulation Lab

Department of ECE

a =1 -3
1
'enter the coefficient vector of output starting from the coefficient of
y(n) term'
b =1
enter the duration of the input
n =10
'enter the amount of shift i.e a number between 1 and n required for
the input'
k =1
The system is Time invariant
2.The system is y(n)=0.9y(n-1)+x(n)
enter the coefficient vector of input starting from the coefficient of x(n)
term
a =1
enter the coefficient vector of output starting from the coefficient of
y(n) term
b =1

-0.9

enter the duration of the input


n = 10
'enter the amount of shift i.e a number between 1 and n required for
the input'
k =2

The system is

Time Invariant

3. The Given system is y(n)= n.x(n)


i=input('enter the duration of the input')
k=input('enter the amount of shift i.e a number between 1 and n
required for the input')
x=rand(1,i);
n=1:i;
n1=n;
y=n.*x;
x1=[zeros(1,k) x];
n1(length(n)+1:length(x1))=0;
y1=n1.*x1;
n=[zeros(1,k) n];
y2=n.*x1;
error=max(abs(y1-y2));
if error==0
disp('The system is Time invariant')
else

Geethanjali College of Engineering & Technology

Page 108

Basic Simulation Lab

Department of ECE

disp('The system is not Time Invariant')


end
The given system is not Time Invariant

RESULT:- Various discrete systems are checked for Linearity and Time
Invariance.
VIVA QUESTIONS
1.Define the Principle of Homogeneity of a system.
2. Is the system y(n)=n2.x(n) (i) Linear (ii) Time invariant
EXP.NO:8
COMPUTATION OF UNIT SAMPLE, UNIT STEP AND SINUSOIDAL
RESPONSE OF THE GIVEN LTI SYSTEM AND VERIFYING ITS PHYSICAL
REALIZABILITY AND STABILITY PROPERTIES.
Aim: To Unit Step And Sinusoidal Response of the given LTI System And Verifying Its
Physical Realizability And Stability Properties.
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB/Scilab Software
A system performs an operation on an input signal based on predefined criteria to
produce a modified output signal. The input signal x(n) is the system excitation, and
y(n) is the system response. The transform operation is shown as,

If the input to the system is unit impulse i.e. x(n) = (n), Sin(won) and Step sequence ,
the respective outputs of the system are referred to as Impulse response, Sinusoidal
Response and Step Response respectively
Computation of Unit Sample response :
//This program finds the unit sample response of the given
discrete
system

Geethanjali College of Engineering & Technology

Page 109

Basic Simulation Lab

Department of ECE

a=input('enter the coefficient vector of input starting from the


coefficient of x(n) term')
b=input('enter the coefficient vector of output starting from the
coefficient of y(n) term')
n1=input('enter the lower limit of the range of impulse response')
n2=input('enter the upper limit of the range of impulse response')
n=[n1:n2];
x=zeros(1,length(n));
i=find(n==0);
x(i)=1;
h=filter(a,b,x);
plot2d3(n,h,style=-4,rect=[n1 min(h)-1 n2 max(h)+1])
xtitle("", "time", "amplitude")
xgrid
legend('Unit Sample response of the given discrete system y(n)-y(n1)+0.9y(n-2)=x(n)')

Computation of Unit Step response :


//This program finds the unit step response of the given discrete
Geethanjali College of Engineering & Technology

Page 110

Basic Simulation Lab

Department of ECE

system
a=input('enter the coefficient vector of input starting from the
coefficient of x(n) term')
b=input('enter the coefficient vector of output starting from the
coefficient of y(n) term')
n1=input('enter the lower limit of the range of impulse response')
n2=input('enter the upper limit of the range of impulse response')
n=[n1:n2];
x=zeros(1,length(n));
i=find(n==0);
x(i:length(x))=1;
h=filter(a,b,x);
plot2d3(n,h,style=-4,rect=[n1 min(h)-1 n2 max(h)+1])
xtitle("", "time", "amplitude")
xgrid
legend('Unit Step response of the given discrete system y(n)-y(n1)+0.9y(n-2)=x(n)')

Computation of Sinusoidal response :


//This program finds the Sinusoidal response of the given discrete
Geethanjali College of Engineering & Technology

Page 111

Basic Simulation Lab

Department of ECE

system
a=input('enter the coefficient vector of input starting from the
coefficient of x(n) term')
b=input('enter the coefficient vector of output starting from the
coefficient of y(n) term')
f=input('enter the sampling frequency')
T=1/f;
t=0:T/f:T;
x=sin(2*%pi*f*t);
h=filter(a,b,x);
subplot(2,1,1)
plot2d3(t,x,style=-4,rect=[0 min(x)-1 T max(x)+1])
xtitle("", "time", "amplitude")
xgrid
legend('Sinusoidal input(f=50) for the discrete system y(n)-y(n1)+0.9y(n-2)=x(n)')
subplot(2,1,2)
plot2d3(t,h,style=-4,rect=[0 min(x)-1 T max(x)+1])
xtitle("", "time", "amplitude")
xgrid
legend('Sinusoidal(f=50) response of the discrete system y(n)-y(n1)+0.9y(n-2)=x(n)')

Geethanjali College of Engineering & Technology

Page 112

Basic Simulation Lab

Department of ECE

Verifying the physical realizability and Staility of the given discrete


system
For a system to be physically realizable, it must be causal.
This can be checked as
The unit impulse response h(t)<0 for t<0.
A system is said to be BIBO stable, if every bounded input results in a
bounded output. Foe BIBO stable system, the impulse response must be
absolutely integrable/summable.
//This program checks the given discrete system for its physical
realizability and Stability
a=input('enter the coefficients of numerator in the order of decreasing
order of the variable z')
b=input('enter the coefficients of denominator in the order of decreasing
order of the variable z')
p=roots(a);
q=roots(b);
i=find(abs(q)<1);

Geethanjali College of Engineering & Technology

Page 113

Basic Simulation Lab

Department of ECE

R1=input('enter the lower bound of ROC')


R2=input('enter the upper bound of ROC')
if length(p)<=length(q) & R2==%inf
disp('The system is causal')
else
disp('The system is not causal')
end
if R1<1&R2>1 | length(i)==length(q)
disp('The system is stable')
else
disp('The system is unstable')
end
1.H(z)=z/(3z2-4z+1) ROC |z|>1
enter the coefficients of numerator in the order of decreasing order of
the variable z
a =1
0
enter the coefficients of denominator in the order of decreasing order of
the variable z
b=3 -4
1
enter the lower bound of ROC
R1 =1
enter the upper bound of ROC
R2 =Inf
The system is causal. The system is unstable
2.H(z)=z/(3z2-4z+1) ROC 1/3<|z|<1
enter the coefficients of numerator in the order of decreasing order of
the variable z
a =1
0
enter the coefficients of denominator in the order of decreasing order of
the variable z
b=3 -4
1
enter the lower bound of ROC
R1 =1/3
enter the upper bound of ROC
R2 =1
The system is not causal. The system is unstable
3.H(z)= (z2-1.5z)/[z2-(5/6)z+1/6] ROC |z|>0.5
enter the coefficients of numerator in the order of decreasing order of
the variable z
a =1.0000 -1.5000
0

Geethanjali College of Engineering & Technology

Page 114

Basic Simulation Lab

Department of ECE

enter the coefficients of denominator in the order of decreasing order of


the variable z
b =1.0000 -0.8333 0.1667
enter the lower bound of ROC
R1 =0.5000
enter the upper bound of ROC
R2 =inf. The system is causal. The system is stable
4.H(z)= (z2-1.5z)/(z2-(5/6)z+1/6) ROC 1/3< |z|<0.5
enter the coefficients of numerator in the order of decreasing order of
the variable z
a =1.0000 -1.5000
0
enter the coefficients of denominator in the order of decreasing order of
the variable z
b =1.0000 -0.8333 0.1667
enter the lower bound of ROC
R1 =1/3
enter the upper bound of ROC
R2 =0.5. The system is not causal. The system is stable
5. H(z)=[2z2-2.5z]/[z2-2.5z+1] ROC 0.5<z<2
The system is not causal. The system is stable
**A Discrete LTI system with a rational system function H(z) is
causal if the ROC is exterior of a circle with a radius equal to the
outermost pole i.e ROC should include Infinity i.e.

This is satisfied if H(z) does not have the order of the numerator is
not greater than that of the denominator
**A Discrete LTI system is stable if and only if the ROC of the
system function includes the unit circle, i.e.|z|=1
**For a causal system to be stable, all the poles must lie within the
unit circle.
CONCLUSION: In this experiment computation of unit sample, unit step and
sinusoidal response of the given LTI system is implemented and the given systems are
checked for their physical realizability and stability.
Geethanjali College of Engineering & Technology

Page 115

Basic Simulation Lab

Department of ECE

VIVA QUESTIONS
1.Why Ideal LPF is not physically realizable?
2.What is Paley-wiener criterion?
3.For discrete system to be BIBO stable, what is the condition to be satisfied by its unit
sample response?

EXP.NO: 9
GIBBS PHENOMENON
Aim: To verify the Gibbs Phenomenon.
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB/Scilab Software
Consider the approximation of symmetric rectangular pulse defined as
by a single function sint.
The approximation improves when a large number of mutually orthogonal functions are
used.
The functions
are mutually orthogonal over
.
The given rectangular pulse is now approximated by a finite series of sinusoidal
functions:

The constant

=
The approximation is given by

The approximation will be better as the number of sinusoids used for


approximation increases.
//This program verifies Gibb's Phenomenon

Geethanjali College of Engineering & Technology

Page 116

Basic Simulation Lab

Department of ECE

f=input('enter the sampling frequency')


T=input('enter the duration over which the wave is to be plotted')
t=linspace(0,T,f);
p=zeros(1,length(t));
q=p;
for i=1:length(t)/2
p(i)=1;
p(i+(length(t)/2))=-1;
end
n=input('enter the number of sinusoids')
for i=0:n-1
k=1/(2*i+1);
for j=1:length(t)
q(j)=(q(j)+(4/%pi)*k*sin((1/k)*t(j)));
end
end
plot(t,p,'r',t,q,'k')
xlabel("time")
ylabel("Amplitude")
legend(["Rectangular Pulse","Sinusoidal Signals"])
title('f=1000 and Number of Sinusoids=')
mtlb_axis([0 6 -2 2])
enter the sampling frequency 1000
enter the duration over which the wave is to be plotted
enter the number of sinusoids 1

Geethanjali College of Engineering & Technology

2*%pi

Page 117

Basic Simulation Lab

Department of ECE

enter the sampling frequency 1000


enter the duration over which the wave is to be plotted
enter the number of sinusoids 2

2*%pi

enter the sampling frequency 1000


enter the duration over which the wave is to be plotted
enter the number of sinusoids 3

2*%pi

enter the sampling frequency 1000


enter the duration over which the wave is to be plotted
enter the number of sinusoids 6

2*%pi

Geethanjali College of Engineering & Technology

Page 118

Basic Simulation Lab

Department of ECE

enter the sampling frequency 1000


enter the duration over which the wave is to be plotted
enter the number of sinusoids 10

2*%pi

enter the sampling frequency 1000


enter the duration over which the wave is to be plotted
enter the number of sinusoids 15

2*%pi

Geethanjali College of Engineering & Technology

Page 119

Basic Simulation Lab

Department of ECE

enter the sampling frequency 1000


enter the duration over which the wave is to be plotted
enter the number of sinusoids 25

2*%pi

enter the sampling frequency 1000


enter the duration over which the wave is to be plotted
enter the number of sinusoids 50

2*%pi

Geethanjali College of Engineering & Technology

Page 120

Basic Simulation Lab

Department of ECE

enter the sampling frequency 1000


enter the duration over which the wave is to be plotted
enter the number of sinusoids 100

2*%pi

enter the sampling frequency 1000


enter the duration over which the wave is to be plotted
enter the number of sinusoids 500

2*%pi

Geethanjali College of Engineering & Technology

Page 121

Basic Simulation Lab

Department of ECE

CONCLUSION: Gibbs phenomenon have been verified


VIVA QUESTIONS
1. What are Dirchlet Condition
2. Define Fourier Series
3. What is Half Wave Symmetry

EXP.NO: 10
Geethanjali College of Engineering & Technology

Page 122

Basic Simulation Lab

Department of ECE

FINDING THE FOURIER TRANSFORM OF A GIVEN SIGNAL AND


PLOTTING ITS MAGNITUDE AND PHASE SPECTRUM
Aim: To find the Fourier transform of a given signal and plotting its magnitude and
phase spectrum
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB/Scilab Software
Fourier Transform of signal f(t) is defined as

//This program finds the Fourier Transform of exp(-At)


//Defining the Time domain signal x(t)=exp(-At)
A=input('enter the constant of decay')
T=input('nter the increment for time axis')
T1=input('enter the upper bound for time axis')
t=0:T:T1;
x=exp(-A*t);
//Defining the Omega Axis
f=input('enter the analog frequency')
B=4; //a random integer
b=0:B/1000:B;
w=b*2*%pi*f/B;
//Defining Fourier Transform
ft=x*exp(-%i*t'*w)*T;
//Magnitude of Fourier Transform
a=abs(ft);
//computing phase spectrum
[phase dB]=phasemag(ft);
W=[-mtlb_fliplr(w) w(2:length(w))];
FT=[mtlb_fliplr(a) a(2:length(a))]
phase_plot=[-mtlb_fliplr(phase) phase(2:length(w))]
subplot(3,1,1))
plot2d(t,x,style=-4,rect=[min(t) min(x) max(t) max(x)])
xgrid
xtitle('The given exponential signal with
A=1,T=0.005,T1=5',"t","Amplitude")
Geethanjali College of Engineering & Technology

Page 123

Basic Simulation Lab

Department of ECE

subplot(3,1,2)
plot2d(W,FT,style=-4,rect=[min(W)-3.5 min(FT)-0.01 max(W)+3.5
max(FT)+0.01])
xgrid
xtitle('Magnitude Spectrum with f=1',"W","Magnitude")
subplot(3,1,3)
plot2d(W,phase_plot*%pi/180,style=-4,rect=[min(W) min(phase_plot*
%pi/180) max(W) max(phase_plot*%pi/180)])
xgrid
xtitle('Phase Spectrum ',"W","phase")

Geethanjali College of Engineering & Technology

Page 124

Basic Simulation Lab

Department of ECE

[phi,db]=phasemag(z [,mod])
Arguments
z -matrix or row vector of complex numbers.
mod -character string
mod='c' - "continuous" representation between -infinity and
+360 degrees (default)
mod='m' -representation between -360 and 0 degrees
phi - phases (in degree) of z.
db -magnitude (in Db)
Description:
computes the phases and magnitudes of the entries of
a complex matrix.
phasemag

To obtain the phase between -%pi and %pi, use phi=atan(imag(z),real(z))


CONCLUSION: In this experiment the Fourier transform of a given signal and plotting
its magnitude and phase spectrum have been demonstrated using MATLAB.
VIVA QUESTIONS
1.What is the relation between Fourier Series and Fourier Transform?
2. What is the condition for a signal to have Fourier Transform?
3.How to find the area enclosed by f(t), from its Fourier Transform?
Geethanjali College of Engineering & Technology

Page 125

Basic Simulation Lab

Department of ECE

Use of Symbolic Mathematics in MATLAB:


sym Function: It is used to create a symbolic number, variable and
object. The syntax is x=sym(x).This creates the symbolic variable with
name x and stores the result in x.
syms Function: It is the shortcut for constructing a number of
symbolic objects. The syntax is syms arg1 arg2 arg3. For example,
syms p q r
creates three symbolic objects p, q, r. It is similar to three sym
functions as syms p, syms q, syms r.
Example:
1.X=sqrt(20)
ans =
4.4721
When expressed as symbolic object,
X=sqrt(sym(10))
ans =
10^(1/2)
2. sym t
ans =
t
Geethanjali College of Engineering & Technology

Page 126

Basic Simulation Lab

Department of ECE

x=sin(t);
diff(x)
This command takes the derivative of x with respect to variable t as
there is only one variable t in the expression.
ans =
cos(t)
diff(x,2)
This command takes the second derivative of x with respect to t.
ans =
-sin(t)

Exp:11
WAVEFORM SYNSTHESIS
Aim: To perform waveform synthesis using Laplace Transforms of a given signal
Bilateral Laplace transform :
The bilateral Laplace transform is defined as follows:

%This program find the laplace transform of the given function f(t)
syms t
ft=input('define the function')
fs=laplace(ft);
disp('The laplace Transform of the given function f(t) is')
disp(fs)

Geethanjali College of Engineering & Technology

Page 127

Basic Simulation Lab

Department of ECE

1. f(t)= (-4/3)e-t+(1/3)e2t.
define the function
ft =
-4/3*exp(-t)+1/3*exp(2*t)
The laplace Transform of the given function f(t) is
-4/3/(s+1)+1/3/(s-2) i.e. (4/3).(1/(s+1))+(1/3).(1/(s-2)).
2. f(t)=t2.sin(t).
define the function
ft =
t^2*sin(t)
The laplace Transform of the given function f(t) is
2/(s^2+1)^3*(-1+3*s^2).
3. f(t)=t2.e-2t.
define the function
ft =
t^2*exp(-2*t)
The laplace Transform of the given function f(t) is
2/(s+2)^3
4. f(t)=3e-2t-2e-t.
define the function
ft =
3*exp(-2*t)-2*exp(-t)
The laplace Transform of the given function f(t) is
3/(s+2)-2/(s+1)
5. define the function
ft = dirac(t)
The laplace Transform of the given function f(t) is 1
%This program finds the inverese laplace transform of given F(s)
syms s t;
fs=input('enter the Laplace Tranform ')
ft=ilaplace(fs);
disp('The inverse laplace Transform of the given F(s) is')
disp(ft)
1.enter the Laplace Transform
fs =
Geethanjali College of Engineering & Technology

Page 128

Basic Simulation Lab

Department of ECE

1/(s+4)
The inverse laplace Transform of the given F(s) is
exp(-4*t)
2.enter the Laplace Transform
fs =
36/(s^2+3*s+36)
The inverse laplace Transform of the given F(s) is
8/5*15^(1/2)*exp(-3/2*t)*sin(3/2*15^(1/2)*t)
3.enter the Laplace Transform
fs = (2*s^2+5*s+12)/(s^2+2*s+10)/(s+2)
The inverse laplace Transform of the given F(s) is
exp(-t)*cos(3*t)+exp(-2*t)
4. enter the Laplace Transform
fs = 1/s
The inverse laplace Transform of the given F(s) is 1
5. enter the Laplace Transform
fs = 1/s^3
The inverse laplace Transform of the given F(s) is 1/2*t^2

Waveform synthesis
//(i)This program performs the wave form synthesis of a stair case
waveform
f=input('enter the sampling frequency')
T=1/f;
L=input('enter the lower bound for the time axis')
Geethanjali College of Engineering & Technology

Page 129

Basic Simulation Lab

Department of ECE

U=input('enter the upper bound for the time axis')


t=L:T:U;
x=zeros(1,length(t));
y=x;
for i=find(t==0):find(t==1)
x(i)=1;
end
x(find(t==1))=0;
for i=find(t==1):find(t==2)
x(i)=2;
end
x(find(t==2))=0;
for i=find(t==2):find(t==3)
x(i)=3;
end
z=find(dif(x)==1);
y(z(1)+1:length(y))=1;
subplot(4,1,1)
plot2d2(t,x,style=5,rect=[L min(x) U max(x)+1])
xtitle("","time","Amplitude")
legend('u(t)+u(t-1)+u(t-2) with f=1000;L=-1;U=3')
xgrid
subplot(4,1,2)
plot2d2(t,y,style=5,rect=[L min(y) U max(y)+1])
xtitle("","time","Amplitude")
legend('The First Constituent Step Function')
xgrid
y=y-y;
y(z(2)+1:length(y))=1;
subplot(4,1,3)
plot2d2(t,y,style=5,rect=[L min(y) U max(y)+1])
xtitle("","time","Amplitude")
legend('The Second Constituent Step Function')
xgrid
y=y-y;
y(z(3)+1:length(y))=1;
subplot(4,1,4)
plot2d2(t,y,style=5,rect=[L min(y) U max(y)+1])
xtitle("","time","Amplitude")
legend('The Third Constituent Step Function')
xgrid

Geethanjali College of Engineering & Technology

Page 130

Basic Simulation Lab

Department of ECE

(ii) x(t)=2u(t)-3u(t-2)+2u(t-4)
f=input('enter the sampling frequency')
T=1/f;
L=input('enter the lower bound for the time axis <0')
U=input('enter the upper bound for the time axis>4')
t=L:T:U;
x=zeros(1,length(t));
y=x;
for i=find(t==0):find(t==2)
x(i)=2;
end
x(find(t==2))=0;
for i=find(t==2):find(t==4)
x(i)=-3;
end
x(find(t==4))=0;
for i=find(t==4):find(t==U)
x(i)=2;
end
z=find(dif(x)==2);
y(z(1)+1:length(y))=2;
subplot(4,1,1)
Geethanjali College of Engineering & Technology

Page 131

Basic Simulation Lab

Department of ECE

plot2d2(t,x,style=5,rect=[L min(x)-1 U max(x)+1])


xtitle("","time","Amplitude")
legend('2u(t)-3u(t-2)+2u(t-4) with f=1000,L=-1,U=6')
xgrid
subplot(4,1,2)
plot2d2(t,y,style=5,rect=[L min(y) U max(y)+1])
xtitle("","time","Amplitude")
legend('The First Constituent Step Function')
xgrid
y=y-y;
z=find(dif(x)==-5);
y(z(1)+1:length(y))=-5;
subplot(4,1,3)
plot2d2(t,y,style=5,rect=[L min(y)-1 U max(y)])
xtitle("","time","Amplitude")
legend('The Second Constituent Step Function')
xgrid
y=y-y;
z=find(dif(x)==5);
y(z(1)+1:length(y))=5;
subplot(4,1,4)
plot2d2(t,y,style=5,rect=[L min(y) U max(y)+1])
xtitle("","time","Amplitude")
legend('The Third Constituent Step Function',2)
xgrid

(iii) x(t)=r(t)-2r(t-1)+r(t-2)
Geethanjali College of Engineering & Technology

Page 132

Basic Simulation Lab

Department of ECE

f=input('enter the sampling frequency')


T=1/f;
U=input('enter the upper bound for the time axis')
t=0:T:U;
//Finding the first Constitutent Ramp
x=t;
//Finding the second constitutent Ramp
y=zeros(1,length(t));
z=y;
i=find(t==1);
j=length(i:length(t));
y(i:i+j-1)=2*x(1:j)
//Finding the third consrtitutent Ramp
i=find(t==2);
j=length(i:length(t));
z(i:i+j-1)=x(1:j);
subplot(2,2,1)
plot2d(t,x-y+z,rect=[0 0 U 1])
xtitle('x(t)=r(t)-2r(t-1)+r(t-2) with fs=10 and U=3')
xlabel('time')
ylabel('Amplitude')
xgrid
subplot(2,2,2)
plot2d(t,x,rect=[0 0 U 1])
xtitle('Plot of the first constituent ramp signal')
xlabel('time')
ylabel('Amplitude')
xgrid
subplot(2,2,3)
plot2d(t,-y,rect=[0 min(-y) U max(y)])
xtitle('Plot of the second constituent ramp signal')
xlabel('time')
ylabel('Amplitude')
xgrid
subplot(2,2,4)
plot2d(t,z,rect=[0 0 U 1])
xtitle('Plot of the Third constituent ramp signal')
xlabel('time')
ylabel('Amplitude')
xgrid

Geethanjali College of Engineering & Technology

Page 133

Basic Simulation Lab

Department of ECE

CONCLUSION: In this experiment Laplace Transforms of various signals was


computed and wave form synthesis was implemented.
Applications of Laplace transforms:
1. Derive the circuit (differential) equations in the time domain, then transform
these ODEs to the s-domain;
2. Transform the circuit to the s-domain, then derive the circuit equations in the sdomain (using the concept of "impedance").The main idea behind the Laplace
Transformation is that we can solve an equation (or system of equations)
containing differential and integral terms by transforming the equation in "tspace" to one in "s-space". This makes the problem much easier to solve.
3. VIVA QUESTIONS
1. Define Laplace-Transform
2. What is the Condition for Convergence of the L.T
Geethanjali College of Engineering & Technology

Page 134

Basic Simulation Lab

Department of ECE

3. What is the Region of Convergence(ROC)


4. State the Shifting property of L.T
5. State convolution Property of L.T

Polynomials in Scilab.
Polynomials can be defined by specifying their (i) roots (ii)
coefficients.
Ex.
(i)p=poly([3 4], x,roots)
p=12-7x+x2
(ii) p=poly([1 2],x,coeff)
p= 1+2x.
**In the above poly, x represents the variable/symbol which is
verified by varn() command.
varn(p) gives the answer as x.
**The variable x can be replaced by another variable as varn(p,s).
The resulting polynomial will be in terms of s.
p=poly([1 2 3 4 5],"x", "coeff")
p =
2
3
4
1 + 2x + 3x + 4x + 5x
varn(p,"s")
ans =
2
3
4
1 + 2s + 3s + 4s + 5s
**coeff(p) will give the coefficients of the polynomial p.

Geethanjali College of Engineering & Technology

Page 135

Basic Simulation Lab

Department of ECE

coeff(p)
ans =
1.

2.

3.

4.

5.

**The coefficient can be extracted separately by referring to the


index
coeff(p,4)
ans =5
** Polynomial Matrix
x=poly(0,'s')
x =s
-->p=[1 x; x x^2]
p =
1

2
s

**Derivative of a polynomial.
x=poly(0,'s')
x =s
derivat(x^2)
ans = 2s
**Integration of a polynomial.
x=integrate(expr,v,x0,x1)

Arguments
expr =Character string defining a Scilab expression.
v =Character string, the integration variable name
x0 =real number, the lower bound of integration
x1 =vector of real numbers, upper bounds of integration

Geethanjali College of Engineering & Technology

Page 136

Basic Simulation Lab

Department of ECE

x =vector of real numbers, the integral value for each x1(i).

&&&&&&&&

EXP.NO:12
LOCATING THE ZEROS AND POLES AND PLOTTING THE POLE ZERO
MAPS IN S-PLANE AND Z-PLANE FOR THE GIVEN TRANSFER FUNCTION.
Aim: Pplotting the pole zero maps in s-plane and z-plane for the given transfer function
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB/Scilab Software
Z-transforms
the Z-transform converts a discrete time-domain signal, which is a sequence of real or
complex numbers, into a complex frequency-domain representation. The Z-transform,
like many other integral transforms, can be defined as either a one-sided or two-sided
transform.
Bilateral Z-transform
The bilateral or two-sided Z-transform of a discrete-time signal x[n] is the function X(z)
defined as

Unilateral Z-transform

Geethanjali College of Engineering & Technology

Page 137

Basic Simulation Lab

Department of ECE

Alternatively, in cases where x[n] is defined only for n 0, the single-sided or


unilateral Z-transform is defined as

In signal processing, this definition is used when the signal is causal.

The roots of the equation P(z) = 0 correspond to the 'zeros' of X(z)


The roots of the equation Q(z) = 0 correspond to the 'poles' of X(z)
Consider the Transfer Function H(z) given as

PROGRAM:- ZEROS AND POLES IN S- PLANE


** s=poly(0,"s") is the seed for defining polynomials with symbol "s".
**Define the system Transfer function as a ratio of numerator(n) and
denominator(d) polynomials using h=syslin(dom,n,d), where dom is
the character string c-for continuous stem; d-for discrete system;
n-for sampled system with sampling period n
**plzr(h) will give the pole-zero plot of the system.
//This program finds the poles and zeros of the given H(s) and
gives the pole-zero plot in S-Plane
s=poly(o,s);
a=input('enter the numerator Polynomial)
b=input('enter the denominator Polynomial))
z=roots(a);
p=roots(b);
Geethanjali College of Engineering & Technology

Page 138

Basic Simulation Lab

Department of ECE

disp('The poles of the given H(s) are')


disp(p)
disp('The zeros of the given H(s)are')
disp(z)
h=syslin(c, a, b)
plzr(h)
1.H(s)= (s2+5s+4)/(s2+8s+12)
enter the numerator coefficients as a vector in the order of decreasing
powers of s
a=
2
4 + 5s + s
enter the denominator coefficients as a vector in the order of decreasing
powers of s
b=
2
12 + 8s + s
The poles of the given H(s) are
-6
-2
The zeros of the given H(s) are
-4
-1

Geethanjali College of Engineering & Technology

Page 139

Basic Simulation Lab

Department of ECE

2. H(s)= (s2+3s+4)/(s2+3s+12)
enter the numerator coefficients as a vector in the order of decreasing
powers of s
a=
2
4 + 3s + s
enter the denominator coefficients as a vector in the order of decreasing
powers of s
b=
2
12 + 3s + s
The poles of the given H(s) are
-1.5000 + 3.1225i
-1.5000 - 3.1225i
The zeros of the given H(s)are
-1.5000 + 1.3229i
-1.5000 - 1.3229i

Geethanjali College of Engineering & Technology

Page 140

Basic Simulation Lab

Department of ECE

//This program finds the poles and zeros of the given H(z) and
gives the pole-zero plot in Z-Plane
z=poly(o,z);
a=input('enter the numerator Polynomial)
b=input('enter the denominator Polynomial))
z=roots(a);
p=roots(b);
disp('The poles of the given H(z) are')
disp(p)
disp('The zeros of the given H(z)are')
disp(z)
h=syslin(d, a, b)
plzr(h)

1.H(z)= z2/(z-1)(z2+3z+2)

Geethanjali College of Engineering & Technology

Page 141

Basic Simulation Lab

Department of ECE

After expressing both numerator and denominator as negative powers


of z, H(z)=z-1/(1+2z-1-z-2-2z-3)
enter the numerator polynomial
a = z2
enter the denominator polynomial
b=
2 3
- 2 - z + 2z + z
The poles of the given H(z) are
1.
- 2.
- 1.
The zeros of the given H(z)are
0
0

Geethanjali College of Engineering & Technology

Page 142

Basic Simulation Lab

Department of ECE

2. H(z)= z/(3z2-4z+1)
enter the numerator coefficients as a vector starting from constant
a=z
enter the numerator coefficients as a vector starting from constant
b=
2
1 - 4z + 3z
The poles of the given H(z) are
1.
0.3333333
The zeros of the given H(z)are
0.

Geethanjali College of Engineering & Technology

Page 143

Basic Simulation Lab

Department of ECE

CONCLUSION: In this experiment the pole-zero plots pf continuous/Discrete systems


were plotted.

VIVA QUESTIONS
1.What is the importance of poles and zeros of a system, with respect to the stability of
a
system?
2.If the pole of a continuous is lying in the left half of the S-Plane, what will be the
steady state value of its impulse response?
3. If the pole of a discrete system is lying within the unit circle, what about the
convergence of its unit sample response?

Geethanjali College of Engineering & Technology

Page 144

Basic Simulation Lab

Department of ECE

EXP.NO: 13
Generation of Gaussian Noise, Computation of its mean,
mean square value, Skew, Kurtosis, and CDF
AIM: - To generate a Gaussian noise and to compute its Mean, Mean Square
Value, Skew, Kurtosis, PSD, Probability Distribution function.
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB/Scilab Software
PROGRAM:Generation of Gaussian Density Function:
//This program generates a Gaussian distributed random variable
for a given value of mean and variance
n1=input('enter the lower limit of range of values of x')
n2=input('enter the higher limit of range of values of x')
n3=input('enter the incremental value of the range')
n=[n1:n3:n2];
m=input('enter the mean of the random variable')
v=input('enter the variance of the random variable')
x=(1/(sqrt(2*%pi*v)))*exp(-((n-m).^2)/(2*v));
plot2d(n,x,style=5,rect=[n1 0 n2 max(x)])
xtitle('normal density')
xlabel('x')
ylabel('Density function')
legend('mean=0,variance=4')
xgrid
enter the lower limit of range of values of x
n1 =-4
enter the higher limit of range of values of x
n2 =4
enter the incremental value of the range
n3 =0.2000
enter the mean of the random variable
Geethanjali College of Engineering & Technology

Page 145

Basic Simulation Lab

Department of ECE

m=0
enter the variance of the random variable
v =4

Y=grand(m,n,'nor',Av,Sd)- generates normally distributed random


data with mean=Av and Sd is the standard deviation. 'mxn is the
size of the data

Generation of Cumulative Distribution Function of Gaussian


Random Variable:
//This program generates a Gaussian distributed random variable
for a given value of mean and variance
function y=qfunc(x)
Geethanjali College of Engineering & Technology

Page 146

Basic Simulation Lab

Department of ECE

y=0.5*erfc(x/sqrt(2));
endfunction
n1=input('enter the lower limit of range of values of x')
n2=input('enter the higher limit of range of values of x')
n3=input('enter the incremental value of the range')
n=[n1:n3:n2];
m=input('enter the mean of the random variable')
v=input('enter the variance of the random variable')
x=(n-m)/sqrt(v);
y=1-qfunc(x);
plot2d(n,y,style=-4,rect=[n1 min(y) n2 max(y)+0.25])
xgrid
xtitle('CDF of a Gausian Random Variable',"x","cdf")
legend('mean=1,variance=4',"x","cdf",2)
1.enter the lower limit of range of values of x
n1 = -10
enter the higher limit of range of values of x
n2 =10
enter the incremental value of the range
n3 = 0.02
enter the mean of the random variable
m =1
enter the variance of the random variable
v =4

Geethanjali College of Engineering & Technology

Page 147

Basic Simulation Lab

Department of ECE

Finding the Moments of the Gaussian Random Variable.


//This program finds the mean, variance, skew and Kurtosis of a
Gaussian distributed random variable
n=input('enter the number of values taken by the random variable')
rand('normal')
y=rand(1,n);
y1=zeros(1,length(y));
M=mean(y);
for i=1:length(y)
y1(i)= ((y(i)-M).^2)/(length(y));
end
variance=sum(y1);
for i=1:length(y)
y1(i)=((y(i)-M).^3)/(length(y));
end
skew=sum(y1)/(variance^1.5);
for i=1:length(y)
y1(i)=((y(i)-M).^4)/(length(y));
end
kurtosis=sum(y1)/(variance^2);

Geethanjali College of Engineering & Technology

Page 148

Basic Simulation Lab

Department of ECE

disp('The mean, variance, skew and kurtosis of the given normal


distribution are "+string(M)+" "+string(variance)+" "+string(skew)+"
"+string(kurtosis)+" respectively')
1. enter the number of values taken by the random variable
n =100
The mean, variance, skew and kurtosis of the given normal distribution
are 0.0093114, 0.9415152, 0.0827996, 2.9007932 respectively
2. enter the number of values taken by the random variable
n =1000
The mean, variance, skew and kurtosis of the given normal distribution
are -0.0044692, 0.9889842, 0.0277401, 2.7898307 respectively
Result: The pdf and CDF of a Gaussian Distributed random variable are plotted
and its moment are computed.
Viva Questions:
1.Stae Central Limit Theorem.
2.For what value of x, the Gaussian random variable X will have its maximum value?
3. What is a standardized Gaussian Random Variable?

EXP.NO: 14
14. Sampling theorem verification
AIM: -. To generate a MATLAB Program to verify sampling theorem.
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
Geethanjali College of Engineering & Technology

Page 149

Basic Simulation Lab

Department of ECE

MATLAB Software
Sampling Theorem:
A bandlimited signal can be reconstructed exactly if it is sampled at a
rate atleast twice the maximum frequency component in it." Figure 1 shows a signal g(t)
that is bandlimited.

Figure 1: Spectrum of band limited signal g(t)


The maximum frequency component of g(t) is fm. To recover the signal g(t) exactly
from its samples it has to be sampled at a rate fs 2fm.
The minimum required sampling rate fs = 2fm is called ' Nyquist rate
Proof: Let g(t) be a bandlimited signal whose bandwidth is fm
(wm = 2fm).

Figure 2: (a) Original signal g(t) (b) Spectrum G(w)


(t) is the sampling signal with fs = 1/T > 2fm.

Figure 3: (a) sampling signal (t) ) (b) Spectrum (w)


Geethanjali College of Engineering & Technology

Page 150

Basic Simulation Lab

Department of ECE

Let gs(t) be the sampled signal. Its Fourier Transform Gs(w) isgiven by

Figure 4: (a) sampled signal gs(t) (b) Spectrum Gs(w)

To recover the original signal G(w):


1. Filter with a Gate function, H2wm(w) of width 2wm
Scale it by T.

Geethanjali College of Engineering & Technology

Page 151

Basic Simulation Lab

Department of ECE

Figure 5: Recovery of signal by filtering with a fiter of width 2wm


Aliasing
Aliasing is a phenomenon where the high frequency components of the sampled
signal interfere with each other because of inadequate sampling ws< 2wm.

Figure 6: Aliasing due to inadequate sampling


Aliasing leads to distortion in recovered signal. This is the
reason why sampling frequency should be atleast twice thebandwidth of the signal.
Oversampling
{ In practice signal are oversampled, where fs is significantly
higher than Nyquists rate to avoid aliasing.

Figure 7: Oversampled signal-avoids aliasing


Geethanjali College of Engineering & Technology

Page 152

Basic Simulation Lab

Department of ECE

PROGRAM:
%This Program samples the signal exp(-1000|t|)
f=input('enter the frequency of the signal')
T=1/f;
t=-T:T/f:T;
xa=exp(-1000*abs(t));
%Sampling the given signal
fs=input('enter the sampling frequency')
Ts=1/fs;
n=-150:150;
xd=exp(-1000*abs(n*Ts));
subplot(4,1,1)
plot(t,xa,'k')
subplot(4,1,2)
plot(t,xa,'k')
hold on
stem(n,xd,'k')
gtext('Ts=0.2msec')
hold of
%Signal recovery through zero order hold((ZOH) circuit
subplot(4,1,3)
stairs(n,xd,'k')
title('Reconstructed signal through ZOH')
%signal recovery through first order hold(FOH) circuit
subplot(4,1,4)
plot(n,xd,'k')
title('Reconstructed signal through FOH')

stairs(X,Y) plots the elements in Y at the


locations specified in X.

If the sampling frequency is much


higher than the Nyquists rate, FOH
interpolation provides an acceptable
reconstruction.
Geethanjali College of Engineering & Technology

Page 153

Basic Simulation Lab

Department of ECE

1. enter the frequency of the signal


f =1000
enter the sampling frequency
fs =5000

1
0.5
0
-1

-0.8

-0.6

-0.4

-0.2

0.2

0.4

0.6

0.8

1
-3

x 10

1
Ts=0.2msec

0.5
0
-150

-100

-50
0
50
Reconstructed signal through ZOH

100

150

-100

-50
0
50
Reconstructed signal through FOH

100

150

100

150

1
0.5
0
-150
1
0.5
0
-150

-100

-50

50

2. enter the frequency of the signal


f=1000
enter the sampling frequency
Geethanjali College of Engineering & Technology

Page 154

Basic Simulation Lab

Department of ECE

fs =10000

1
0.5
0
-1

-0.8

-0.6

-0.4

-0.2

0.2

0.4

0.6

0.8

1
-3

x 10

1
Ts=0.1msec

0.5
0
-150

-100

-50
0
50
Reconstructed signal through ZOH

100

150

-100

-50
0
50
Reconstructed signal through FOH

100

150

100

150

1
0.5
0
-150
1
0.5
0
-150

-100

-50

50

CONCLUSION: In this experiment the sampling theorem have been verified

VIVA QUESTIONS
1.
2.
3.
4.

Define sampling Theorem


What is Aliasing Effect
what is Under sampling
What is Over sampling

Geethanjali College of Engineering & Technology

Page 155

Basic Simulation Lab

Department of ECE

EXP.No:15
REMOVAL OF NOISE BY AUTO CORRELATION/CROSS CORRELATION
Aim: Removal of Noise by auto correlation/cross correlation
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB/Scilab Software
%This program estimates the signal in the presence of noise
%Generation of the signal
f=input('enter the frequency')
T=1/f;
t=0:T/f:T;
x1=sin(2*pi*f*t);
%Two cycles of the signal
x11=[x1 x1];
%Generation of noise uniformly distributed between -1 and +1
y1=2*rand(1,length(t))-1;
%Sum of signal plus noise
x2=x1+y1;
%Periodic (signal+noise)
x=[x2 x2];
%Generation of Unit impulse sequence
p=zeros(1,length(t));
for i=1:length(t)
if t(i)>=0
p(i)=1;
end
end
%periodic impulse train (length same as signal+noise)
y=[p p];
%Finding the cross Correlation between signal+Noise and the impulse
train
%Finding the cross correlation without shifting the impulse train
z=sum(x.*y);
%For each iteration of correlation, the impulse train is shifted towards
%right, i.e. each element of y is made zero.

Geethanjali College of Engineering & Technology

Page 156

Basic Simulation Lab

Department of ECE

for i=2:length(x)
y(i)=0;
z1=sum(x.*y);
z(i)=z1;
end
t1=0:T/f:2*T+T/f;
subplot(3,1,1)
plot(t1,x11,'k')
title('The Periodic signal')
subplot(3,1,2)
plot(t1,x,'k')
title('Signal+noise')
subplot(3,1,3)
plot(t1,z,'k')
title('The estimated signal')

1. enter the frequency


f =1000
The Periodic signal

1
0
-1

0.5

1.5

2.5
-3

x 10

Signal+noise

2
0
-2

0.5

1.5

2.5
-3

x 10

The estimated signal

500
0
-500

0.5

1.5

2.5
-3

x 10

2. enter the frequency


f =2000

Geethanjali College of Engineering & Technology

Page 157

Basic Simulation Lab

Department of ECE

The Periodic signal

1
0
-1

0.2

0.4

0.6

0.8

1.2
-3

x 10

Signal+noise

2
0
-2

0.2

0.4

0.6

0.8

1.2
-3

x 10

The estimated signal

1000
0
-1000

0.2

0.4

0.6

0.8

1.2
-3

x 10

CONCLUSION: in this experiment, the signal is extracted from a noisy environment,


by removing the noise.
VIVA QUESTIONS
1. Define Auto-Correlation
2. Define Cross-Correlation
3. What is the Difference Between Convolution& Correlation

Geethanjali College of Engineering & Technology

Page 158

Basic Simulation Lab

Department of ECE

EXP.No:16
EXTRACTION OF PERIODIC SIGNAL MASKED BY NOISE USING
CORRELATION

Aim: To extract a periodic signal masked by noise using correlation.


EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software.
PROGRAM:- MATLAB Program to detect the periodic signal masked by noise using
Auto Correlation &Cross Correlation method is performed.
clc;
clear all;
close all;
t=0:0.01:10;
s=cos(2*pi*3*t)+sin(2*pi*5*t); % periodic signal
figure;
subplot(2,1,1);
plot(t,s);
axis([0 10 -2 2]);
xlabel(' t ---->'),ylabel(' amp ----> ');
title('the periodic signal');
L=length(t);
n=randn(1,L); % noise signal
subplot(2,1,2);
plot(t,n);
xlabel(' t ---->'),ylabel(' amp ----> ');
title('the noise signal');
L=length(t);
f=s+n; % received signal
figure;
subplot(2,1,1);
plot(t,f);
xlabel(' t ---->'),ylabel(' amp ----> ');
title('the received signal');
rxx=xcorr(f,s,200);
subplot(2,1,2);
plot(rxx);
title('the Correlator output');

Geethanjali College of Engineering & Technology

Page 159

Basic Simulation Lab

Department of ECE

Application:
Geethanjali College of Engineering & Technology

Page 160

Basic Simulation Lab

Department of ECE

CONCLUSION: In this experiment, the Extraction of periodic signal masked by noise


using correlation have been verified .
VIVA QUESTIONS
1.What are the applications of Auto Correlation?
2.State the properties of Auto Correlation function.

EXP.No:17

Geethanjali College of Engineering & Technology

Page 161

Basic Simulation Lab

Department of ECE

VERIFICATION OF WIENERKHINCHIN RELATION


AIM: verification of wiener khinchin relation
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB/Scilab Software
The WienerKhinchin theorem (also known as the WienerKhintchine theorem and
sometimes as the WienerKhinchinEinstein theorem or the KhinchinKolmogorov
theorem) states that the power spectral density of a wide-sense-stationary random
process is the Fourier transform of the corresponding autocorrelation function.[1][2][3]
Continuous case:

Where

is the autocorrelation function defined in terms of statistical expectation, and where is


the power spectral density of the function . Note that the autocorrelation function is
defined in terms of the expected value of a product, and that the Fourier transform of
does not exist in general, because stationary random functions are not square integrable.
The asterisk denotes complex conjugate, and can be omitted if the random process is
real-valued.
Discrete case:

Where

and where is the power spectral density of the function with discrete values . Being a
sampled and discrete-time sequence, the spectral density is periodic in the frequency
domain.
PROGRAM:

Geethanjali College of Engineering & Technology

Page 162

Basic Simulation Lab

Department of ECE

clc;clear all; close all;


t=0:0.1:2*pi;
x=sin(2*t);
subplot(3,2,1);
plot(x);
au=xcorr(x,x);
subplot(3,2,2);
plot(au);
v=ft(au);
subplot(3,2,3);
plot(abs(v));
fw=ft(x);
subplot(3,2,4);
plot(fw);
fw2=(abs(fw)).^2;
subplot(3,2,5);
plot(fw2);

output:

Geethanjali College of Engineering & Technology

Page 163

Basic Simulation Lab

Department of ECE

CONCLUSION: In this experiment the Weiner-Khinchine Relation have been


verified using MATLAB.
VIVA QUESTIONS
1.State Wiener-Khinchine Relation
2.Define Power Spectral Density of a signal
3.How to find the power of a signal from its Auto correlation function?
4.Give the relation between Power and Power Spectral Density of a signal.

Geethanjali College of Engineering & Technology

Page 164

Basic Simulation Lab

Department of ECE

EXP18.
CHECKING A RANDOM PROCESS FOR STATIONARITY IN WIDE SENSE.
AIM: Checking a random process for stationarity in wide sense.
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
Theory:
a stationary process (or strict(ly) stationary process or strong(ly) stationary process)
is a stochastic process whose joint probability distribution does not change when shifted in
time or space. As a result, parameters such as the mean and variance, if they exist, also do
not change over time or position..
Definition: Formally, let Xt be a stochastic process and let
represent the cumulative distribution function of the joint
distribution of Xt at times t1..tk. Then, Xt is said to be stationary if, for all k, for all ,
and for all t1..tk

Weak or wide-sense stationarity


A weaker form of stationarity commonly employed in signal processing is known as
weak-sense stationarity, wide-sense stationarity (WSS) or covariance stationarity.
WSS random processes only require that 1st and 2nd moments do not vary with respect
to time. Any strictly stationary process which has a mean and a covariance is also WSS.
So, a continuous-time random processx(t) which is WSS has the following restrictions
on its mean function

and autocorrelation function

The first property implies that the mean function mx(t) must be constant. The second
property implies that the correlation function depends only on the difference between t1
and t2 and only needs to be indexed by one variable rather than two variables. Thus,
instead of writing,

Geethanjali College of Engineering & Technology

Page 165

Basic Simulation Lab

Department of ECE

we usually abbreviate the notation and write

This also implies that the autocovariance depends only on = t1 t2, since

Stationary and Non Stationary Random Process:


A random X(t) is stationary if its statistical properties are unchanged by a time shift in
the time origin.When the auto-Correlation function Rx(t,t+T) of the random X(t) varies
with time difference T and the mean value of the random variable X(t1) is independent
of the choice of t1,then X(t) is said to be stationary in the wide-sense or wide-sense
stationary . So a continous- Time random process X(t) which is WSS has the following
properties
1) E[X(t)]=X(t)= X(t+T)
2) The Autocorrelation function is written as a function of T that is
3) RX(t,t+T)=Rx(T)
If the statistical properties like mean value or moments depends on time then the
random process is said to be non-stationary.
When dealing wih two random process X(t) and Y(t), we say that they are jointly
wide-sense stationary if each pocess is stationary in the wide-sense.
Rxy(t,t+T)=E[X(t)Y(t+T)]=Rxy(T).
//This program checks the random process Acos(wt+theta) for
Stationarity, where the random variable involved is uniform
syms A w theta t k
p=sym(2);
rv=input('enter the random variable')
a=input('enter the lower limit of the density of the variable')
b=input('enter the upper limit of the density of the variable')
density=1/(b-a);
x=input('enter the random process')
y= int(x,rv,a,b);
x1= ((A^p)/p)*(cos(a*w*t+a*theta+w*k)+cos(w*k));
y1=int(x1,rv,a,b);
disp('The density of the random variable over(0,2*pi)is')
disp(density)
Geethanjali College of Engineering & Technology

Page 166

Basic Simulation Lab

Department of ECE

disp('Mean of the process is')


disp(y)
disp('The Autocorrelation function of the process is')
disp(y1)

1. The process is x(t)=Acos(wt+theta), where theta is a uniform random


variable over (0,2*pi).
enter the random variable
rv =theta
enter the lower limit of the density of the variable
a =0
enter the upper limit of the density of the variable
b =6.2832
enter the random process
x = A*cos(w*t+theta)
The density of the random variable over (0,2*pi)is
0.1592
Mean of the process is0
The Autocorrelation function of the process is 2*A^2*cos (w*k)*pi
Since, the mean of the process is constant and the Autocorrelation
function of the process is independent of time and is a function of k,
the process is stationary.

2.The process is x(t)=Acos(wt+theta), where w is a uniform random


variable over (0,2*pi).
//This program checks the random process Acos(wt+theta), where
the random variable involved is uniform
syms A w theta t k
p=sym(2);
rv=input('enter the random variable')
a=input('enter the lower limit of the density of the variable')
b=input('enter the upper limit of the density of the variable')
density=1/(b-a);
x=input('enter the random process')
y= int(x,rv);
x_Mean=subs(y,rv,b)-subs(y,rv,a)
x1= ((A^p)/p)*(cos(a*w*t+a*theta+w*k)+cos(w*k));
y1=int(x1,rv);
Geethanjali College of Engineering & Technology

Page 167

Basic Simulation Lab

Department of ECE

x_Autocorrelation=subs(y1,rv,b)-subs(y1,rv,a);
disp('The density of the random variable over(0,2*pi)is')
disp(density)
disp('Mean of the process is')
disp(x_Mean)
disp('The Autocorrelation function of the process is')
disp(x_Autocorrelation)
enter the random variable
rv = w
enter the lower limit of the density of the variable0
a =0
enter the upper limit of the density of the variable2*pi
b =6.2832
enter the random process
x =A*cos(w*t+theta)
x_Mean = sin(2*pi*t+theta)*A/t-A/t*sin(theta)
The density of the random variable over(0,2*pi)is 0.1592
Mean of the process is
sin(2*pi*t+theta)*A/t-A/t*sin(theta)
The Autocorrelation function of the process is
sin(2*k*pi)*A^2/k
Since the mean of the process is not independent of time, the given
process is not stationary.

CONCLUSION: In this experiment the process of checking a random process for


stationary in wide sense have been verified .

Geethanjali College of Engineering & Technology

Page 168

Basic Simulation Lab

Department of ECE

ADDITIONAL
EXPERIMENTS

EXP:1
To find mean and variance of a discrete random variable
AIM:To find amean and variance of a discrete random variable
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
Theory:
Random Variable
The outcome of an experiment need not be a number, for example, the outcome when a
coin is tossed can be 'heads' or 'tails'. However, we often want to represent outcomes as
numbers. A random variable is a function that associates a unique numerical value with
every outcome of an experiment. The value of the random variable will vary from trial
to trial as the experiment is repeated.
There are two types of random variable - discrete and continuous.
A random variable has either an associated probability distribution (discrete random
variable) or probability density function (continuous random variable).
Examples
1. A coin is tossed ten times. The random variable X is the number of tails that are
noted. X can only take the values 0, 1. 10, so X is a discrete random variable.

Geethanjali College of Engineering & Technology

Page 169

Basic Simulation Lab

Department of ECE

2. A light bulb is burned until it burns out. The random variable Y is its lifetime in
hours. Y can take any positive real value, so Y is a continuous random variable.
Expected Value
The expected value (or population mean) of a random variable indicates its average or
central value. It is a useful summary value (a number) of the variable's distribution.
Stating the expected value gives a general impression of the behaviour of some random
variable without giving full details of its probability distribution (if it is discrete) or its
probability density function (if it is continuous).
Two random variables with the same expected value can have very different
distributions. There are other useful descriptive measures which affect the shape of the
distribution, for example variance.
The expected value of a random variable X is symbolised by E(X) or .
If X is a discrete random variable with possible values x1, x2, x3, ..., xn, and p(xi)
denotes P(X = xi), then the expected value of X is defined by:
where the elements are summed over all values of the random variable X.
If X is a continuous random variable with probability density function f(x), then the
expected value of X is defined by:
Example
Discrete case : When a die is thrown, each of the possible faces 1, 2, 3, 4, 5, 6 (the xi's)
has a probability of 1/6 (the p(xi)'s) of showing. The expected value of the face showing
is therefore:
= E(X) = (1 x 1/6) + (2 x 1/6) + (3 x 1/6) + (4 x 1/6) + (5 x 1/6) + (6 x 1/6) =
3.5
Notice that, in this case, E(X) is 3.5, which is not a possible value of X.
Variance
The (population) variance of a random variable is a non-negative number which gives
an idea of how widely spread the values of the random variable are likely to be; the
larger the variance, the more scattered the observations on average.
Stating the variance gives an impression of how closely concentrated round the
expected value the distribution is; it is a measure of the 'spread' of a distribution about
its average value.
Variance is symbolised by V(X) or Var(X) or
The variance of the random variable X is defined to be:
where E(X) is the expected value of the random variable X.
Geethanjali College of Engineering & Technology

Page 170

Basic Simulation Lab

Department of ECE

Notes
a. the larger the variance, the further that individual values of the random variable
(observations) tend to be from the mean, on average;
b. the smaller the variance, the closer that individual values of the random variable
(observations) tend to be to the mean, on average;
c. taking the square root of the variance gives the standard deviation, i.e.:
d. the variance and standard deviation of a random variable are always nonnegative.
MATLAB PROGRAM:
clear all;
close all;
x=[1 2 3 4 5 6];
n=length(x)
m = (1/n)*sum(x)
v = (1/n)*(x-m)*(x-m)'
RESULTS:
n=

m =3.5000
v=

2.9167

VIVA QUESTIONS
1.Define a moment generating function of a discrete random variable?
2. .Define a moment generating function of a continuous random variable?
3. Define a characteristic function of a discrete random variable?
4. .Define a characteristic function of a continuous random variable
5 what are the properties of the characteristic function of a discrete random variable?

Geethanjali College of Engineering & Technology

Page 171

Basic Simulation Lab

Department of ECE

EXP 2.
To find a moment generating function of a discrete random variable
AIM:To find a moment generating functionof a discrete random variable
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
Theory:
In probability theory and statistics, the moment-generating function of a random
variable is an alternative specification of its probability distribution (however, note that
not all random variables have moment-generating functions). Thus, it provides the basis
of an alternative route to analytical results compared with working directly with
probability density functions or cumulative distribution functions. There are particularly
simple results for the moment-generating functions of distributions defined by the
weighted sums of random variables.
In addition to univariate distributions, moment-generating functions can be defined for
vector- or matrix-valued random variables, and can even be extended to more general
cases.
The moment-generating function does not always exist even for real-valued arguments,
unlike the characteristic function. There are relations between the behavior of the
moment-generating function of a distribution and properties of the distribution, such as
the existence of moments.
In probability theory and statistics, the moment-generating function of a random
variableX is

wherever this expectation exists.

Geethanjali College of Engineering & Technology

Page 172

Basic Simulation Lab

Department of ECE

always exists and is equal to 1.


A key problem with moment-generating functions is that moments and the momentgenerating function may not exist, as the integrals need not converge absolutely. By
contrast, the characteristic function always exists (because it is the integral of a bounded
function on a space of finite measure), and thus may be used instead.
More generally, where
uses
instead of tX:

, an n-dimensional random vector, one

The reason for defining this function is that it can be used to find all the moments of the
distribution.[1] The series expansion of etX is:

Hence:

where mn is the nth moment.


If we differentiate MX(t) i times with respect to t and then set t = 0 we shall therefore
obtain the ith moment about the origin, mi.
MATLAB PROGRAM:
clear all;
close all;
s=0;t=1;
x=[1 2 3 4 5 6];
p=[1/6 1/6 1/6 1/6 1/6 1/6];
for i=1:6
s= sum(exp(t*x(i)).*p(i))
end
disp(s)
RESULT:
s = 0.4530
s=

1.2315

VIVA QUESTIONS
Geethanjali College of Engineering & Technology

Page 173

Basic Simulation Lab

Department of ECE

1.Define a random variable ?


2. How to define of a discrete random variable?
3. Give one example of a continuous random variable?
4. Define variance of a random variable?
5 Expected value of 1?

DESIGN
EXPERIMENTS

Experiment 1
To Design Half wave rectifier
AIM:To find the input current flowing through the diode and output voltage.
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
Theory:
During the positive half-cycle ofthe input voltage, the diode is forward-biased for all
instantaneous voltages greater than thediode cut-in voltage, V . Current flowing through
the
diode during the positive half-cycleproduces approximately a half sine wave of
voltages
across the load resistor, To simplify our discussions, we will assume that the diode is
ideal
and that the peak input voltage is always much larger than the V of the diode. Hence, we
assumethat the zero of the rectified voltage coincides with the zero of the input voltage.
On
the negativehalf-cycle of the input voltage, the diode is reverse-biased. Ignoring the
reverse
leakage currentof the diode, the load current drops to zero, resulting in zero load voltage
(output voltage).
Design Problem.
A battery charging circuit is shown in Figure 9.10. The battery voltage is VB= 118. V.
The source voltage is vs(t)=18 sin120tV and the resistance is R = 100 . Use
MATLAB (a) to sketch the input voltage, (b) to plot the current flowing through the

Geethanjali College of Engineering & Technology

Page 174

Basic Simulation Lab

Department of ECE

diode, (c ) to calculate the conduction angle of the diode, and (d) calculate the peak
current. (Assume that the diode is ideal.)
Matlab code:
diary ex9_5.dat
% Baltery charging circuit
period = 1/60;
period2 = period*2;
inc =period/100;
npts = period2/inc;
r=100;
vb = 11.8;
t = [];
for i = 1:npts
t(i) = (i-1)*inc;
vs(i) = 18*sin(120*pi*t(i));
if vs(i) >vb
idiode(i) = (vs(i) -vb)/r;
else
idiode(i) = 0;
end
end
subplot(211), plot(t,vs)
%title('Input Voltage')
xlabel('Time (s)')
ylabel('Voltage (V)')
text(0.027,10, 'Input Voltage')
subplot(212), plot(t,idiode)
%title('Diode Current')
xlabel('Time (s)')
ylabel('Current(A)')
text(0.027, 0.7e-3, 'Diode Current')
% conduction angle
theta1 = asin(vb/18); theta2 = pi - theta1;
acond = (theta2 -theta1)/(2*pi)
% peak current
pcurrent = (18*sin(pi/2) - vb)/r
% pcurrent = max(idiode)
Diary
results:
acond = 0.2724
pcurrent =0.0620
Conclusion: The current flowing through the diode and output voltage are calculated
and observed.
ViVa Questions:

Geethanjali College of Engineering & Technology

Page 175

Basic Simulation Lab

Department of ECE

1. What is Rectifier?
2. What is half wave Rectifier?
3. What is ripple?
4. What is the ripple factor of half wave rectifier?
5. What is the Efficiency of half wave rectifier?

Experiment 2
To Design Zener break down characteristics
AIM:To find the Zener break down characteristics.
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
Theory:
A zener diode is a special kind of diode which allows current to flow in the forward
direction
in the same manner as an ideal diode, but will also permit it to flow in the reverse
direction
when the voltage is above a certain value known as the breakdown voltage, "zener knee
voltage" or "zener voltage".
The device was named after Clarence Zener, who discovered this electrical
property.
Many diodes described as "zener" diodes rely instead on avalanche breakdown as the
mechanism. Both types are used. Common applications include providing a reference
voltage for voltage regulators, or to protect other semiconductor devices from
momentary
voltage pulses.
Design Problem.
A zener diode voltage regulator circuit has the following data:
30 VS 35V; RL = 10K, RS = 2K
VZ = -20+0.05I for -100 mA I < 0
Use MATLAB to
(a) plot the zener breakdown characteristics,
(b) plot the loadline for VS = 30V and VS = 35 V,
(c) determine the output voltage when VS = 30V and VS = 35V
Geethanjali College of Engineering & Technology

Page 176

Basic Simulation Lab

Department of ECE

Matlab code:
% Zener diode voltage regulator
vs1 = -30; vs2 = -35;
rl =10e3; rs = 2e3;
i = -50e-3: 5e-3 :0;
vz = -20 + 0.05*i;
m = length(i);
i(m+1) = 0; vz(m+1) = -10;
i(m+2) = 0; vz(m+2) = 0;
% loadlines
vt1 = vs1*rl/(rl+rs);
vt2 = vs2*rl/(rl+rs);
rt = rl*rs/(rl+rs);
l1 = vt1/20;
l2 = vt2/20;
v1 = vt1:abs(l1):0;
i1 = (vt1 - v1)/rt;
v2 = vt2:abs(l2):0;
i2 = (vt2 - v2)/rt;
% plots of Zener characteristics, loadlines
plot(vz,i,'b',v1,i1,'r',v2,i2,'g')
axis([-30,0,-0.03,0.005])
title('Zener Voltage Regulator Circuit')
xlabel('Voltage (V)')
ylabel('Current (A)')
text(-19.5,-0.025,'Zener Diode Curve')
text(-18.6,-0.016, 'Loadline (35 V Source)')
text(-14.7,-0.005,'Loadline (30 V Source)')
% output voltage when vs = -30v
ip1 = (vt1 + 20)/(rt + 0.05)
vp1 = vt1 - rt*(vt1+20)/(rt + 0.05)
% output voltage when vs = -35v
ip2 = (vt2 + 20)/(rt + 0.05)
vp2 = vt2 - rt*(vt2+20)/(rt + 0.05)
Results:
ip1 = -0.0030
vp1 = -20.0001
ip2 = -0.0055
vp2 = -20.0003
Conclusion: Zener break down characteristics observed.
ViVa Questions:
1. Zener Diode operates in which region?

Geethanjali College of Engineering & Technology

Page 177

Basic Simulation Lab

Department of ECE

2. What is the application of zener diode?


3. What is Voltage regulator?
4. Load Regulation?

OPEN
EXPERIMENTS

1. IMPLEMENTATION OF DECIMATION PROCESS


AIM: To implementation of decimation of given sequence by factor M.
EQUIPMENTS:
Operating System - Windows XP
Constructor - Simulator
Software - CCStudio 3 & MATLAB 7.5
THEORY :
Decimation is the process of reducing the sampling frequency of a signal to a
lower sampling frequency that differs from the original frequency by an integer value.
Decimation also is known as down-sampling. The lowpass filtering associated with
decimation removes high-frequency content from the signal to accommodate the new
sampling frequency.
Decimation is useful in applications in which the Nyquist frequency of a signal
is much higher than the highest frequency of the signal. Decimation filters help you
remove the excess bandwidth and reduce the sampling frequency of the signal.
Decimation filters also help you reduce the computational resources required for
processing and storing the signal. During the analog-to-digital (A/D) conversion
process, decimation filters also can reduce the variance of quantization noise in a signal
and maintain the signal power, thus improving the signal-to-noise ratio (SNR).
The following figure shows a typical M-fold decimation filter, where M is the
integer value by which you want to decrease the sampling frequency. This filter contains
a lowpass FIR filter H(z). This lowpass FIR filter is an anti-aliasing filter followed by
anM-fold decimator. The decimator passes every Mth sample and discards the other
samples. After this operation, the decimation filter changes the sampling frequency fs of

Geethanjali College of Engineering & Technology

Page 178

Basic Simulation Lab

Department of ECE

the input signal x(n) to a new sampling frequency fs/M. The decimation filter then
returns an output signal y(n) with the new sampling frequency.
equation for decimation
To prevent aliasing, this system uses the lowpass filter H(z) before the M-fold
decimator to suppress the frequency contents above the frequency fs/(2M), which is the
Nyquist frequency of the output signal. This system produces the same results as an
analog anti-aliasing filter with a cutoff frequency of fs/(2M) followed by an analog-todigital (A/D) converter with a sampling frequency of fs/M. Because the system shown in
the figure above is in the digital domain, H(z) is a digital anti-aliasing filter.

Geethanjali College of Engineering & Technology

Page 179

Basic Simulation Lab

Department of ECE

PROGRAM: (Without inbuilt function)


clc;
close all;
clear all;
N=input(' input length of the sine seq');
M= input(' down sampling factor');
fi= input(' input signal freq'); % generation of sine sequence
t=0:N-1;
m=0:N*M-1;
x=sin(2*pi*fi*m);
%generate the down sample signal
Y=x([1:m:length(x)]);
Y([1:M:length(x)])=x;
Subplot(2,1,1);
Stem(n,x(1:M));
Title(' input sequence');
Xlable('time');
Ylabel('amplitude');
Subplot(2,1,2);
Stem(n, Y);
Title([' output sequence ',num2str(m)]);
Xlable('time');
Ylabel('amplitude');
%Decimate a signal by a factor of four by using inbuilt function
clc;
clear all;
close all;
t = 0:.00025:1; % Time vector x = sin(2*pi*30*t) + sin(2*pi*60*t);
y = decimate(x,4);
subplot(1,2,1);
stem(x(1:120)), axis([0 120 -2 2]) % Original signal
title('Original Signal')
subplot(1,2,2);
stem(y(1:30)) % Decimated signal
title('Decimated Signal')
OUTPUT :

Geethanjali College of Engineering & Technology

Page 180

Basic Simulation Lab

Department of ECE

RESULT: The decimator for a given sequence is observed for chosen factor M.
Hence the theory and practical is verified.
VIVA QUESTION:
1. What is the importance of decimation for a given signal/sequence?
2. What do you mean Aliasing? What is the condition to avoid aliasing for sampling?
3. How does poly phase filtering save computations in a decimation filter?
4. Give any practical application of decimation?
5. Which signals can be down sampled?
6. What happens if I violate the Nyquist criteria in down sampling or decimating?
7. Can we do decimate in multiple stages?
8. What are "decimation" and "downsampling"?
9. What is the "decimation factor"?

Geethanjali College of Engineering & Technology

Page 181

Basic Simulation Lab

Department of ECE

2. IMPLEMENTATION OF INTERPOLATION PROCESS


AIM: To implementation of interpolation for given sequence by factor L.
EQUIPMENTS:
Operating System - Windows XP
Constructor - Simulator
Software - CCStudio 3 & MATLAB 7.5
THEORY:
The process of increasing the sampling rate is called interpolation. Interpolation is
upsampling followed by appropriate filtering. obtained by interpolating , is generally
represented as:
The simplest method to interpolate by a factor of L is to add L-1 zeros in between the
samples, multiply the amplitude by L and filter the generated signal, with a so-called
anti-imaging low pass filter at the high sampling frequency.
PROGRAME:
Clc;
Close all;
Clear all;
N=input( input length of the sine seq);
L= input( up sampling factor);
Fi= input( input signal freq);
t=0:N-1;
X=sin(2*pi*fi*t);
Y=zeros(1,L*length(x));
Y([1:L:length(x)])=x;
Subplot(2,1,1);
Stem(n,x);
Title( input sequence);
Xlable(time);
Ylabel(amplitude);
Subplot(2,1,2);
Stem(n, Y(1:length(x));
Title([ output sequence ,num2str(L)]); Xlable(time);
Ylabel(amplitude);
RESULT: The interpolation of given sequence is observed for factor value L. Hence the
theory and practical are verified.

Geethanjali College of Engineering & Technology

Page 182

Basic Simulation Lab

Department of ECE

VIVA QUESTION:
1. How does polyphase filtering save computations in an interpolation filter?
2. Why do we need I&Q signals?
3. What is Interpolation and decimation filters and why we need it?
4. What are "upsampling" and "interpolation"?
5. Why interpolate is needed for any signal/sequence?
6. What is the "interpolation factor"?
7. Which signals can be interpolated?
8. Can interpolate will happens in multiple stages? If yes give reason?
9. Give any example of a FIR interpolator?

Geethanjali College of Engineering & Technology

Page 183