Date post: | 07-Apr-2016 |
Category: |
Documents |
Upload: | saikrishna |
View: | 232 times |
Download: | 0 times |
DEPT.OF EC.E., LITS.KMM
INDEX
S.No. NAME OF THE EXPERIMENT Pg.No.1 BASIC OPERATIONS ON MATRICES 12 GENERATION OF STANDARD SIGNALS 23 BASIC OPERATIONS ON SIGNALS
i)SCALING OPERATIONS ON SIGNALSii)COMPUTATION ENERGY AND AVERAGEPOWER OF SIGNAL
469
4 FINDING EVEN AND ODD PARTS OF SIGNAL 115 CONVOLUTION OF TWO SIGNALS 136 PROGRAM TO COMPUTE AUTO CORRELATION AND CROSS
CORRELATION15
7 COMPUTSTION OF LINEARITY AND TIME INVARIANCE OF LTI SYSTEM
16
8 FREQUENCY RESPONSE OF SYSTEM 209 GIBB'S PHENOMENON 2510 COMPUTATION OF FOURIER TRANSFORM OF A SIGNSAL 2711 WAVE FORM SYNTHESIS 2812 POLE ZERO PLOT OF Z.T. 2913 GENERATION OF GAUSSION NOISE COMPUTATION OF ITS
MEAN, M.S. VALUE AND ITS SKEW, KURTOSIS AND PSD, PDF34
14 VERIFICATUION OF SAMPLING THEORM 3715 REMOVAL OF NOISE BY AUTO CORRELATION/CROSS
CORRELATION40
16 PROGRAM TO EXTRACT PERIODIC SIGNAL MASKED BY NOISE USING CORRELATION
44
17 VERIFICATION OF WEINER-KHINCHINE RELATION 47
0
DEPT.OF EC.E., LITS.KMM
BASIC OPERATIONS ON MATRICES
EXPT. NO: 1 + Date:Aim: To write and execute a MATLAB program to perform basic operations on matrices.
Program code:clc; close all; clear all; %Defining matrices a and ba=[1 2 3 4;5 6 7 8;9 8 7 6;5 4 3 2]b=[9 8 7 6;5 4 3 2;1 2 3 4;5 6 7 8]a+b %% addition of two matricesa-b %% subtraction of two matricesc=a*b %% multiplication of two matrices diag(a) %%diagonal elements of adiag(b) %%daigonal elements of bdiag(c) %% diagonal elements of c a(1,2) %% extracting of element 1,2 in aa(2,3) %% extracting of element 2,3 in a b(1,2) %% extracting of element 1,2 in bb(2,3) %% extracting of element 2,3 in b sum(a(1,:)) %%sum of 1st row elements of asum(a(2,:)) %% sum of 2nd row elements of asum(a(3,:)) %%sum of 3rd row elements of asum(a(4,:)) %% sum of 4th row elements of a sum(c(1,:)) %%sum of 1st row elements of csum(c(2,:)) %% sum of 2nd row elements of csum(c(3,:)) %%sum of 3rd row elements of csum(c(4,:)) %% sum of 4th row elements of c x=a' %%transpose of a
GENERATION OF STANDARD SIGNALS
1
DEPT.OF EC.E., LITS.KMM
EXPT. NO: 2 Date:Aim: To simulate standard signals using MATLAB software.
Program code:clc; close all; clear all;tmin = -5; dt = 0.1; tmax = 5; %set of time vectort = tmin:dt:tmax;%unit impulse signalx1 = 1; x2 = 0; ximp = x1.*(t==0) + x2.*(t~=0);subplot(3,3,1); plot(t,ximp);xlabel('t');ylabel('x(t)');title('unit impulse signal');% unit step signalxu = x1.*(t>=0) + x2.*(t<0);subplot(3,3,2); plot(t,xu);xlabel('t');ylabel('x(t)');title('unit step signal');% unit ramp signalx = t; xr = x.*(t>=0);subplot(3,3,3); plot(t,xr);xlabel('t');ylabel('x(t)');title('unit ramp signal');% parabolic signalA = 0.4; x1 = (A*(t.^2))/2;xp = x1.*(t>=0) + x2.*(t<0);subplot(3,3,4); plot(t,xp);xlabel('t');ylabel('x(t)');title('parabolic signal');% sinusiodial signalT = 2; F = 1/T; xs = sin(2*pi*F*t);subplot(3,3,5); plot(t,xs);xlabel('t');ylabel('x(t)');title('sinusoidal signal');% triangular pulse siganala = 2; x1 = 1 - abs(t)/a;xt = x1.*(abs(t)<=a) + x2.*(abs(t)>a);subplot(3,3,6); plot(t,xt);xlabel('t');ylabel('x(t)'); title('triangular pulse signal');
2
-5 0 50
0.5
1
t
x(t)
unit impulse signal
-5 0 50
0.5
1
t
x(t)
unit step signal
-5 0 50
5
t
x(t)
unit ramp signal
-5 0 50
5
t
x(t)
Parabolic signal
-5 0 5-1
0
1
t
x(t)
Sinusoidal signal
-5 0 50
0.5
1
t
x(t)
Triangular pulse signal
-5 0 5-1
0
1
t
x(t)
signum signal
-5 0 5-1
0
1
t
x(t)
sinc signal
-5 0 50
0.5
1
t
x(t)
gaussian signal
DEPT.OF EC.E., LITS.KMM
% signum signalx1 = 1; x3 = -1;xsg = x1.*(t>0) + x2.*(t==0) + x3.*(t<0);subplot(3,3,7); plot(t,xsg);xlabel('t');ylabel('x(t)'); title('signum signal');% sinc signalx = sinc(t); subplot(3,3,8); plot(t,x);xlabel('t');ylabel('x(t)'); title('sinc signal');% gaussian signalxga = exp(-a.*(t.^2));subplot(3,3,9); plot(t,xga);xlabel('t');ylabel('x(t)');title('gaussian signal');
OUTPUT OF EXPT:2
3
DEPT.OF EC.E., LITS.KMM
BASIC OPERATIONS ON SIGNALS
EXPT. NO: 3 Date:
Aim: To write and execute a MATLAB program to perform basic operations on signals.Program code:%matlab program to perform operations on signals such as %Addition, Multiplication, Scaling, Shifting, Folding, %computation of energy and average power% Program to perform addition and multiplication of the following two% signals 1) xa(t)=1; 0<t<1 xb(t) = t; 0<t<1% =2; 1<t<2 = 1; 1<t<2 % =1; 2<t<3 = 3-t; 2<t<3clc; clear all; close all;tmin = -1; tmax = 5; dt = 0.1; %setting of time vectort = tmin:dt:tmax;x1=1; x2=2; x3=3-t;xa = x1.*(t>0&t<1) + x2.*(t>=1&t<=2) + x1.*(t>2&t<3);xb = t.*(t>0&t<1) + x1.*(t>=1&t<=2) +x3.*(t>2&t<3);xadd = xa + xb; xmul = xa .* xb;xmin = min([min(xa), min(xb), min(xadd), min(xmul)]);xmax = max([max(xa), max(xb), max(xadd), max(xmul)]);%plot of signal xa(t)subplot(2,3,1); plot(t,xa);axis([tmin tmax xmin xmax]);xlabel('t'); ylabel('xa(t)');title('signal xa(t)');%plot of signal xb(t)subplot(2,3,2); plot(t,xb);axis([tmin tmax xmin xmax]);xlabel('t'); ylabel('xb(t)');title('signal xb(t)');%plot of signal xa(t)+xb(t)subplot(2,3,3); plot(t,xadd);axis([tmin tmax xmin xmax]);xlabel('t'); ylabel('xadd(t)');title('sum of xa(t) and xb(t)');
4
0 2 40
1
2
3
t
xa(t)
signal xa(t)
0 2 40
1
2
3
t
xb(t)
signal xb(t)
0 2 40
1
2
3
t
xad
d(t)
sum of xa(t) and xb(t)
0 2 40
1
2
3
t
xa(t)
signal xa(t)
0 2 40
1
2
3
t
xb(t)
signal xb(t)
0 2 40
1
2
3
t
xmul
(t)
product of xa(t) and xb(t)
DEPT.OF EC.E., LITS.KMM
%plot of signal xa(t)subplot(2,3,4); plot(t,xa);axis([tmin tmax xmin xmax]);xlabel('t'); ylabel('xa(t)');title('signal xa(t)');%plot of signal xb(t)subplot(2,3,5); plot(t,xb);axis([tmin tmax xmin xmax]);xlabel('t'); ylabel('xb(t)');title('signal xb(t)');%plot of signal xa(t)Xxb(t)subplot(2,3,6); plot(t,xmul);axis([tmin tmax xmin xmax]);xlabel('t'); ylabel('xmul(t)');title('product of xa(t) and xb(t)');OUTPUT OF EXPT: 3
5
DEPT.OF EC.E., LITS.KMM
SCALING OPERATIONS ON SIGNALS
EXPT.NO: 3A Date:
Aim: To write and execute a MATLAB program to performs scaling operations on signals.
Program code:% matlab program to perform amplitude scaling, time scaling and time % shifting on the signal x(t) = 1.0+t; for t= 0 to 2tmin = -3; tmax = 5; dt = 0.2; %setting of time vectort = tmin:dt:tmax;y0 = y(t);y1 = 1.5*y(t);y2 = 0.5*y(t);y3 = y(2*t);y4 = y(0.5*t);y5 = y(t-2);y6 = y(t+2); %compute the min and max value for y -axis ymin = min([min(y0), min(y1), min(y2), min(y3), min(y4), min(y5), min(y6)]);ymax = max([max(y0), max(y1), max(y2), max(y3), max(y4), max(y5), max(y6)]);%plot of signal y0(t) %original signal subplot(3,3,1);plot(t,y0);axis([tmin tmax ymin ymax]);xlabel('t');ylabel('y(t)');title('signal x(t)');%plot of signal y1(t) %amplified signal
6
DEPT.OF EC.E., LITS.KMM
subplot(3,3,2);plot(t,y1);axis([tmin tmax ymin ymax]);xlabel('t');ylabel('1.5y(t)');title('amplified signal x1(t)');%plot of signal y2(t) %attenuated signalsubplot(3,3,3);plot(t,y2);axis([tmin tmax ymin ymax]);xlabel('t');ylabel('0.5y(t)');title('attenuted signal x2(t)');%plot of signal y0(t) %original signalsubplot(3,3,4);plot(t,y0);axis([tmin tmax ymin ymax]);xlabel('t');ylabel('y(t)');title('signal x(t)');
%plot of signal y3(t) %compressed signalsubplot(3,3,5);plot(t,y3);axis([tmin tmax ymin ymax]);xlabel('t');ylabel('y(2*t)');title('time compressed signal');subplot(3,3,6);plot(t,y4);axis([tmin tmax ymin ymax]);xlabel('t');ylabel('y(0.5*t)');title('time expanded signal');%plot of signal y0(t) %original signalsubplot(3,3,7);plot(t,y0);axis([tmin tmax ymin ymax]);xlabel('t');ylabel('y(t)'); title('signal x(t)');%plot of signal y5(t) % delayed signalsubplot(3,3,8);plot(t,y5);axis([tmin tmax ymin ymax]);xlabel('t');ylabel('y(t-2)');title('delayed signal');%plot of signal y6(t) %sdvanced signalsubplot(3,3,9);plot(t,y6);axis([tmin tmax ymin ymax]);xlabel('t');ylabel('y(t+2)');title('advanced signal');
7
DEPT.OF EC.E., LITS.KMM
OUTPUT OF EXPT: 3A
8
-2 0 2 40
2
4
t
y(t)
signal x(t)
-2 0 2 40
2
4
t
1.5y
(t)
amplified signal x1(t)
-2 0 2 40
2
4
t
0.5y
(t)
Attenuated signal x2(t)
-2 0 2 40
2
4
t
y(t)
signal x(t)
-2 0 2 40
2
4
t
y(2*
t)
time compressed signal
-2 0 2 40
2
4
t
y(0.
5*t)
time expanded signal
-2 0 2 40
2
4
t
y(t)
signal x(t)
-2 0 2 40
2
4
t
y(t-
2)
delayed signal
-2 0 2 40
2
4
t
y(t+
2)
advanced signal
DEPT.OF EC.E., LITS.KMM
COMPUTATION ENERGY AND AVERAGEPOWER OF SIGNAL
9
DEPT.OF EC.E., LITS.KMM
EXPT NO:3B Date:
Aim: To write and execute a MATLAB program to compute energy and average power of signal.
Program code:%matlab program to find folded signal and to compute power and energy of a signal%folding of a signaltmin = -3; tmax = 5; dt = 0.2; %setting of time vectorx = y(t);x_fold = y(-t);ymin = min([min(x),min(x_fold)]);ymax = max([max(x),max(x_fold)]);
%plot of signalsubplot(2,1,1);plot(t,x); axis([tmin tmax ymin ymax]);xlabel('t');ylabel('y(t)'); title('signal x(t)');
%plot of folded signalsubplot(2,1,2);plot(t,x_fold);xlabel('t');ylabel('y(-t)');axis([tmin tmax ymin ymax]);title('folded version signal x(t)');
%program to compute the energy and average power of the signal%x(t)=10sin(10*pi*t)tmax = 10; dt = .01; T0 = 10; %setting of time vectort = -tmax:dt:tmax;x = 10*sin(10*pi*t); xsq = x.^2; E = trapz(t,xsq); % computation of energyP = E /(2*T0); % computation of powerdisp([' Energy, E = ',num2str(E),'Joules']); %printing of energy valuedisp([' power, P = ',num2str(P),'Watts']); %printing of power value
10
-2 0 2 40
0.5
1
1.5
2
2.5
3
t
y(t)
signal x(t)
-2 0 2 40
0.5
1
1.5
2
2.5
3
t
y(-t)
folded version signal x(t)
DEPT.OF EC.E., LITS.KMM
OUTPUT OF EXPT:3B
Energy E = 1000J, Power P = 50W.
FINDING EVEN AND ODD PARTS OF SIGNAL
EXPT NO: 4 Date:
11
DEPT.OF EC.E., LITS.KMM
Aim: To write and execute a MATLAB program to find even &odd parts of signal.Program code: tmin = -3; tmax = 3; dt = 0.1; t = tmin:dt:tmax; x1 = exp(2*t); x2 = exp(-2*t);if (x2==x1) disp('The given signal is even signal');else if (x2 ==(-x1)) disp('The given signal is an odd signal'); else disp('The given signal is neighter odd nor even signa'); endendxe = (x1+x2)/2;xo = (x1+x2)/2; ymin = min([min(x1), min(x2), min(xe), min(xo)]);ymax = max([max(x1), max(x2), max(xe), max(xo)]);subplot(2,2,1);plot(t,x1); axis([tmin tmax ymin ymax]);xlabel('t');ylabel('x1(t)'); title('signal x(t)'); subplot(2,2,2);plot(t,x2);axis([tmin tmax ymin ymax]); xlabel('t');ylabel('x2(t)'); title('signal x(-t)');subplot(2,2,3);plot(t,xe); axis([tmin tmax ymin ymax]); xlabel('t');ylabel('xe(t)');title('even part of signal x(t)'); subplot(2,2,4);
plot(t,xo);axis([tmin tmax ymin ymax]); xlabel('t');ylabel('xo(t)');
12
DEPT.OF EC.E., LITS.KMM
title('odd part of signal x(t)');
OUTPUT OF EXPT: 4
CONVOLUTION OF TWO SIGNALLS
EXPT. NO: 5 Date:
13
DEPT.OF EC.E., LITS.KMM
Aim: To write and execute a MATLAB program for computation of convolution of two signals.Program code:%x1(t)=exp(-0.7t); 0<=t<=T and x2(t)=1; 0<=t<=TT = 2;tmin = 0; tmax = 2*T; dt = 0.01;t = tmin:dt:tmax;x1 = exp(-0.7*t).*(t>=0 & t<T);x2 = 1.*(t>=0 & t<T); x3 = conv(x1,x2) n3 = length(x3);t1 = 0:1:n3-1;subplot(2,2,1);plot(t,x1);xlabel('t');ylabel('x1(t)');title('signal x1(t)');subplot(2,2,2);plot(t,x2);xlabel('t');ylabel('x2(t)');title('signal x2(t)');subplot(2,2,3:4);plot(t1,x3);xlabel('t');ylabel('x3(t)');title('convolved signal of x1(t)&x2(t)');
%deconvolution to get original x1d = deconv(x3,x2);x2d = deconv(x3,x1);ymin = min([min(x1d), min(x2d)]);ymax = max([max(x1d), max(x2d)]);figure;subplot(2,1,1);plot(t,x1d);axis([tmin tmax ymin ymax]);xlabel('t');ylabel('x1(t)');title('extracted signal,x1(t)');subplot(2,1,2);plot(t,x2d);axis([tmin tmax ymin ymax]);xlabel('t');ylabel('x2(t)');title('extracted signal,x2(t)');
OUTPUT OF EXPT: 5
14
0 1 2 3 40
0.5
1
t
x1(t)
signal x1(t)
0 1 2 3 40
0.5
1
t
x2(t)
signal x2(t)
0 100 200 300 400 500 600 700 8000
50
100
150
t
x3(t)
convolved signal of x1(t)&x2(t)
0 0.5 1 1.5 2 2.5 3 3.5 40
0.5
1
t
x1(t)
extracted signal,x1(t)
0 0.5 1 1.5 2 2.5 3 3.5 40
0.5
1
t
x2(t)
extracted signal,x2(t)
DEPT.OF EC.E., LITS.KMM
PROGRAM TO COMPUTE AUTO CORRELATION AND CROSS CORRELATION
EXPT. NO: 6 Date:
15
-2 -1 0 1 2-1
-0.5
0
0.5
1
t
x1(t
)
signal x1(t)
-2 -1 0 1 20
2
4
6
8
t
x2(t
)
signal x2(t)
0 200 400 600 800-200
-100
0
100
200
t
R13
(t)
cross correlation of x1,x2
0 200 400 600 8000
1000
2000
3000
t
R23
(t)
auto correlation of x2
DEPT.OF EC.E., LITS.KMM
Aim: To write a program for computation of auto correlation and cross correlation between signals.
Program code:clc; clear all; close all;t = -2:0.01:2; x1 = sin(2*pi*t);subplot(2,2,1);plot(t,x1); xlabel('t');ylabel('x1(t)');title('signal x1(t)'); x2 = exp(t);subplot(2,2,2);plot(t,x2); xlabel('t');ylabel('x2(t)');title('signal x2(t)'); x3 = exp(-t);%computation of cross correlationR13 = conv(x1,x3); n13 = length(R13);t13 = 0:1:n13-1;subplot(2,2,3);plot(t13,R13); xlabel('t');ylabel('R13(t)');title('cross correlation of x1,x2');%computation of auto correlationR23 = conv(x2,x3); n23 = length(R23);t23 = 0:1:n23-1;subplot(2,2,4);plot(t23,R23); xlabel('t');ylabel('R23(t)');title('auto correlation of x2');OUTPUT OF EXPT:6
COMPUTSTION OF LINEARITY AND TIME INVARIANCE OF LTI SYSTEM
16
DEPT.OF EC.E., LITS.KMM
EXPT. NO:7 Date:
Aim: To write a program for computation of linearity and time invariance of LTI system.
Program code:clc; clear all; close all;x1 = input('type the samples of x1');x2 = input('type the samples of x2');if (length(x1)~=length(x2)) disp('Error: length of x1 and x2 are diffrent'); return;endh = input('type the samples of h');N = length(x1) + length(x2)-1;disp('the length of the out put signal will be');disp(N);%linearity checka1 = 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);y1s = a1*y1;y2 = conv(x2,h);y2s = a2*y2;y02 = y1s + y2s;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% time invariance checkx = input('type the samples 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 signal is ' );xd = [zeros(1,d), x];nxd = 0 : length(xd)-1;
17
DEPT.OF EC.E., LITS.KMM
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)];figuresubplot(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)];figuresubplot(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) ' ); OUTPUT OF EXPT7 type the samples of x1[1 2 3]
type the samples of x2[4 5 6]
type the samples of h[1 2 3]
the length of the out put signal will 5
the scale factor a1 is 3
the scale factor a2 is 4
input signal x1 is
1 2 3
18
DEPT.OF EC.E., LITS.KMM
input signal x2 is
4 5 6
output sequence y01 is
19 64 142 144 99
output sequence y02 is
19 64 142 144 99
y01=y02.Hence the LTI system is LINEAR
type the samples of signal x(n)[1 2 3]
Type the samples of signal h(n) [4 5 6]
Enter a POSITIVE number for delay
Desired delay of the signal is 2
Original Input Signal x(n) is
1 2 3
Delayed Input Signal xd(n) is
0 0 1 2 3
Original Output Signal y(n) is
4 13 28 27 18
Delayed Output Signal yd(n) is
0 0 4 13 28 27 18
19
0 0.5 1 1.5 2 2.5 3 3.5 40
1
2
3
Time Index n
x(n
) Original Input Signal x(n)
0 0.5 1 1.5 2 2.5 3 3.5 40
1
2
3
Time Index n
xd(n
)
Delayed Input Signal xd(n)
0 1 2 3 4 5 60
10
20
30
Time Index n
y(n
)
Original Output Signal y(n)
0 1 2 3 4 5 60
10
20
30
Time Index n
yd(n
)
Delayed Output Signal yd(n)
DEPT.OF EC.E., LITS.KMM
20
DEPT.OF EC.E., LITS.KMM
FREQUENCY RESPONSE OF SYSTEM
EXPT. NO: 8 Date:Aim: to write a program for finding frequency response of system.Program code:clc; clear all; close all; num = input ('type the numerator vector ');den = input ('type the denominator vector '); N = input ('number of frequency points ');w = 0 : pi / N : pi; H = freqz (num, den, w) ;figure; subplot( 2 , 1 , 1 ); plot( w/pi , real(H) );xlabel( ' \omega / \pi' ); ylabel(' Amplitude ' )title ( 'Real part' );subplot( 2 , 1 , 2 ); plot( w/pi , imag(H) );xlabel( ' \omega / \pi' );ylabel(' Amplitude ' ); title ( 'Imaginary part' );figure; subplot( 2 , 1 , 1 );plot( w/pi , abs(H) ); xlabel(' \omega / \pi');ylabel(' Magnitude'); title ('Magnitude Spectrum');subplot( 2 , 1 , 2 ); plot( w/pi , angle(H) );xlabel(' \omega / \pi'); ylabel(' Phase(radians) '); title ('Phase Spectrum');%unit sample responsenum = input ('type the numerator vector ');den = input ('type the denominator vector ');N=input ('type the desired length of the output sequence N ');n = 0 : N-1; imp = [ 1 zeros(1, N-1) ];h = filter ( num, den, imp );%disp('The impulse response of LTI system is'); disp(h);figure,stem(n,h); xlabel ('time index n');ylabel ('h(n)'); title ('Impulse Response of LTI system');%unit step responsenum = input ('type the numerator vector ');den = input ('type the denominator vector ');N = input('type the desired length of the output sequence N ');n = 0:1:N-1; u = ones (1, N); s = filter ( num, den, u );%disp('The step response of LTI system is'); disp(s);figure,stem(n,s); xlabel ('time index n');ylabel ('s(n)'); title ('Step Response of LTI system');%stability and physical realizabilitynum = input (' type the numerator vector '); den = input (' type the denominator vector ');[z,p,k] = tf2zp(num,den); disp ('Gain constant is '); disp(k);disp (' Zeros are at '); disp(z)disp ('radius of Zeros ') ; radzero = abs(z)disp ('Poles are at '); disp(p)
21
DEPT.OF EC.E., LITS.KMM
disp ('radius of Poles ') ; radpole = abs(p)if max(radpole) >= 1disp (' ALL the POLES do not lie within the Unit Circle ');disp(‘Oooooopsà..The given LTI system is NOT a stable system ');elsedisp (' ALL the POLES lie WITHIN the Unit Circle ');disp('The given LTI system is a REALIZABLE and STABLE system');end;figure;zplane(num,den);title('Pole-Zero Map of the LTI system');
OUTPUT OF EXPT8
pe the numerator vector [1], type the denominator vector [1 -0.8],number of frequency points 50
type the numerator vector [1], type the denominator vector [1 -0.8]
type the desired length of the output sequence N 50, type the numerator vector [1]
type the denominator vector [1 -0.8], type the desired length of the output sequence N 50
type the numerator vector [1], type the denominator vector [1 -0.8]
Gain constant is 1, Zeros are at, radius of Zeros, radzero =, Empty matrix: 0-by-1
Poles are at, 0.8000, radius of Poles, radpole = 0.8000
ALL the POLES lie WITHIN the Unit Circle
The given LTI system is a REALIZABLE and STABLE system
22
-1 -0.5 0 0.5 1
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Real Part
Pole-Zero Map of the LTI system
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
2
4
6
/
Real part
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-3
-2
-1
0
/
Imaginary part
Am
plitu
de
Am
plit
ude
DEPT.OF EC.E., LITS.KMM
23
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
2
4
6
/
Magnitude Spectrum
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1
-0.5
0
/
Phase Spectrum
0 5 10 15 20 25 30 35 40 45 500
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
time index n
h(n)
Impulse Response of LTI system
DEPT.OF EC.E., LITS.KMM
24
Magnitude
Phase(radians)
0 5 10 15 20 25 30 35 40 45 500
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
time index n
s(n)
Step Response of LTI system
-1 -0.5 0 0.5 1
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Real Part
Pole-Zero Map of the LTI system
DEPT.OF EC.E., LITS.KMM
25
Imaginary Part
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1.5
-1
-0.5
0
0.5
1
1.5
t
sq(t
)
Synthesized Square Wave Using Fourier Series
DEPT.OF EC.E., LITS.KMM
GIBB'S PHENOMENON
EXPT. NO: 9 Date:
Aim: To write a program to illustrate Gibb’s phenomenon.
Program code:clc; clear all; close all;N = input('type the total no of harmonics ');t = 0:0.001:1; y = square( 2 * pi * t ); plot( t , y , 'r' , 'linewidth' , 2 )axis( [ 0 1 -1.5 1.5 ] )hold;sq = zeros( size(t) );for n = 1 : 2 : Nsq = 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');
OUTPUT OF EXPT9No of harmonics = 20
26
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1.5
-1
-0.5
0
0.5
1
1.5
t
sq(t)
Synthesized Square Wave Using Fourier Series
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1.5
-1
-0.5
0
0.5
1
1.5
t
sq(t)
Synthesized Square Wave Using Fourier Series
DEPT.OF EC.E., LITS.KMM
No of harmonics = 40
No of harmonics = 100
COMPUTATION OF FOURIER TRANSFORM OF A SIGNSAL27
-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)
DEPT.OF EC.E., LITS.KMM
EXPT .NO: 10 Date:
Aim: To write a program for computation of Fourier transform of a signal.
Program code:clc; close all; clear all;syms t omegax = 2; expw = exp(-j*omega*t);z = int(x*expw,omega,-2,2);z = simplify(z);figure(1);subplot(2,1,1);ezplot('2',[-2 2]);subplot(2,1,2);ezplot(z);
OUTPUT OF EXPT: 10
.
WAVE FORM SYNTHESIS28
-6 -4 -2 0 2 4 6
-1
-0.5
0
0.5
1
t
(-1)floor(2 t)
DEPT.OF EC.E., LITS.KMM
EXPT .NO:11 Date:
Aim: to write a program to synthesize a waveform using Laplace transforms.
Program code:clc; clear all; close all;syms s ; T = 1; F1 = 1 - exp(-T*s/2);F2 = s * (1 + exp(-T*s/2));F = F1/F2;f=ilaplace(F);pretty(simplify(f));ezplot(f);%syms s complex;%x = 2/(s*(s+1)*(s+2));%disp('inverse lapalce transform x is ');%x = ilaplace(x);%simplify(x)
OUTPUT OF EXPT11
POLE ZERO PLOT OF Z.T29
DEPT.OF EC.E., LITS.KMM
EXPT. NO 12 Date:
Aim: To write a program to draw Z-transform pole-zero plot of a system.
Program code:clc; clear all; close all;num = input ( 'type the numerator polynomial vector ' );den = input( ' type the denominator polynomial vector ' );H = tf( num , den )[ p , z ] = pzmap( H );disp (' zeros are at '); disp( z )disp ('poles are at '); disp( p )subplot(2,1,1);pzmap( H )[ r, p, k ] = residue( num , den );disp ('PFE coefficients '); disp( r );disp ('Gain constant is '); disp( k );if max(real(p)) >= 1disp (' All poles DO NOT LIE in the Left Half of S-Plane ');disp (' Oooooopsà..The given LTI system is NOT a stable system ');Elsedisp (' ALL the POLES lie in the Left Half of S-Plane ');disp (' The given LTI system is a STABLE system ');end;subplot(2,1,2); t = 0 : 0.1 : 5; h = impulse( H , t );plot( t , h )xlabel('t'); ylabel('h(t)');title ( ' Impulse Response of the LTI system ' ); %program to plot pole zero plot of z.tclc; clear all; close all;num = input (' type the numerator vector ');den = input (' type the denominator vector ');H = filt(num , den)z = zero(H);disp (' zeros are at '); disp(z)disp ('radius of Zeros ') ; radzero = abs(z)[r,p,k] = residuez(num,den);disp ('poles are at '); disp(p)disp ('radius of poles ') ; radpole = abs(p)disp ('PFE coefficients '); disp(r);disp ('Gain constant is '); disp(k);
30
DEPT.OF EC.E., LITS.KMM
figure;zplane(num,den)title ( ' Pole-Zero Map of the LTI system in Z-Plane' );if max(radpole) >= 1disp (' ALL the POLES do not lie within the Unit Circle ');disp (' Oooooopsà..The given LTI system is NOT a stable system ');end;
OUTPUT OF EXPT: 12
type the numerator polynomial vector [1 0.8 0.8],
type the denominator polynomial vector [1 0 0.49]
Transfer function:
s^2 + 0.8 s + 0.8
-----------------
s^2 + 0.49
zeros are at -0.4000 + 0.8000i , -0.4000 - 0.8000i
poles are at : 0 + 0.7000i, 0 - 0.7000i
PFE coefficients : 0.4000 - 0.2214i , 0.4000 + 0.2214i
Gain constant is 1
type the numerator vector [1 0.8 0.8]
type the denominator vector [1 0 0.49]
Transfer function:
1 + 0.8 z^-1 + 0.8 z^-2
-----------------------
1 + 0.49 z^-2
Sampling time: unspecified
zeros are at : -0.4000 + 0.8000i , -0.4000 - 0.8000i
31
-0.4 -0.35 -0.3 -0.25 -0.2 -0.15 -0.1 -0.05 0-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
Pole-Zero Map
Real Axis
DEPT.OF EC.E., LITS.KMM
radius of Zeros ,radzero = 0.8944, 0.8944
poles are at : 0 + 0.7000i , 0 - 0.7000i
radius of poles radpole = 0.7000, 0.7000
PFE coefficients : -0.3163 - 0.5714i, -0.3163 + 0.5714i
Gain constant is : 1.6327
ALL the POLES lie WITHIN the Unit Circle
The given LTI system is a REALIZABLE and STABLE system
32
Impulse Response of the LTI system
Imaginary Axis
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
t
h(t)
-1 -0.5 0 0.5 1
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Real Part
Pole-Zero Map of the LTI system in Z-Plane
DEPT.OF EC.E., LITS.KMM
33
Imaginary Part
0 5 10 15 20 25-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
n (samples)
Impulse Response
DEPT.OF EC.E., LITS.KMM
34
Amplitude
DEPT.OF EC.E., LITS.KMM
GENERATION OF GAUSSION NOISE COMPUTATION OF ITS MEAN, M.S. VALUE AND ITS SKEW, KURTOSIS AND PSD, PDF.
EXPT. NO: 13 Date:
Aim: To write a program for simulation of Gaussian noise and to compute mean, meansqure, skew, kurtosis, psd, and pdf of Gaussian noise.
Program code:clc; clear all; close 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)
OUTPUT OF EXPT 13:
ymu = 0.0038 ,ymsq = 1.0043, ysigma = 1.0022 ,yvar =1.0043, yskew = -0.0178 ykurt = 3.0212
35
-4 -3 -2 -1 0 1 2 3 4-4
-3
-2
-1
0
1
2
3
4Scatter Plot of Gaussian Distributed Random Numbers
DEPT.OF EC.E., LITS.KMM
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1Scatter Plot of Uniform Distributed Random Numbers
36
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
5000
10000
15000
-5 -4 -3 -2 -1 0 1 2 3 4 50
1
2
3
4x 10
4 Gaussian Distribution
DEPT.OF EC.E., LITS.KMM
37
Uniform Distribution
DEPT.OF EC.E., LITS.KMM
VERIFICATION OF SAMPLING THEORM
EXPT. NO: 14 Date:Aim: To write a program to verify sampling theorem.
Program code:clc; clear all; close all;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\piF_1t) + cos(2\piF_2t)');% Case 1Fs1 = 1.4 * F2; ts1 = 1 / Fs1;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 offxlabel('Time Sample (n)'), ylabel('Amplitude');title ('Discrete Time Signal');legend( ' Fs < 2Fmax ' );% Case 2Fs2 = 2 * F2; ts2 = 1/Fs2;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 offxlabel('Time Sample (n)'), ylabel('Amplitude');title ('Discrete Time Signal');legend( ' Fs = 2Fmax ' );% Case 3Fs3 = 7 * F2; ts3 = 1/Fs3; 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 offxlabel('Time Sample (n)'), ylabel('Amplitude');
38
-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
F1t) + cos(2F2t)
-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 Sample (n)
Am
plitu
de
Discrete Time Signal
Fs < 2Fmax
DEPT.OF EC.E., LITS.KMM
title ('Discrete Time Signal'); legend( ' Fs > 2Fmax ' );
OUTPUT OF EXPT 14
39
-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 Sample (n)
Am
plitu
deDiscrete 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 Sample (n)
Am
plitu
de
Discrete Time Signal
Fs > 2Fmax
DEPT.OF EC.E., LITS.KMM
40
DEPT.OF EC.E., LITS.KMM
REMOVAL OF NOISE BY AUTO CORRELATION/CROSS CORRELATION
EXP.T NO: 15 Date:Aim: To write a program to remove noise from a signal by auto/cross correlation.Program code:clc; clear all; close 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 ); gridaxis( [ 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 ); gridaxis( [ 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 );gridaxis( [ 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 ); gridaxis( [ 0 50 -1.5 1.5 ] )xlabel( 'Lag Index l' ); ylabel( 'R_y_y(l)' );title( 'Autocorrelation Signal R_y_y(l)' )[ rxx , lag ] = xcorr( x , x ); figure(2);stem( lag , rxx ); gridaxis( [ -20 20 min(rxx) max(rxx) ] )xlabel( 'Lag Index l' ); ylabel( 'R_x_x(l)' );title( 'Autocorrelation Signal R_x_x(l)' )[ rxw , lag ] = xcorr( x , w );figure(5);stem( lag , rxw ); gridaxis( [ -20 20 min(rxw) max(rxw) ] )xlabel( 'Lag Index l' ); ylabel( 'R_x_w(l)' );title( 'Cross Correlation Between x(n) and w(n) ' )[ rww , lag ] = xcorr( w , w );figure(4); stem( lag , rww ); grid
41
0 5 10 15 20 25 30 35 40 45 50-1.5
-1
-0.5
0
0.5
1
1.5
n
x(n)
Sinusoidal Signal x(n)
DEPT.OF EC.E., LITS.KMM
axis( [ -20 20 min(rww) max(rww) ] )xlabel('Lag Index l' ); ylabel( 'R_w_w(l)' );title( 'Autocorrelation Signal R_w_w(l)' );OUTPUT OF EXPT15:type desired SNR in dB30px =1.0101 ;pn = 8.6937e-004The calculated SNR SNRdb = 30.6516
42
-20 -15 -10 -5 0 5 10 15 20
-80
-60
-40
-20
0
20
40
60
80
100
Lag Index l
R xx(l)
Autocorrelation Signal R xx(l)
DEPT.OF EC.E., LITS.KMM
0 5 10 15 20 25 30 35 40 45 50
-0.05
-0.04
-0.03
-0.02
-0.01
0
0.01
0.02
0.03
0.04
0.05
n
w(n
)
Random Noise Signal w(n)
43
DEPT.OF EC.E., LITS.KMM
-20 -15 -10 -5 0 5 10 15 20
-0.01
0
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
Lag Index l
Rw
w(l)
Autocorrelation Signal Rw w (l)
-20 -15 -10 -5 0 5 10 15 20
-0.25
-0.2
-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
Lag Index l
Rxw
(l)
Cross Correlation Between x(n) and w(n)
44
DEPT.OF EC.E., LITS.KMM
0 5 10 15 20 25 30 35 40 45 50
-1
-0.5
0
0.5
1
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 l
Ryy
(l)
Autocorrelation Signal Ryy(l)
45
DEPT.OF EC.E., LITS.KMM
PROGRAM TO EXTRACT PERIODIC SIGNAL MASKED BY NOISE USING CORRELATION
EXPT .NO 16 Date:Aim: To write a program to extract a period signal masked by noise using correlation.
Program code:clc; clear all; close all; M = 256; n = 0 : M-1;x = cos(16*pi*n/M) + sin(32*pi*n/M);snr = input( ' Type the desired SNR ' );px = var(x)w = sqrt(12) * (rand( 1 , M ) - 0.5); an = sqrt(px * (10 ^ ( (-1 * snr) / 10) ))w = w .* an; pn = var(w)SNRdb = 10 * log10(px / pn)y = x + w; N = M / 8;L = floor( M / N ); d = zeros( 1 , M );for i = 1 : Mif rem(i-1,N) == 0d(i) = 1;end;end;Cyd = ifft( fft(y,M) .* fft(d,M)) / M;r = Cyd * ( M / L ); figure(1);plot( n , x , 'b' ); axis( [ 1 80 -3 3 ] )xlabel( 'n' ); ylabel( 'x(n)' ); title( ' Periodic Signal x(n) ' )figure(2);subplot(2,1,1); plot( n , y , 'r' ); grid; axis( [ 1 96 -3 3 ] ); xlabel( 'n' ); ylabel( 'y(n)' );title( ' Noisy Signal y(n) ' )subplot(2,1,2); stem( n , d ); grid; axis( [ 1 96 -0.5 1.5 ] );xlabel( 'n' ); ylabel( 'd(n)' );title( ' Impulse Train d(n) ' )figure(3); plot( n , r , 'k' ); axis( [ 1 80 -3 3 ] )xlabel( 'n' ); ylabel( 'r(n)' );title('Extracted Periodic Signal r(n)')figure(4); plot( n , x , 'b' ); hold on; axis( [ 1 80 -3 3 ] ) plot( n , r , 'r:' ); hold off; axis( [ 1 80 -3 3 ] ) legend( 'x(n)' , 'r(n)' )
46
10 20 30 40 50 60 70 80-3
-2
-1
0
1
2
3
n
x(n)
10 20 30 40 50 60 70 80 90
-2
0
2
n
y(n)
Noisy Signal y(n)
10 20 30 40 50 60 70 80 90-0.5
0
0.5
1
1.5
n
d(n)
Impulse Train d(n)
DEPT.OF EC.E., LITS.KMM
OUTPUT OF EXPT 16:
Type the desired SNR 30 px = 1.0039 an = 0.0317
pn = 9.3657e-004 SNRdb = 30.3016
47
Periodic Signal x(n)
10 20 30 40 50 60 70 80-3
-2
-1
0
1
2
3
n
r(n)
10 20 30 40 50 60 70 80-3
-2
-1
0
1
2
3x(n)r(n)
DEPT.OF EC.E., LITS.KMM
48
Extracted Periodic Signal r(n)
DEPT.OF EC.E., LITS.KMM
VERIFICATION OF WEINER-KHINCHINE RELATION
EXPT. NO: 17 Date:
Aim: To write a program to verify weiner-khinchine relation.Program code:clc; clear all; close all;Fs = 100; t = 0:1/Fs:10;x = sin(2*pi*15*t) + sin(2*pi*30*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 f'); ylabel('Power');figure(2)rxx = xcorr( x , x );Sxx = fft(rxx,512); plot(f, abs(Sxx))title('Fourier Transform of Autocorrelation');xlabel('Frequency f'); ylabel('abs(Sxx)');
49
0 10 20 30 40 50 60 70 80 90 1000
20
40
60
80
100
120Power Spectrum through Fourier Transform
Frequency f
Pow
er
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
Frequency( f)
abs(
Sxx)
DEPT.OF EC.E., LITS.KMM
OUTPUT OF EXPT:17
50