Download - Basic Simulation Lab
-
7/27/2019 Basic Simulation Lab
1/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 1
BASIC SIMULATION LAB
(Using MATLAB)
Ex.No. Name of the Experiment
1. Basic operations on Matrices2. Generation Of Various Signals and Sequence ( periodic and aperiodic)3. Operations on signals and sequence4. Even and Odd parts of signal or sequence5. Convolution Between Signals6. Convolution Between Sequences7. Auto correlation and Cross correlation between signals and sequences8. Computation of Unit sample, Unit step and sinusoidal response of LTI
system
9. Reconstruction of Periodic Signal by its Fourier Series10. Locating Zeros and Poles on S-Plane and Z-Plane11. Sampling Theorem
ADDITIONAL EXPERIMENTS
1. Removal of noise by Auto correlation / Cross Correlation
2. Impulse response of a raised cosine filter
-
7/27/2019 Basic Simulation Lab
2/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 2
EXPERIMENT-1
BASIC OPERATIONS ON MATRICES
AIM:To perform the different operations on Matrices.
Requirements: PC with MATLAB R2008a
THEORY:
What Is MATLAB?
MATLAB is a high-performance language for technical computing. It integrates
computation, visualization, and programming in an easy-to-use environment where problems
and solutions are expressed in familiar mathematical notation. Typical uses include Math andcomputation Algorithm development Data acquisition Modeling, simulation, and prototyping
Data analysis, exploration, and visualization Scientific and engineering graphics Application
development, including graphical user interface building .
MATLAB is an interactive system whose basic data element is an array that does not
require dimensioning. This allows you to solve many technical computing problems,
especially those with matrix and vector formulations, in a fraction of the time it would take to
write a program in a scalar noninteractive language such as C or Fortran.
The name MATLAB stands for matrix laboratory. MATLAB was originally writtento provide easy access to matrix software developed by the LINPACK and EISPACK
projects. Today, MATLAB engines incorporate the LAPACK and BLAS libraries,
embedding the state of the art in software for matrix computation.
MATLAB has evolved over a period of years with input from many users. In
university environments, it is the standard instructional tool for introductory and advanced
courses in mathematics, engineering, and science. In industry, MATLAB is the tool of choice
for high-productivity research, development, and analysis.
MATLAB features a family of add-on application-specific solutions called toolboxes.
Very important to most users of MATLAB, toolboxes allow you to learn and apply
specialized technology. Toolboxes are comprehensive collections of MATLAB functions
(M-files) that extend the MATLAB environment to solve particular classes of problems.
Areas in which toolboxes are available include signal processing, control systems, neural
networks, fuzzy logic, wavelets, simulation, and many others.
Basic Matrix Operations:
This is a demonstration of some aspects of the MATLAB language.
First, let's create a simple vector with 9 elements called a.
a = [1 2 3 4 6 4 3 4 5]
a =
1 2 3 4 6 4 3 4 5
Now let's add 2 to each element of our vector, a, and store the result in a new vector.
Notice how MATLAB requires no special handling of vector or matrix math.
b = a + 2
-
7/27/2019 Basic Simulation Lab
3/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 3
b = 3 4 5 6 8 6 5 6 7
Creating a matrix is as easy as making a vector, using semicolons (;) to separate the
rows of a matrix.
A = [1 2 0; 2 5 -1; 4 10 -1]
A =
1 2 0
2 5 -1
4 10 -1
We can easily find the transpose of the matrix A.
B = A'
B =
1 2 4
2 5 10
0 -1 -1
Now let's multiply these two matrices together.
Note again that MATLAB doesn't require you to deal with matrices as a collection of
numbers. MATLAB knows when you are dealing with matrices and adjusts your calculations
accordingly.
C = A * B
C =
5 12 24
12 30 59
24 59 117
Instead of doing a matrix multiply, we can multiply the corresponding elements of
two matrices or vectors using the .* operator.
C = A .* B
C =
1 4 0
4 25 -100 -10 1
Let's find the inverse of a matrix ...
X = inv(A)
X =
5 2 -2
-2 -1 1
0 -2 1
... and then illustrate the fact that a matrix times its inverse is the identity matrix.
I = inv(A) * A
I =
1 0 0
0 1 0
0 0 1
MATLAB has functions for nearly every type of common matrix calculation.
-
7/27/2019 Basic Simulation Lab
4/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 4
There are functions to obtain eigenvalues ...
eig(A)
ans =
3.7321
0.2679
1.0000
... as well as the singular value decomposition.
svd(A)
ans =
12.3171
0.51490.1577
The "poly" function generates a vector containing the coefficients of the characteristic
polynomial.
The characteristic polynomial of a matrix A is
p = round(poly(A))
p =
1 -5 5 -1
We can easily find the roots of a polynomial using the roots function.
These are actually the eigenvalues of the original matrix.
roots(p)
ans =
3.7321
1.0000
0.2679
MATLAB has many applications beyond just matrix computation.
To convolve two vectors ...
q = conv(p,p)
q =
1 -10 35 -52 35 -10 1
r = conv(p,q)
r =1 -15 90 -278 480 -480 278 -90 15 -1
At any time, we can get a listing of the variables we have stored in memory using the
who or whos command.
whos
Name Size Bytes Class
A 3x3 72 double array
B 3x3 72 double array
C 3x3 72 double array
-
7/27/2019 Basic Simulation Lab
5/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 5
I 3x3 72 double array
X 3x3 72 double array
a 1x9 72 double array
ans 3x1 24 double arrayb 1x9 72 double array
opts 1x1 522 struct array
p 1x4 32 double array
q 1x7 56 double array
r 1x10 80 double array
Grand total is 162 elements using 1218 bytes
You can get the value of a particular variable by typing its name.
A
A =
1 2 0
2 5 -1
4 10 -1
You can have more than one statement on a single line by separating each statement
with commas or semicolons.
If you don't assign a variable to store the result of an operation, the result is stored in
a temporary variable called ans.
sqrt(-1)
ans =
0 + 1.0000i
RESULT:Thus the different basic operations on Matrices and vectors were verified using
MATLAB.
QUESTIONS:
1. What is MATLAB ?2. What are the applications of MATLAB?3. What are the advantages of MATLAB over other software?4. What are the different operators in MATLAB?5. What are the different windows in MATLAB?
-
7/27/2019 Basic Simulation Lab
6/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 6
EXPERIMENT-2
GENERATION OF VARIOUS SIGNALS AND SEQUENCES
(PERIODIC AND APERIODIC)
AIM:To generate various signals and sequences, such as Unit Impulse, Unit Step, Square,Sawtooth, Triangular, Sinusoidal, Ramp and Sinc functions
Requirements: PC with MATLAB R2008a
MATLAB CODE:
%Unit impluse signaln=-10:2:10;
X1=1; X2=0;X=X1.*(n==0)+X2.*(n~=0);
subplot(4,3,1); stem(n,X);title('unit impluse');
xlabel('n'); ylabel('X(n)');
%Unit step signaln=-10:2:10;
X1=1; X2=0;X=X1.*(n>=0)+X2.*(n
-
7/27/2019 Basic Simulation Lab
7/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 7
xlabel('n'); ylabel('X(n)');
%increasing ramp
n=-10:2:10;X1=n; X2=0;X=X1.*(n>=0)+X2.*(n
-
7/27/2019 Basic Simulation Lab
8/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 8
title('sinc signal');
Expected Waveforms:Discrete Time Signals
Continuous Time Signals
RESULT: Thus the various signals in discrete and continuous form were generated by using
MATLAB.
-10 0 100
0.51
unit impluse
n
X(n)
-1
0 0 100
0.51
step signal
n
X(n)
0 1 20
0.51
time base
t
X(t)
-10 0
10012
increasing exponential
n
X(n)
-10 0
10012
decreasing exponential
n
X(n)
-10 0 10-101
sine function
n
X(n)
-1
0 0 1005
10increasing ramp
n
X(n)
-1
0 0 10-10-50
decreasing ramp
n
X(n)
0 0.5 1-101
sawsooth
t
X(t)
0 0.5
1-101
triangular singal
t
x(t)
-10 0
10-101
square wave form
n
X(n)
-10 0 10-101rectangular wave form
n
X(n)
-1
0 0 1000.5
1unit impluse
n
X
(n)
-1
0 0 1000.5
1step signal
n
X
(n)
0 1 200.5
1time base
t
X
(t)
-1
0 0 10012
increasing exponential
n
X(n)
-1
0 0 10012
decreasing exponential
n
X(n)
-1
0 0 10-101
sine function
n
X(n)
-1
0 0 1005
10increasing ramp
n
X(n)
-1
0 0 10-10-50
decreasing ramp
n
X(n)
0 0.5 1-101
sawsooth
t
X(t)
0 0.5
1-101
triangular singal
t
x(t)
-10 0 10-101
square wave form
n
X(n)
-10 0 10-101rectangular wave form
n
X(n)
-
7/27/2019 Basic Simulation Lab
9/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 9
QUESTIONS:
1.Define a signal?
A.A signal is defined as a single valued function of one or more independent variables whichcontains some information.
2.Define unit ramp function?
A.The continuous time unit ramp function r(t) is defined asr(t)=t for t>=0;
0 for t=0;
0 for n
-
7/27/2019 Basic Simulation Lab
10/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 10
EXPERIMENT-3
OPERATIONS ON SIGNALS AND SEQUENCES
AIM:To perform the different operations on signals and sequences such as addition,multiplication, scaling, shifting, folding, computation of energy and average power.
Requirements: PC with MATLAB R2008a
MATLAB Code: a) Operations on signals
%operations on signalsN=128;
f1=150; f2=450; fs=8000;
n=0:N-1; %specify the range of n
x1=sin(2*pi*(f1/fs)*n);x2=(1/3)*sin(2*pi*(f2/fs)*n);
subplot(2,2,1);
plot(n,x1); %plot the generated signal x1(n)grid;
xlabel('t');ylabel('x(t)');
title('signal,x1(t)');subplot(2,2,2);
plot(n,x2); %plot the generated signal x2(n)
grid;
xlabel('t');ylabel('x(t)');title('signal,x2(t)');
%signal delayx1d=[zeros(1,20),x1(1:N-20)];
subplot(2,2,3);
plot(n,x1d); %plot the generated delayed signalgrid;
xlabel('t');ylabel('x(t)');
title('delayed x1(t),[x1(t-20)]');
%signal additionxadd=x1+x2; %generate signal addition
subplot(2,2,4);plot(n,xadd); %plot the generated signal
grid;
xlabel('t');ylabel('x(t)');title('x1(t)+x2(t)');
-
7/27/2019 Basic Simulation Lab
11/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 11
Expected Waveforms: Addition and Delay Operation
%signal multiplication
N=128;f1=150;
f3=1500;
fs=8000;
n=0:N-1; %specify the range of nx1=sin(2*pi*(f1/fs)*n);
x3=sin(2*pi*(f3/fs)*n);
subplot(2,2,1);
plot(n,x1); %plot the generated signal x1(n)grid;
xlabel('t');ylabel('x(t)');title('signal,x1(t)');
subplot(2,2,2);plot(n,x3); %plot the generated signal x2(n)
grid;
xlabel('t');ylabel('x(t)');title('signal,x3(t)');
xmult=x1.*x3;
subplot(2,2,3);plot(n,xmult); %plot the generated signal
grid;
xlabel('t');ylabel('x(t)');title('x1*x3');
0 50 100 150-1
-0.5
0
0.5
1
t
x(t)
signal,x1(t)
0 50 100 150-0.4
-0.2
0
0.2
0.4
t
x(t)
signal,x2(t)
0 50 100 150-1
-0.5
0
0.5
1
t
x(t)
delayed x1(t),[x1(t-20)]
0 50 100 150-1
-0.5
0
0.5
1
t
x(t)
x1(t)+x2(t)
-
7/27/2019 Basic Simulation Lab
12/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 12
Expected Waveforms: Multiplication operation
%amplitudeand frequency scalingN=128;f1=150;
f2=450;
fs=8000;
n=0:N-1;x1=sin(2*pi*(f1/fs)*n);
x4=5*sin(2*pi*(f1/fs)*n);
%amplitude scalingsubplot(2,2,1);
plot(n,x1);
grid;title('original signal');
subplot(2,2,2);
plot(n,x2);grid;
title('amplitude scaling of a signal');
%frequency scalingf2=450;
x5=sin(2*pi*(f2/fs)*n);subplot(2,2,3);plot(n,x5);
grid;
xlabel('t');ylabel('x(t)');
title('frequency scaling');
0 50 100 150-1
-0.5
0
0.5
1
t
x(t)
signal,x1(t)
0 50 100 150-1
-0.5
0
0.5
1
t
x(t)
signal,x3(t)
0 50 100 150-1
-0.5
0
0.5
1x1*x3
-
7/27/2019 Basic Simulation Lab
13/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 13
Expected Waveforms: Amplitude scaling and Frequency Scaling
%time folding
t=0:0.1:10;x=0.5*t;
lx=length(x);
nx=0:lx-1;
xf=fliplr(x);nf=-fliplr(x);
subplot(1,2,1);stem(nx,x);
xlabel('n(x)');ylabel('x');
title('original signal');
subplot(1,2,2);
stem(nf,xf);
xlabel('nf');ylabel('xf');title('folding signal');
Expected Waveforms: Signal folding operation
0 50 100 150-1
-0.5
0
0.5
1original signal
0 50 100 150-0.4
-0.2
0
0.2
0.4amplitude scaling of a signal
0 50 100 150-1
-0.5
0
0.5
1
t
x(t)
frequency scaling
-
7/27/2019 Basic Simulation Lab
14/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 14
OPERATIONS ON SEQUENCE
%operations on sequence
N=5;
n=0:N-1;x1=[1,2,3,-2,7];
x2=[0,-1,4,3,-5];
subplot(2,2,1);stem(n,x1); grid;xlabel('n');ylabel('x(n)');
title('sequence,x1(n)');
subplot(2,2,2);stem(n,x2); grid;
xlabel('n');ylabel('x(n)');title('sequence,x2(n)');
%sequence additionxadd=x1+x2;
subplot(2,2,3);
stem(n,xadd);grid;
xlabel('n');ylabel('x(n)');
title('x1(n)+x2(n)');
%sequence multiplicationxmult=x1.*x2;
subplot(2,2,4);stem(n,xmult);grid;
xlabel('n');ylabel('x(n)');
title('x1(n)*x2(n)');
Expected Waveforms: Addition and Multiplication Oprations
0 5 100
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
n(x)
x
original signal
-6 -4 -2 00
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
nf
xf
folding signal
-
7/27/2019 Basic Simulation Lab
15/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 15
%operations on sequence
N=5;n=0:N-1;
x1=[1,2,3,-2,7];
x2=[0,-1,4,3,-5];%sequence subtraction
xsub=x1-x2;
subplot(2,2,1);
stem(n,xsub); grid;xlabel('n');ylabel('x(n)');
title('x1(n)-x2(n)');
subplot(2,2,2);stem(n,x1); grid;xlabel('n');ylabel('x(n)');
title('sequence,x1(n)');
%sequence delayx3=[zeros(1,2),x1(1:N-2)];
subplot(2,2,3);
stem(n,x3); grid;xlabel('n');ylabel('x(n)');
title('delayed x1(n),[x1(n-3)]');
%amplitude scaling of sequencex4=5*x1;
subplot(2,2,4);
stem(n,x4); grid;xlabel('n');ylabel('x(n)');
title('amplitude scaling of sequence,x1(n)');
Expected Waveforms: Subtraction , delay and scaling operation
0 1 2 3 4-5
0
5
10
n
x(n)
sequence,x1(n)
0 1 2 3 4-5
0
5
n
x(n)
sequence,x2(n)
0 1 2 3 40
2
4
6
8
n
x(n)
x1(n)+x2(n)
0 1 2 3 4-40
-20
0
20
n
x(n)
x1(n)*x2(n)
-
7/27/2019 Basic Simulation Lab
16/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 16
%time shiftingx=input('type sample');
n1=input('type time origin first sample');N=length(x);
n2=n1+N-1;
n=n1:n2;disp('the amount of shift');
disp('enter positive no. for delay,negative no. for advance');
pause;
d=input('enter desired amount of shift');nn=n+d;
xs=x;
subplot(2,1,1);stem(n,x);
xlabel('time index n(sec)');ylabel('x(n)');
title('original signal');subplot(2,1,2);
stem(nn,x);
xlabel('time index n(sec)');ylabel('x2(n)');title('time shifted signal');
Results in command window:
type sample [1 2 4 3 0]
type time origin first sample 1
the amount of shift
enter positive no. for delay, negative no. for advance
enter desired amount of shift 2
0 1 2 3 4-5
0
5
10
15
n
x(n)
x1(n)-x2(n)
0 1 2 3 4-5
0
5
10
n
x(n)
sequence,x1(n)
0 1 2 3 40
1
2
3
n
x(n)
delayed x1(n),[x1(n-3)]
0 1 2 3 4-20
0
20
40
n
x(n)
amplitude scaling of sequence,x1(n)
-
7/27/2019 Basic Simulation Lab
17/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 17
%energy sequence
n=0:1:5;
x1=(0.5).^n;disp('calculated energy E is ');
E=sum(abs(x).^2);
figuresubplot(1,2,1);stem(x1);axis([0 5 0 2]);
xlabel('n');ylabel('x(n)');
title('x1=(0.5).^n sequence');subplot(1,2,2);
stem(E);axis([0 5 0 3]);
xlabel('n');ylabel('x(n)');
title('energy sequence');
%power sequence
n=0:1:5;x2=0.8.^n;
disp('calculated power P is');
P=(sum(abs(x).^2))/length(x);figure
subplot(1,2,1);
stem(x2);axis([0 5 0 2]);xlabel('n');ylabel('x(n)');
title('x2=(0.8).^n sequence');
subplot(1,2,2);
stem(P);axis([0 5 0 0.5]);xlabel('n');ylabel('x(n)');
title('power sequence');
Results in command window:
calculated energy E is E = 2.5869
calculated power P is P = 0.4311
Expected Waveforms: Computation of Energy and Power
1 1.5 2 2.5 3 3.5 4 4.5 50
1
2
3
4
time index n(sec)
x(n)
original signal
3 3.5 4 4.5 5 5.5 6 6.5 70
1
2
3
4
time index n(sec)
x2(n)
time shifted signal
-
7/27/2019 Basic Simulation Lab
18/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 18
RESULT:Thus the different operations on signals and sequences were performed by usingMATLAB.
QUESTIONS:
1.What are the basic operations on signals?
The basic set of operations on signals are:
A)Time shifting b)Time reversal c)Time scaling d)Amplitude scaling e)Signal additionf)Signal multiplication
2.What is an analog signal?A.Continuous time signals are also called as analog signals.
3.What are digital signals?
A.The signals that are discrete in time and quantized in amplitude are called digital signals.
4.Distinguish between energy and power signals?
A.An energy signal is one whose total energy E=finite value and whose average power P=0.
Power signal is the one whose average power P=finite value and total energy E =infinity.
5.Distinguish between deterministic and random signals?
A.A deterministic signal is a signal exhibiting no uncertainity of its magnitude and phase at anygiven instant of time.It can be represented by a mathematical equation.
A random signal is a signal characterized by uncertainity about its occurrence.It cannot be
represented by a mathematical equation.
0 1 2 3 4 50
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
2
n
x(n)
x1=(0.5).nsequence
0 1 2 3 4 50
0.5
1
1.5
2
2.5
3
n
x(n)
energy sequence
0 1 2 3 4 50
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
2
n
x(n)
x2=(0.8).nsequence
0 1 2 3 4 50
0.05
0.1
0.15
0.2
0.25
0.3
0.35
0.4
0.45
0.5
n
x(n)
power sequence
-
7/27/2019 Basic Simulation Lab
19/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 19
EXPERIMENT-4
EVEN AND ODD PARTS OF SIGNALS AND SEQUENCES
AIM:To find the even and odd parts of signals
Requirements: PC with MATLAB R2008a
MATLAB Code:
%finding the even and odd part of the sequence x(n)=0.8^n
n=-5:1:5; %specify the range of n
A=0.8;x1=A.^n; %generate the given sequence
x2=A.^(-n); %generate the folded sequence
if(x2==x1)disp('the given sequence is even sequence');
elseif(x2==(-x1))
disp('the given sequence is odd sequence');else
disp('the given sequence is neither even nor odd signal');
end
-
7/27/2019 Basic Simulation Lab
20/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 20
xe=(x1+x2)/2; %compute even partxo=(x1-x2)/2; %compute odd part
subplot(2,2,1);stem(n,x1); %plot the generated sequencexlabel('n');ylabel('x1(n)');title('sequence,x(n)');
subplot(2,2,2);stem(n,x2); %plot the generated folded sequencexlabel('n');ylabel('x2(n)');
title('sequence,x(-n)');
subplot(2,2,3);stem(n,xe); %plot the generated even part of sequence
xlabel('n');ylabel('xe(n)');
title('even part of x(n)');
subplot(2,2,4);stem(n,xo); %plot the generated odd part of sequence
xlabel('n');ylabel('xo(n)');
title('odd part of x(n)');
Expected Waveforms: Even and odd parts of signal x(n)=0.8^n
%finding real and imaginary parts of signalt=[-0.5:0.01:0.5];
w=20;
y=exp(i*pi*w*t/2);
-5 0 50
1
2
3
4
n
x1(n)
sequence,x(n)
-5 0 50
1
2
3
4
n
x2(n)
sequence,x(-n)
-5 0 50
0.5
1
1.5
2
n
xe(n)
even part of x(n)
-5 0 5-2
-1
0
1
2
n
xo(n)
odd part of x(n)
-
7/27/2019 Basic Simulation Lab
21/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 21
a=real(y);
subplot(2,2,1);plot(t,a);
xlabel('t');ylabel('x(t)');
title('real part of signal');
b=imag(y);
subplot(2,2,2);plot(t,b);
xlabel('t');ylabel('x(t)');
title('imaginary part of signal');
c=abs(y);
subplot(2,2,3);plot(t,c);
axis([-0.5 0.5 0 2]);
xlabel('t');ylabel('x(t)');
title('absolute value');
d=angle(y);
subplot(2,2,4);plot(t,d);
xlabel('t');ylabel('x(t)');
title('phase angle');
Expected Waveforms: Real and Imaginary parts of signal and its magnitude & phase
-
7/27/2019 Basic Simulation Lab
22/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 22
RESULT: Thus the even and odd parts of real signals and complex signals were calculated
using MATLAB.
QUESTIONS:
1.Distinguish between even and odd signals?A.A continuous time signal x(t) is said to be even (symmetric) signal,if it satisfies the condition
X(-t)=x(t) for all t.If it is said to be odd (anti symmetric)signal if it satisfies the condition
X(-t)=-x(t) for all t.
A discrete time signal x(n) is said to bee even signal if it satisfies the conditionX(-n)=x(n) for all n.If it is said to be odd signal if it satisfies the condition
X(-n)=-x(n) for all n.
2.Can every signal be decomposed into even and odd parts?A.Yes,every signal can be decomposed into even and odd parts.
3.Write the expression for even and odd parts of signal?A.The even and odd parts of a continuous time signal are given by
Xe(t)=1/2[x(t)+x(-t)]
Xo(t)=1/2[x(t)-x(-t)]The even and odd parts of a discrete time signal are given by
Xe(n)=1/2[x(n)+x(-n)]
Xo(n)=1/2[x(n)-x(-n)]
4.Do all the signals correspond to either even or odd type?A.No ,All the signals need not necessarily belong to either even or odd type.There are signals
which are neither even nor odd.
5.Distinguish between causal and non causal signals?
A.A continuous time signal x(t) is said to be causal,if x(t)=o for t
-
7/27/2019 Basic Simulation Lab
23/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 23
EXPERIMENT-5
CONVOLUTION BETWEEN SIGNALS AND SEQUENCES
AIM:The convolution between signals and sequences
Requirements: PC with MATLAB R2008a
MATLAB Code:
% convolution between two signals
tmin=0;
tmax=4;dt=0.01;
t=tmin:dt:tmax;
x1=1.*(t>=0&t=0&t=1&t
-
7/27/2019 Basic Simulation Lab
24/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 24
%CONVOLUTION between two sequences
n= 0:1:4;n1=0:1:3;
x1=[2 -4 3 -1 5];
x2=[-1 2 -3 6];N1=length(x1);N2=length(x2);
x3=conv(x1,x2)
n2=0:1:N1+N2-2;
subplot(3,1,1); stem(n,x1);
xlabel('n'); ylabel('x1(n)');title('sequence x1(n)');
subplot(3,1,2); stem(n1,x2);
xlabel('n'); ylabel('x2(n)');title('sequence x2(n)');
subplot(3,1,3); stem(n2,x3);
xlabel('n'); ylabel('x3(n)');title('sequence,x3(n)=x1(n)*x2(n)');
Result in Command Window:x3 = -2 8 -17 31 -40 31 -21 30
Expected Waveforms:
%CONVOLUTION of x(t)=1/(1+t^2) itself
syms ttau;x=1/(1+t^2);
z=int(subs(x,tau)*subs(x,t-tau),tau,-inf,inf);
z1=simplify(z);pretty(z1);
figure;subplot(211); ezplot(x);
subplot(212); ezplot(z1);
0 0.5 1 1.5 2 2.5 3 3.5 4-5
0
5
n
x1(n)
sequence x1(n)
0 0.5 1 1.5 2 2.5 3-10
0
10
n
x2(n)
sequence x2(n)
0 1 2 3 4 5 6 7-50
0
50
n
x3(n)
sequence,x3(n)=x1(n)*x2(n)
-
7/27/2019 Basic Simulation Lab
25/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 25
Expected Waveforms:
Results:z1 = 2*i*pi/(t-2*i)/(-2+t*i)
Ans:
2 i pi
--------------------(t - 2 i) (-2 + t i)
%CONVOLUTION of x(t)=exp(-t^2);h(t)=3*t^2;
syms ttau;x=exp(-t^2);
h=3*t^2;
z=int(subs(x,tau)*subs(h,t-tau),tau,-inf,inf);
z1=simplify(y)figure();
subplot(211);ezplot(x);
subplot(212);ezplot(h);figure;
ezplot(z);
Expected Waveforms: Input Signal x(t) and h(t)
-5 -4 -3 -2 -1 0 1 2 3 4 5
0
0.5
1
t
original signal x (t)=1/(1+t2)
-6 -4 -2 0 2 4 60
0.5
1
1.5
t
Convolution of x(t)=1/(1+t2) and itself
-2.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5 20
0.5
1
t
exp(-t2)
-6 -4 -2 0 2 4 6
0
50
100
t
3 t2
-
7/27/2019 Basic Simulation Lab
26/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 26
Output: CONVOLUTION of x(t)=exp(-t^2);h(t)=3*t^2
z1 = 3*t^2*pi^(1/2)+3/2*pi^(1/2)
2 1/2 1/23 t pi + 3/2 pi
RESULT:Thus the convolution between signals and sequences were verified using MATLAB.
QUESTIONS:
1.What is meant by convolution?A.It is a mathematical way (multiplication and addition)if combininig two signals to form a thirdsignal.
2.What is the associative property of convolution?A. x1(t)*[x2(t)*x3(t)] = [x1(t)*x2(t)*]x3(t) where x1(t),x2(t) and x3(t) are three real signals.
3.What is the convolution of a signal with an impulse?
A.The convolution of a signal with an impulse is equal to that signal itself.
4.State time convolution theorem?
A.The time convolution theorem states that the convolution in time domain is equivalent tomultiplication of their spectra in frequency domain.mathematically,if x1(t)X1(w) andx2(t)X2(w)
Then x1(t)*x2(t)X1(w) X2(w)
5.State frequency convolution theorem?
A.It states that the multiplication of two functions in time domain is equal to convolution of their
spectra in frequency domain.Mathematically, if x1(t)X1(w) and x2(t)X2(w)Then x1(t) x2(t)1/2pi[X1(w)*X2(w)]
-6 -4 -2 0 2 4 6
0
50
100
150
200
t
3 t21/2+3/2 1/2
-
7/27/2019 Basic Simulation Lab
27/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 27
EXPERIMENT-6
AUTOCORRELATION AND CROSSCORRELATION
BETWEEN SIGNALS AND SEQUENCES
AIM:To find autocorrelation and cross correlation between signals and sequences.
Requirements: PC with MATLAB R2008a
MATLAB Code:
%CROSS CORRELATION:
N=1024;
F=1;Fs=200;
n=0:N-1;x=sin(2*pi*F*n/Fs);
y=x+10*randn(1,N);subplot(3,1,1); plot(x);
title('pure sine wave');grid;
subplot(3,1,2); plot(y); grid;
title('y(n), pure sine wave + noise');Rxy=xcorr(x,y);
subplot(3,1,3);
plot(Rxy); grid;title('cross correlation Rxy');
%AUTOCORRELATION:N=1024;
f1=1;
Fs=200;
n=0:N-1;x=sin(2*pi*f1*n/Fs);
t=[1:N]*(1*Fs);
subplot(2,1,1);plot(t,x); grid;
title('sin wave of frequency 1000 hz[Fs=8000 hz]');
xlabel('time,(s)'); ylabel('amplitude');Rxy=xcorr(x);subplot(2,1,2);
plot(Rxy); grid;
title('auto crrelation function of the sine wave');xlabel('lags'); ylabel('auto correlation');
-
7/27/2019 Basic Simulation Lab
28/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 28
Expected Waveforms:%CROSS CORRELATION:
%AUTO CORRELATION:
RESULT:Thus the cross correlation and auto correlation of different signals and sequences
were verified using MATLAB.
QUESTIONS:
1.What is meant by correlation?
A: Correlation is measure of the degree of the similarity between two signals.
2. What is auto correlation?
A. Auto correlation is the measure of similarity of a signal with its delayed version.
3. What is meant by cross correlation?
A. Correlation between the two different signals is called cross correlation.
4. What is the autocorrelation function at the origin?
A. Auto correlation at the origin equals to its energy.
5. What is meant by Parsevals theorem?
A. Total average power of a periodic signal x(t) is the sum of the squares of its fourier
coefficients.
0 200 400 600 800 1000 1200-1
0
1
time
x1
pure sine wave
0 200 400 600 800 1000 1200-1
0
1
time
cosine
y(n),cosine wave
-1500 -1000 -500 0 500 1000 1500-500
0
500
time
Rxy
cross correlation Rxy
0 0.5 1 1.5 2 2.5
x 105
-1
-0.5
0
0.5
1sin wave of frequency 1000 hz[Fs=8000 hz]
time,(s)
amplitude(x)
-1500 -1000 -500 0 500 1000 1500-500
0
500
1000auto crrelation function of the sine wave
time
autocorrelation(Rxx
-
7/27/2019 Basic Simulation Lab
29/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 29
EXPERIMENT-7
VERIFICATION OF LINEARITY AND TIME INVARIENCE PROPERTIES
AIM:To verify the linearity and time-invariance property Reconstruction of a periodic signal byFourier series.
Requirements: PC with MATLAB R2008a
MATLAB Code:
%LINEARITY:
x1=input('type the samples of x1');
x2=input('type the samples of x2');
if(length(x1)~=length(x2));disp('error:lengths of x1 & x2 are diffrent');return;
end;
h=input('type the samples of h');
N=length(x1)+length(x2)-1;disp('length of the output signal will be');
disp(N);
a1=input('the scale factor a1 is');a2=input('the scale factor a2 is');
x=a1*x1+a2*x2
y01=conv(x,h)y1=conv(x1,h)
ys1=a1*y1
y2=conv(x2,h)ys2=a2*y2
y02=ys1+ys2
disp('input signal x1 is');
disp(x1);disp('input signal x2 is');
disp(x2);
disp('output sequence y01 is');
disp(y01);disp('output sequence y02 is');
disp(y02);
if(y01==y02)disp('y01=y02,hence the LTI system is linear');
end;
-
7/27/2019 Basic Simulation Lab
30/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 30
COMMAND WINDOW:
a)Verification of Lineariy:
type the samples of x1[1 2 3 4]type the samples of x2[2 3 4 5]type the samples of h[1 2 3 4 5 6 7]
length of the output signal will be 7
the scale factor a1 is3the scale factor a2 is2
x =7 12 17 22
y01 = 7 26 62 120 178 236 294 296 251 154
y1 = 1 4 10 20 30 40 50 52 45 28
ys1 = 3 12 30 60 90 120 150 156 135 84
y2 = 2 7 16 30 44 58 72 70 58 35
ys2 = 4 14 32 60 88 116 144 140 116 70
y02 = 7 26 62 120 178 236 294 296 251 154
input signal x1 is 1 2 3 4
input signal x2 is 2 3 4 5
output sequence y01 is
7 26 62 120 178 236 294 296 251 154
output sequence y02 is
7 26 62 120 178 236 294 296 251 154
y01=y02,hence the LTI system is linear
-
7/27/2019 Basic Simulation Lab
31/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 31
%TIME INVARIENT:
x=input('type the sample of signal x(n)');
h=input('type the samples of signal h(n)');
y=conv(x,h);disp('enter a positive number for delay');
d=input('desired delay of the signals is');
xd=[zeros(1,d),x];nxd=0:length(xd)-1;
yd=conv(xd,h);
nyd=0:length(yd)-1;disp('original input signal x(n) is');
disp(x);
disp('delayed input signal xd(n) is');disp(xd);
disp('original output signal y(n) is');disp(y);
disp('delayed output signal yd(n) is');disp(yd);
xp=[x,zeros(1,d)];
figure
subplot(2,1,1); stem(nxd,xp);grid;xlabel('time index n'); ylabel('x(n)');
title('original input signal x(n)');
subplot(2,1,2); stem(nxd,xd); grid;xlabel('time index n'); ylabel('xd(n)');
title('delayed input signal xd(n)');yp=[y,zeros(1,d)];figure
subplot(2,1,1); stem(nyd,yp); grid;
xlabel('time index n'); ylabel('y(n)');title('original output signal y(n)');
subplot(2,1,2); stem(nyd,yd); grid;
xlabel('time index n'); ylabel('yd(n)');
title('delayed output signal yd(n)');
COMMAND WINDOW:
b)Verification of Time Invarience:
type the sample of signal x(n)[1 2 3 4]
type the samples of signal h(n)[2 3 4 5 ]
enter a positive number for delaydesired delay of the signals is 4
original input signal x(n) is 1 2 3 4
delayed input signal xd(n) is 0 0 0 0 1 2 3 4
original output signal y(n) is 2 7 16 30 34 31 20
delayed output signal yd(n) is 0 0 0 0 2 7 16 30 34 31 20
-
7/27/2019 Basic Simulation Lab
32/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 32
Expected Waveforms:
RESULT:Thus the linearity and timeinvarient properties of an LTI system were verified using
MATLAB.
QUESTIONS:
1.What i s meant by linear system?
A.A system is said to be linear if it satisfies the superposition principle.
2.What is meant by time-invariant system?A.A system is said to be time-invariant if the i/p-o/p relationship does not vary with time
3.What is meant by causal system?A.A system is said to be causal if the o/p depends only on the values of present i/p.
4.What is meant by stable system?A.A system is said to be stable if bounded i/p results in bounded o/p.
5.What is meant by order of a system?
A.The order of a continuous system corresponds to highest derivative of o/p signal which may
appear in i/po/p differentialequation.
0 1 2 3 4 5 6 70
1
2
3
4
time index n
x(n)
original input signal x(n)
0 1 2 3 4 5 6 70
1
2
3
4
time index n
xd(n)
delayed input signal xd(n)
0 1 2 3 4 5 6 7 8 9 100
10
20
30
40
time index n
y(n)
original output signal y(n)
0 1 2 3 4 5 6 7 8 9 100
10
20
30
40
time index n
yd(n)
delayed output signal yd(n)
-
7/27/2019 Basic Simulation Lab
33/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 33
EXPERIMENT-8
RESPONSE OF THE LTI SYSTEM
AIM:To compute unit sample, unit step response of the LTI systems.
Requirements: PC with MATLAB R2008a
MATLAB Code:
%IMPULSE RESPONSE OF LTI SYSTM:
clear all
syms zn
H=1/(1-0.8*(z^(-1))+0.16*(z^(-2)));disp('impulse response h(n) is');
h=iztrans(H)
simplify(h)
N=15;b=[1 0 0];
a=[1 -0.8 0.16];
[H,n]=impz(b,a,N);
stem(n,H);xlabel('n'); ylabel('h(n)');
title('Impulse response of a LTI system');
Expected Waveforms:
0 2 4 6 8 10 12 140
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
n
h(n)
Impulse response of a LTI system
-
7/27/2019 Basic Simulation Lab
34/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 34
%UNIT STEP RESPONSE OF LTI SYSTM:
syms scomplex
H1=5/(s^2+25);
disp('step response of first order system is:');h1=ilaplace(H1)simplify(h1)
H2=1/((s-0.8)^2);
disp('step response of second order system');h2=ilaplace(H2)
simplify(h2)
s=tf('s');H1=1/(s+2);
H2=1/(s^2+2.5*s+25);
t1=0:0.005:5;
s1=step(H1,t1);s2=step(H2,t1);
subplot(2,1,1); plot(t1,s1);
xlabel('time in seconds');
ylabel('s1(t)');title('step response of first order system');
subplot(2,1,2); plot(t1,s2);
xlabel('time in seconds');ylabel('s2(t)');
title('step response of second order system');
Expected Waveforms:
RESULT:Thus the step and impulse response of LTI system were verified using MATLAB.
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 50
0.2
0.4
0.6
0.8
time in seconds
s1(t)
step response of first order system
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 50
0.02
0.04
0.06
time in seconds
s2(t)
step response of second order system
-
7/27/2019 Basic Simulation Lab
35/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 35
QUESTIONS:
1.What is meant by system?
A:A set of elements or functional blocks which are connected together and produces an output in
response to an input signal.
2.What is meant by continuous time system?
A:A continuous time system is one in which continuous time i/p signals are transformedcontinuous time o/p signals.
3. What is meant by discrete time system?A: A discrete time system is one in which discrete time i/p signals are transformed discrete time
o/p signals.
4.What is meant by step response of a discrete system?
A:The step response of a discrete-time LTI system is the running sum of its impulse response.
5.What is meant by an impulse response ?
A:The impulse response specifies the i/p-o/p behavior of an LTI system.
-
7/27/2019 Basic Simulation Lab
36/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 36
EXPERIMENT-9
RECONSTRUCTION OF PERIODIC SIGNAL BY FOURIER SERIES
OR GIBBS PHENOMENON
AIM:To Reconstruct a periodic signal by Fourier series.
Requirements: PC with MATLAB R2008a
MATLAB Code:
%gibbs phenomenon
N=input('type the total number of harmonics');t=0:0.001:1;
y=square(2*pi*t);
plot(t,y,'r','linewidth',2);
axis([0 1.5 -1.5 1.5]);
hold;
sq=zeros(size(t));
forn=1:2:N;
sq=sq+((4/(pi*n))*sin(2*pi*n*t));
end;
plot(t,sq);
grid;xlabel('t');
ylabel('sq(t)');
title('synthesized square wave using Fourier Series');legend('N=0','N=3');
COMMAND WINDOW:
type the total number of harmonics 3
Expected Waveforms:
0 0.5 1 1.5-1.5
-1
-0.5
0
0.5
1
1.5
t
s
q(t)
synthesized square wave using Fourier Series
N=0
N=3
-
7/27/2019 Basic Simulation Lab
37/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 37
COMMAND WINDOW:
type the total number of harmonics 5
Expected Waveforms:
COMMAND WINDOW:
type the total number of harmonics111
Expected Waveforms:
RESULT: Thus the extraction of a periodic signal was performed successfully using
MATLAB.
0 0.5 1 1.5-1.5
-1
-0.5
0
0.5
1
1.5
t
sq(t)
synthesized square wave using Fourier Series
N=0
N=5
0 0.5 1 1.5-1.5
-1
-0.5
0
0.5
1
1.5
t
sq(t)
synthesized square wave using Fourier Series
N=0
N=111
-
7/27/2019 Basic Simulation Lab
38/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 38
QUESTIONS:
1.What do you mean by gibbs phenomenon?
A.Gibbs discovered that for a periodic signal with discontinuities, if the signal is reconstructed
by adding the fourier series ,overshoots appear around the edges.These overshoots decayoutwards in a damped oscillatory manner away from the edges.This is called Gibbs
Phenomenon.
2.What is fourier spectrum?
A.The fourier spectrum of a periodic signal is x(t) is a plot of its Fourier coefficients versus
frequency w.It is in two parts:a)The amplitude spectrum b)Phase spectrum
3.What is fourier series?
A.The representation of signals over a certain interval of time in terms of the linear combination
of orthogonal functions is called fourier series.
4.What are Dirichlets conditions?
A.The conditions under which a periodic signal can be represented by a Fourier series are known
as Dirichlets conditions.They are:
a)The function x(t) must be a single valued function
b)The function x(t) has only a finite number of maxima and minima
c)The function x(t) has a finite number of discontinuities.
d)The function x(t)is absolutely integrable over one period,that is integral(0,t)[l(x(t)ldt]
-
7/27/2019 Basic Simulation Lab
39/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 39
EXPERIMENT-10
FINDING FOURIER TRANSFORM
AIM: To find the Fourier Transform of a various signals such as cosine, sine, impulse, step,
square and rectangular signals
Requirements: PC with MATLAB R2008a
MATLAB Code:
%cosine signalclc;clear all;
f=100;fs=1000;
Fs=1/fs;
N=1024;n=[0:N-1]*Fs;
x=0.8*cos(2*pi*f*n);
figure;
plot(n,x); grid;axis([0 0.05 -1 1]);
title('cosine signal of frequency f');
xlabel('time t(sec)');ylabel('x(t)');
xk=fft(x,N);
k=0:N-1;figure;
xmag=abs(xk);subplot(2,1,1);
plot(k,xmag); grid;
title('magnitude of Fourier Transform');
xlabel('frequency index,k');ylabel('magnitude');
subplot(2,1,2);plot(k,angle(xk)); grid;
title('phase of fourier transform');
xlabel('frequency index,k');ylabel('phase');
Expected Waveforms:
-
7/27/2019 Basic Simulation Lab
40/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 40
%sine signal
clc;clear all;f=100;
fs=1000;
Fs=1/fs;N=1024;
n=[0:N-1]*Fs;
x=0.8*sin(2*pi*f*n);figure;
plot(n,x);
grid;axis([0 0.05 -1 1]);
title('sine signal of frequency f');xlabel('time t(sec)');ylabel('x(t)');
xk=fft(x,N);
k=0:N-1;
figure;
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1cosine signal of frequency f
time t(sec)
x(t)
0 200 400 600 800 1000 12000
100
200
300
400magnitude of Fourier Transform
frequency index,k
m
agnitude
0 200 400 600 800 1000 1200-2
-1
0
1
2phase of fourier transform
frequency index,k
phase
-
7/27/2019 Basic Simulation Lab
41/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 41
xmag=abs(xk);subplot(2,1,1);
plot(k,xmag);
grid;title('magnitude of Fourier Transform');xlabel('frequency index,k');ylabel('magnitude');
subplot(2,1,2);plot(k,angle(xk));
grid;
title('phase of fourier transform');xlabel('frequency index,k');ylabel('phase');
Expected Waveforms:
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1sine signal of frequency f
time t(sec)
x(t)
0 200 400 600 800 1000 12000
100
200
300
400magnitude of Fourier Transform
frequency index,k
magnitude
0 200 400 600 800 1000 1200-4
-2
0
2
4phase of fourier transform
frequency index,k
pha
se
-
7/27/2019 Basic Simulation Lab
42/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 42
%square signal
clc;clear all;f=100; fs=900;
Fs=1/fs;
N=1024;n=[0:N-1]*Fs;
x=0.5*square(2*pi*f*n);
figure;plot(n,x); grid; axis([0 0.05 -1 1]);
title('square signal of frequency f'); xlabel('time t(sec)');ylabel('x(t)');
xk=fft(x,N);
k=0:N-1;
figure;
xmag=abs(xk);
subplot(2,1,1);
plot(k,xmag); grid;
title('magnitude of Fourier Transform');xlabel('frequency index,k');ylabel('magnitude');
subplot(2,1,2); plot(k,angle(xk)); grid;title('phase of fourier transform');
xlabel('frequency index,k');ylabel('phase');
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1square signal of frequency f
time t(sec)
x(t)
0 200 400 600 800 1000 12000
100
200
300
400
magnitude of Fourier Transform
frequency index,k
magnitude
0 200 400 600 800 1000 1200-4
-2
0
2
4
phase of fourier transform
frequency index,k
phase
-
7/27/2019 Basic Simulation Lab
43/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 43
%impulse signal
n=-20:2:20;N=1024;
x1=1;
x2=0;
x=x1.*(n==0)+x2.*(n~=0);
figure;
stem(n,x);grid;axis([-20 20 -1 1]);
title('impulse signal');
xlabel('time n(sec)');ylabel('x(n)');
xk=fft(x,N);
k=0:N-1;
figure;
xmag=abs(xk);
subplot(2,1,1);
plot(k,xmag); grid;title('magnitude of Fourier Transform');
xlabel('frequency index,k');ylabel('magnitude');
subplot(2,1,2);
plot(k,angle(xk)); grid;
title('phase of fourier transform');
xlabel('frequency index,k');ylabel('phase');
-20 -15 -10 -5 0 5 10 15 20-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1impulse signal
time n(sec)
x(n)
0 200 400 600 800 1000 12001
1
1
1magnitude of Fourier Transform
frequency index,k
magnitude
0 200 400 600 800 1000 1200-4
-2
0
2
4phase of fourier transform
frequency index,k
phase
-
7/27/2019 Basic Simulation Lab
44/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 44
%rectangular pulse
n=-20:2:20;t=-10:1:10;
f=1/20;
x=square(2*pi*f*t,75);figure;
stem(n,x);grid; axis([0 40 -1 1]);
title('rectangular pulse'); xlabel('time n(sec)');ylabel('x(n)');
xk=fft(x,N);
k=0:N-1;figure;
xmag=abs(xk);
subplot(2,1,1);plot(k,xmag); grid; title('magnitude of Fourier Transform');
xlabel('frequency index,k');ylabel('magnitude');
subplot(2,1,2);plot(k,angle(xk)); grid;
title('phase of fourier transform');
xlabel('frequency index,k');ylabel('phase');
0 5 10 15 20 25 30 35 40-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1rectangular pulse
time n(sec)
x(n)
0 200 400 600 800 1000 12000
5
10
15magnitude of Fourier Transform
frequency index,k
magnitude
0 200 400 600 800 1000 1200-4
-2
0
2
4phase of fourier transform
frequency index,k
phase
-
7/27/2019 Basic Simulation Lab
45/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 45
%step signal
n=-20:2:20;N=1024;
x1=1;
x2=0;
x=x1.*(n>=0)+x2.*(n
-
7/27/2019 Basic Simulation Lab
46/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 46
% Fourier Transform Rectangular Pulse
z = int(x*expw, omega,-2,2);
z=simplify(z);
figure();subplot(211);ezplot('2',[-2,2]);
subplot(212);ezplot(z);
Expected Waveforms:
RESULT: Thus the computation of Fourier transform of a given signal was done using
MATLAB.
QUESTIONS:
1.What is Fourier transform?
A.Fourier transform is a transformation technique which transforms signals from the continuous
time domain into frequency domain and vice versa.
2.Write the formulae for Fourier transform and inverse fourier transform?A.The formula for Fourier transform,also called the equation for direct transform or analysis
equation is:
X(w)=integral(-infinity,infinity)[x(t)e^(-jwt)dt]
The formulae for I.F.T also called the equation for inverse transform or the synthesis equation is:
x(t)=1/2pi[integral(-infinity,infinity)[X(W)e^(jwt)dw]]
3.What is frequency spectrum?
A.The plot of lX(w)l versus w is known as magnitude spectrum or amplitude spectrum,and theplot of LX(w) versus w is known as phase spectrum.The amplitude spectrum and phase spectrum
together is called the frequency spectrum.
4.What are the limitations of F.T?
A.a)It is less powerful than Laplace transformation.
b)There are many functions for which the laplace transform exists,but the fourier transform does
not exist.
5.What is CTFT?
A.CTFT(continuous time fourier transform) is the F.T applied to continuous time signals.In
general CTFT is called as Fourier Transform.
-2 -1.5 -1 -0.5 0 0.5 1 1.5 21
1.5
2
2.5
3
x
2
-6 -4 -2 0 2 4 6
-2
0
2
4
6
8
t
4/t sin(2 t)
-
7/27/2019 Basic Simulation Lab
47/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 47
EXPERIMENT-11
FINDING THE LAPLACE TRANSFORM OF GIVEN FUNCTIONS
AIM: To write a MATLAB program to find the Laplace transform of a given
signal. F(t)=1.5-2.5te^-2t+1.25e^-3t
Requirements: PC with MATLAB R2008a
MATLAB Code:
syms ts;
f=1.5 -2.5 * t * exp(-2*t)+1.25 * exp(-3*t);f = laplace(f, t, s)
simplify(f)pretty(ans)
COMMAND WINDOW:
Expected Results:
3/2/s-5/2/(s+2)^2+5/4/(s+3)
ans =3/2/s-5/2/(s+2)^2+5/4/(s+3)
ans =1/4*(11*s^3+52*s^2+86*s+72)/s/(s+2)^2/(s+3)
3 2
11 s + 52 s + 86 s + 721/4 -------------------------
2
s (s + 2) (s + 3)
RESULT:Thus the computation of Laplace transform of a given signal was done using
MATLAB.
-
7/27/2019 Basic Simulation Lab
48/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 48
QUESTIONS:
1.How is laplace transform useful in the analysis of LTI system?
A.The laplace transform is a powerful mathematical technique used to convert the differential
equations in time domain into algebraic equations in s-domain.
2.What is the region of convergence(ROC)?
A.The set of points in the s plane for which the laplace transform of x(t) ,i.e. the function X(s)
converges is called the ROC.
3.What is the usual condition for x(t) to be laplace transformable?
A.The usual condition for x(t) to be laplace transformable is that it should be piece-wise
continuous and must be of exponential order.
4.What is the relation between F.T and L.T?
a.Laplace transform is a complex fourier transform.The Fourier transform of a function can be
obtained from its laplace transform by replacing s by jw,i.e. F.T is the L.T evaluated along the
imaginary axis of the s plane.
5.What is transient response?
A.The transient response is the response due to the poles of the system function H(s).It vanishesafter some time and hence is called the transient response of the system.
-
7/27/2019 Basic Simulation Lab
49/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 49
EXPERIMENT-12
LOCATING POLES AND ZEROS IN S-PLANE AND Z-PLANE
AIM: To write a MATLAB program to find the location of poles and zeros, and plotting thepole-zero maps in S-plane and Z-plane for given transfer function.
Requirements: PC with MATLAB R2008a
MATLAB Code:
%LOCATING POLES AND ZEROS ON S PLANE
syms s
num_coeff=[1 5 6];
disp('roots of numerator polynomial are');zeros=roots(num_coeff)
den_coeff=[1 9 20];
disp('roots of denominator polynomial are');
poles=roots(den_coeff)H=tf('s');
a=tf([num_coeff],[den_coeff]);
grid on;pzmap(a);
if(max(real(poles)))>=1
disp('all poles DO NOT LIE in the left Half of S-plane');
disp('The given LTI system is NOT a stable system');else
disp('ALL the POLES lie in the Left half of S-plane');
disp('The given LTI system is a STABLE system');end;
-
7/27/2019 Basic Simulation Lab
50/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 50
Command Window:
case(1):num_coeff = [1 5 6]den_coeff = [1 9 20]
roots of numerator polynomial are
zeros =
-3.0000
-2.0000
roots of denominator polynomial are
poles =
-5.0000
-4.0000
ALL the POLES lie in the Left half of S-plane
The given LTI system is a STABLE system
Expected Waveforms:
Pole Zero map of S-plane:
-5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
10.40.660.820.90.9450.974
0.99
0.997
0.40.660.820.90.9450.974
0.99
0.997
1234
Pole-Zero Map
Real Axis
ImaginaryAxis
-
7/27/2019 Basic Simulation Lab
51/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 51
COMMAND WINDOW:
Case(2):num_coeff = [1 5 6]den_coeff = [1 -9 20]
roots of numerator polynomial are
zeros =
-3.0000-2.0000
roots of denominator polynomial are
poles =
5.00004.0000
all poles DO NOT LIE in the left Half of S-plane
The given LTI system is NOT a stable system
Expected Waveforms:
-4 -3 -2 -1 0 1 2 3 4 5-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
10.60.860.930.966
0.982
0.992
0.997
0.999
0.60.860.930.966
0.982
0.992
0.997
0.999
0.511.522.533.5
Pole-Zero Map
Real Axis
Ima
ginaryAxis
-
7/27/2019 Basic Simulation Lab
52/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 52
%Z-PLANE:
syms z
num_coeff=[1 3 5];
disp('roots of numerator polynomial are');zeros=roots(num_coeff)den_coeff=[1 1 0.16];
disp('roots of denominator polynomial are');
poles=roots(den_coeff)H=tf('z');
a=tf([num_coeff],[den_coeff]);
radpoles=abs(poles);grid on;
pzmap(a);
ifmax(radpoles)
-
7/27/2019 Basic Simulation Lab
53/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 53
Case(2):num_coeff=[1 3 5];
den_coeff=[1 0.5 -1.25];
roots of numerator polynomial are
zeros =
-1.5000 + 1.6583i
-1.5000 - 1.6583i
roots of denominator polynomial are
poles =
-1.3956
0.8956
all the poles donot lie with in the unit circle
the given LTI system is not a stable system
>>
RESULT:Thus the poles and zeros in S-Plane and Z-Plane were located and plotted using
MATLAB.
-2 -1.5 -1 -0.5 0 0.5 1-2
-1.5
-1
-0.5
0
0.5
1
1.5
2Pole-Zero Map
Real Axis
ImaginaryAxis
-
7/27/2019 Basic Simulation Lab
54/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 54
QUESTIONS:
1.What are the advantages and limitations of Z-Transforms?A.Advantages of Z-Transform:
1.They convert the difference equations of a discrete time system into linear algebraic equations
so that the analysis become easy and simple.
2.Convolution in time domain is converted into multiplication in Z-domain.
3.Z-transform exists for most of the signals for which DTFT does not exist.
Limitation:Frequency domain response cannot be achieved and cannot be plotted
2.What is ROC of Z-Transform?
A.The range of values of lzl for which X(z) converges is called ROC of X(z).
3.What is the ROC of an infinite duration causal sequences?
A.The ROC of an infinite duration causal sequences is lzl>alpha,i.e. it is the exterior of a circle
of radius alpha where z=alpha is the largest pole in X(z).
4.What is the ROC of an infinite duration non causal sequences?
A.The ROC of an infinite duration non causal sequences is lzlX2(z)
then ax1(n)+bx2(n)---->aX1(Z)+bX2(z)
-
7/27/2019 Basic Simulation Lab
55/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 55
EXPERIMENT-13
RANDOM NOISE SIGNAL GENERATION
AIM: To write a MATLAB program to generate the random noise signal.
Requirements: PC with MATLAB R2008a
MATLAB Code:
clear all;
x1=randn(1,5000);x2=randn(1,5000);
figure;plot(x1,x2,'.')
title('scatter plot of gaussian distributed random numbers');
x1=rand(1,5000);
x2=rand(1,5000);
figure;plot(x1,x2,'.')
title('scatter plot of uniform distributed random numbers');
x3=rand(1,100000);
figure;subplot(2,1,1);hist(x3)title('uniform distribution')
y=randn(1,100000);
subplot(2,1,2);hist(y)
title('gaussian distribution')
ymu=mean(y);
ymsq=sum(y.^2)/length(y);ysigma=std(y);
yvar=var(y);
yskew=skewness(y);ykurt=kurtosis(y);
EXPECTED GRAPH :
-4 -3 -2 -1 0 1 2 3 4-4
-3
-2
-1
0
1
2
3
4scatter plot of gaussian distributed random numbers
-
7/27/2019 Basic Simulation Lab
56/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 56
RESULT:Thus the different characteristics of a random noise signal were verified using
MATLAB.
QUESTIONS:
1. What is meant by Mean of a signal?Ans: Mean is the average value of a signal and is a natural measure of center of distribution.
It is obtained by adding all the values xi of a signal and div iding by N, the total number ofvalues, as
sum(xi)/N from i=0 to N-1
2. What is meant by Mean squqre of a signal?Ans:The summation of a squared sample values of the signal and its average.
3. What is meant by standard deviation of a signal?Ans:the standard deviation is a measure of how far the signal fluctuates from the mean.
4.What is meant by varience?
Ans:The square of the standard deviation is called the varience of the signal.
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
0.10.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1scatter plot of uniform distributed random numbers
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
10
5000
10000
15000uniform distribution
-5 -4 -3 -2 -1 0 1 2 3 4 50
1
2
3
4x 104 gaussian distribution
-
7/27/2019 Basic Simulation Lab
57/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 57
EXPERIMENT-14
VERIFICATION OF SAMPLING THEOREM
AIM: To write a MATLAB code for verification of Sampling theorem.
Requirements: PC with MATLAB R2008a
MATLAB Code:
% MATLAB Code for Verification of Sampling Theorem
t = -5 : 0.0001 : 5;
F1 = 3; F2 = 23;
x = cos(2*pi*F1*t) + cos (2*pi*F2*t);
figure(1); plot(t,x);axis([-0.4 0.4 -2 2])
xlabel('Time t(sec)'); ylabel('x(t)');title('Continuous Time Signal : x(t) = cos(2*pi*F1*t) + cos (2*pi*F2*t)');
%CASE 1
Fs1 = 1.4*F2; ts1 = 1/Fs1; %set the sampling freq to be 1.4 times Fmax=F2
n1 = -0.4 : ts1 : 0.4;xs1 = cos(2*pi*F1*n1) + cos (2*pi*F2*n1);
figure(2); stem(n1,xs1);
hold on; plot(t, x, 'r:');
axis([-0.4 0.4 -2 2]); hold off;xlabel('Time samples (n)'); ylabel('Amplitude');
title('Discrete Time Signal'); legend('Fs < 2Fmax');
%CASE 2
Fs2 = 2*F2; ts2 = 1/Fs2; %set the sampling freq to be 1.4 times Fmax=F2
n2 = -0.4 : ts2 : 0.4;xs2 = cos(2*pi*F1*n2) + cos (2*pi*F2*n2);
figure(3); stem(n2,xs2);
hold on; plot(t, x, 'r:');
axis([-0.4 0.4 -2 2]); hold off;xlabel('Time samples (n)'); ylabel('Amplitude');
title('Discrete Time Signal'); legend('Fs = 2Fmax');
%CASE 3
Fs3 = 7*F2; ts3 = 1/Fs3; %set the sampling freq to be 1.4 times Fmax=F2
n3 = -0.4 : ts3 : 0.4;xs3 = cos(2*pi*F1*n3) + cos (2*pi*F2*n3);
figure(4); stem(n3,xs3);
hold on; plot(t, x, 'r:');
axis([-0.4 0.4 -2 2]); hold off;xlabel('Time samples (n)'); ylabel('Amplitude');
title('Discrete Time Signal'); legend('Fs > 2Fmax');
-
7/27/2019 Basic Simulation Lab
58/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 58
Expected Waveforms:
-0.4 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
Time t(sec)
x(t)
Continuous Time Signal : x(t) = cos(2*pi*F1*t) + cos (2*pi*F2*t)
-0.4 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
Time samples (n)
Amplitude
Discrete Time Signal
Fs < 2Fmax
-
7/27/2019 Basic Simulation Lab
59/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 59
RESULT:Thus the Sampling theorem was verified successfully using MATLAB.
-0.4 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
Time samples (n)
Amp
litude
Discrete Time Signal
Fs = 2Fmax
-0.4 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
Time samples (n)
Amplitude
Discrete Time Signal
Fs > 2Fmax
-
7/27/2019 Basic Simulation Lab
60/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 60
QUESTIONS:
1.What is sampling?
A.Sampling is the process of converting a continuous time signal into a discrete time signal.
2.What is sampling period?
A.Sampling period or a sampling interval is the time interval between successive samples.
3.What is Nyquist rate?
A.Nyquist rate is the theoretical minimum sampling rate at which a signal can be sampled and
still be rteconstructed from its samples without any distortion.
4.What is aliasing?
A.Aliasing is defined as the phenomenon in which a high frequency component in the frequency
spectrum of signal takes identity of a lower frequency component in the spectrum of the samplesignal.
5.State sampling theorem?
A.The sampling theorem also called uniform sampling theorem or low pass sampling theorem
states thatA band limited x(t) with X(w)=0 for lwl>=wm can be represented intoand uniquely
determined from its samples x(nT), if the sampling frequency fs>=2fm,where fm is the highestfrequency component present in it.
-
7/27/2019 Basic Simulation Lab
61/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 61
EXPERIMENT-15
NOISE REMOVAL USING CORRELATION
AIM: To Write a MATLAB Code for Noise Removal using cross correlation or auto correlation.
Requirements:PC with MATLAB R2008a
MATLAB Code:clear all;
N=100;
n=0:N-1;dsnr=input('type desired SNR in dB');
x=sqrt(2)*sin((pi/5)*n);
figure(1);stem(n,x);grid
%axis([0 50 -1.5 1.5])xlabel('n');ylabel('x(n)');title('sinusoidal signal x(n)')
px=var(x) ;an=sqrt(px*(10^(-1*dsnr/10)));
w=sqrt(12)*(rand(1,N)-0.5);
w=w*an;
pn=var(w);disp('The calculated SNR');
SNRdB=10*log10(px/pn);
figure(3);stem(n,w);grid
axis([0 50 min(w) max(w)])xlabel('n');ylabel('w(n)');title('Random Noise Signal w(n)');
y=x+w;
figure(6);subplot(2,1,1);
Stem(n,y);grid
axis([0 50 min(y) max(y)])xlabel('n');ylabel('y(n)=x(n)+w(n)');
title('Sinusoidal Signal Corrupted With Random NOise')
[ryy,lag]=xcorr(y,y,'unbiased');subplot(2,1,2);stem(lag,ryy);grid
axis([0 50 -1.5 1.5])
xlabel('lag index 1');ylabel('R_y_y(1)');title('Auto Correlation R_y_y(1)')
[rxx,lag]=xcorr(x,x);figure(2);stem(lag,rxx);grid
axis([-20 20 min(rxx) max(rxx)])
xlabel('lag index 1');ylabel(R_x_x(1)');
title('Auto Correlation R_x_x(1)')
[rxw,lag]=xcorr(x,w);
figure(5);stem(lag,rxw);gridaxis([-20 20 min(rxw) max(rxw)])
xlabel('lag index 1');ylabel(R_x_w(1)');
title('Cross Correlation Between x(n) and w(n)')
[rww,lag]=xcorr(w,w);figure(4);stem(lag,rww);grid
axis([-20 20 min(rww) max(rww)])
xlabel('lag index 1');ylabel(R_w_w(1)');
title('Auto Correlation R_w_w(1)')
-
7/27/2019 Basic Simulation Lab
62/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 62
Expected Waveforms:
0 10 20 30 40 50 60 70 80 90 100-1.5
-1
-0.5
0
0.5
1
1.5
n
x(n)
sinusoidal signal x(n)
-2
0 -15 -10 -5 0 5 10 15 20
-80
-60
-40
-20
0
20
40
60
80
100
lag index 1
0 5 10 15 20 25 30 35 40 45 50
-0.8
-0.6
-0.4-0.2
0
0.2
0.4
0.6
0.8
n
w(n)
Random Noise Signal w(n)
-
7/27/2019 Basic Simulation Lab
63/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 63
RESULT:Thus the removal of noise by correlation was erformed using MATLAB.
QUESTIONS:
1. What are the applications in which the removal of noise is required( correlation)?Ans: Detection of RADAR and SONAR signals , ocean wave analysis and Geo Physics.
2. What is the procedure to remove noise signal?Ans: A signal is masked by noise can be detected either by correlation technique or by
filtering.
3.What is the signal to noise ratio?A.Signal to noise ratio is measure of signal power to noise power.
SNR=10 log10(Ps/Pn)
4.What is the auto correlation of a periodic signal?
N-1
A:Rxx(l)=1/N x(n)x(n-l)n=0
5. What is the cross correlation of a periodic signal?
N-1
A:Rxy(l)=1/N x(n)y(n-l)n=0
0 5 10 15 20 25 30 35 40 45 50-2
-1
0
1
2
n
y(n)
=x(n)+w(n) Sinusoidal Signal Corrupted With Random NOise
0 5 10 15 20 25 30 35 40 45 50
-1
0
1
lag index 1
Ryy
(1)
Auto Correlation Ryy(1)
-
7/27/2019 Basic Simulation Lab
64/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 64
EXPERIMENT-16
IMPULSE RESPONSE OF RAISED COSINE FILTER
AIM: To write a MATLAB program to plot the impulse response of raised cosine filter.
Requirements: PC with MATLAB R2008a
MATLAB Code:
clc;
clear all;t=linspace(-30,30,1000);
b=0.2;
T=1;
h1=(sin(pi*t/T))./(pi*t/T);
h2=(cos(pi*b*t/T))./(1-(2*b*t/T).^2);
h=h1.*h2;
figure(1);
plot(t,h);
Expected Waveforms:
Impulse response of raised cosine filter:
RESULT:Thus the periodic signal extraction BY correlation was performed successfully using
MATLAB.
-
7/27/2019 Basic Simulation Lab
65/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 65
QUESTIONS:
1. What is meant by raised cosine filter?Ans: A raised cosine filter is a low pass filter which is commonly used in digital
communication systems, such as digital data modems, especially for pulse shaping and toavoid inter symbol interference(ISI).
2. What is meant by ISI?Ans: The ISI is a form of distortion of a signal in which one digital symbol interferes which
subsequent symbols.
3. What are the three different frequency bands of a filter?Ans: Pass band, Transition band, Stop band.
4. What is meant by transition band?Ans: The region between fp(pass band edge frequency) and fs(stop band edge frequency).
5. What is the Ideal value of transition band?Ans: Zero
-
7/27/2019 Basic Simulation Lab
66/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 66
EXPERIMENT-17
WINERKHINTCHINE RELATIONS
AIM: To verify WinerKhintchine Relations
Requirements: PC with MATLAB R2008a
MATLAB Code:
clc; clear all; close all;
fs=100;
t=0:1/fs:10;x=sin(2*pi*15*t);
N=512;
X=fft(x,N);
f=fs*(0:N-1)/N;power=X.*conj(X)/N;
figure(1)
plot(f,power);title('power spectrum through fourier transform');
xlabel('frequency');
ylabel('power');
figure(2)
rxx=xcorr(x,x);
sxx=fft(rxx,512);plot(f,abs(sxx));
title('fourier transform of autocorrelation function');xlabel('frequency');
ylabel('abs(sxx)');
Expected Waveforms:
0 10 20 30 40 50 60 70 80 90 1000
20
40
60
80
100
120power spectrum through fourier transform
frequency
power
-
7/27/2019 Basic Simulation Lab
67/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 67
RESULTS: Thus power spectrum, auto correlation of a signal using fourier transform wereplotted.
QUESTIONS:
1. What is the use of winer-khintchine theorem?Ans: The important properties of a signal like correlation and spectral density can be analysied using
wiener-khitchine theorem.
2. What is meant by wiener-khitchine theorem?
Ans:It states that the Energy spectral density of an energy signal is the fourier transform of its auto
correlation.
3. Which of the two parameters contains the same information about a signal?Ans: Auto correlations and Energy spectral density.
0 10 20 30 40 50 60 70 80 90 1000
0.5
1
1.5
2
2.5
3
3.5x 10
4 fourier transform of autocorrelation function
frequency
abs(sxx)
-
7/27/2019 Basic Simulation Lab
68/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES
Dept.of ECE 68
EXPERIMENT-1
GENERATION OF COEFFICIENTS FOR ANALOG LOWPASS FILTER
%%generation of coefficients for analog lowpass filter%%
r=1000;c=0.000001;w1=1/(r*c);
h1=[];
w2=[];theta1=[];
forw=10:10:10000
h=(1/sqrt(1+(w/w1)^2));theta= -atan(w/w1);
theta1=[theta1,theta];
deg=rad2deg(theta1);
h1=[h1,h];w2=[w2,w];
end
subplot(2,1,1); semilogx(w2,h1,'k-'); grid on;
xlabel('angular frequency'); ylabel('gain');title('Magnitude plot for lowpass filter')
subplot(2,1,2); plot(w2,theta1,'k-'); grid on;
xlabel('frequency'); ylabel('phase angle');title('Phase plot for lowpass filter')
RESULTS: Thus the spectrum were plotted for low pass filter.
101
102
103
104
0
0.5
1
angular frequency
gain
Magnitude plot for lowpass filter
0 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000-1.5
-1
-0.5
0
frequency
phaseangle
Phase plot for lowpass filter
-
7/27/2019 Basic Simulation Lab
69/69
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIESEXPERIMENT-2
GENERATION OF COEFFICIENTS FOR ANALOG HIGHPASS FILTER
AIM: To Write a MATLAB Code for generation of analog lowpass filter.
Requirements:PC with MATLAB R2008a
MATLAB Code:
%%generation of coefficients for analog highpass filter%%r=10000;
c=0.000001;
w1=1/(r*c);h1=[];
w2=[];theta1=[];
forw=10:10:10000h=(1/sqrt(1+(w1/w)^2));
theta= atan(w1/w);
theta1=[theta1,theta];
deg=rad2deg(theta1);h1=[h1,h];
w2=[w2,w];
endsubplot(2,1,1); semilogx(w2,h1,'k-'); grid on;
xlabel('angular frequency'); ylabel('gain');title('Magnitude for highpass filter')subplot(2,1,2); plot(w2,theta1,'k-'); grid on;
xlabel('frequency'); ylabel('phase angle');
title('Phase plot for highpass filter')
101
102
103
104
0
0.5
1
angular frequency
gain
Magnitude for highpass filter
1
1.5
seangle
Phase plot for highpass filter