You are on page 1of 51

DEPT.OF EC.E., LITS.

KMM

INDEX
S.No.
1
2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17

NAME OF THE EXPERIMENT


BASIC OPERATIONS ON MATRICES
GENERATION OF STANDARD SIGNALS
BASIC OPERATIONS ON SIGNALS
i)SCALING OPERATIONS ON SIGNALS
ii)COMPUTATION ENERGY AND AVERAGE
POWER OF SIGNAL
FINDING EVEN AND ODD PARTS OF SIGNAL
CONVOLUTION OF TWO SIGNALS
PROGRAM TO COMPUTE AUTO CORRELATION AND CROSS
CORRELATION
COMPUTSTION OF LINEARITY AND TIME INVARIANCE OF LTI
SYSTEM
FREQUENCY RESPONSE OF SYSTEM
GIBB'S PHENOMENON
COMPUTATION OF FOURIER TRANSFORM OF A SIGNSAL
WAVE FORM SYNTHESIS
POLE ZERO PLOT OF Z.T.
GENERATION OF GAUSSION NOISE COMPUTATION OF ITS
MEAN, M.S. VALUE AND ITS SKEW, KURTOSIS AND PSD, PDF
VERIFICATUION OF SAMPLING THEORM
REMOVAL OF NOISE BY AUTO CORRELATION/CROSS
CORRELATION
PROGRAM TO EXTRACT PERIODIC SIGNAL MASKED BY NOISE
USING CORRELATION
VERIFICATION OF WEINER-KHINCHINE RELATION

Pg.No.
1
2
4
6
9
11
13
15
16
20
25
27
28
29
34
37
40
44
47

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 b
a=[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 matrices
a-b
%% subtraction of two matrices
c=a*b %% multiplication of two matrices
diag(a) %%diagonal elements of a
diag(b) %%daigonal elements of b
diag(c) %% diagonal elements of c

a(1,2) %% extracting of element 1,2 in a


a(2,3) %% extracting of element 2,3 in a
b(1,2) %% extracting of element 1,2 in b
b(2,3) %% extracting of element 2,3 in b
sum(a(1,:)) %%sum of 1st row elements of a
sum(a(2,:)) %% sum of 2nd row elements of a
sum(a(3,:)) %%sum of 3rd row elements of a
sum(a(4,:)) %% sum of 4th row elements of a
sum(c(1,:)) %%sum of 1st row elements of c
sum(c(2,:)) %% sum of 2nd row elements of c
sum(c(3,:)) %%sum of 3rd row elements of c
sum(c(4,:)) %% sum of 4th row elements of c
x=a' %%transpose of a

DEPT.OF EC.E., LITS.KMM

GENERATION OF STANDARD SIGNALS


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 vector
t = tmin:dt:tmax;
%unit impulse signal
x1 = 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 signal
xu = x1.*(t>=0) + x2.*(t<0);
subplot(3,3,2); plot(t,xu);
xlabel('t');ylabel('x(t)');
title('unit step signal');
% unit ramp signal
x = t; xr = x.*(t>=0);
subplot(3,3,3); plot(t,xr);
xlabel('t');ylabel('x(t)');
title('unit ramp signal');
% parabolic signal
A = 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 signal
T = 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 siganal
a = 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

DEPT.OF EC.E., LITS.KMM

% signum signal
x1 = 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 signal
x = sinc(t); subplot(3,3,8); plot(t,x);
xlabel('t');ylabel('x(t)'); title('sinc signal');
% gaussian signal
xga = exp(-a.*(t.^2));
subplot(3,3,9); plot(t,xga);
xlabel('t');ylabel('x(t)');title('gaussian signal');

OUTPUT OF EXPT:2
1

unit impulse signal

x(t) 0.5
0
-5

unit step signal

0
t

Parabolic signal

0
-5

0
t

signum signal

Sinusoidal signal

-1
-5

-1
-5

0
t

-1
-5

0
t

Triangular pulse signal


1

x(t) 0.5
0
t

sinc signal

0
-5

0
t

gaussian signal

x(t) 0.5

x(t) 0

x(t) 0

0
-5

x(t) 0
0
t

unit ramp signal

x(t)

x(t) 0.5

x(t)
0
-5

0
t

0
-5

0
t

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<3
clc; clear all; close all;
tmin = -1; tmax = 5; dt = 0.1; %setting of time vector
t = 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)');

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

DEPT.OF EC.E., LITS.KMM

signal xa(t)

signal xb(t)

2
xa(t)

2
xb(t)

2
4
t
signal xa(t)

2
xa(t)

2
xb(t)

2
t

sum of xa(t) and xb(t)


3

2
xadd(t)
1

2
4
t
signal xb(t)

2
4
t
product of xa(t) and xb(t)
3

2
xmul(t)
1

2
t

2
t

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 2
tmin = -3; tmax = 5; dt = 0.2; %setting of time vector
t = 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
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 signal
subplot(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 signal
subplot(3,3,4);plot(t,y0);
axis([tmin tmax ymin ymax]);
xlabel('t');ylabel('y(t)');
title('signal x(t)');

DEPT.OF EC.E., LITS.KMM

%plot of signal y3(t) %compressed signal


subplot(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 signal
subplot(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 signal
subplot(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 signal
subplot(3,3,9);plot(t,y6);
axis([tmin tmax ymin ymax]);
xlabel('t');ylabel('y(t+2)');title('advanced signal');

DEPT.OF EC.E., LITS.KMM

OUTPUT OF EXPT: 3A
signal x(t)

amplified signal x1(t)

4
y(t)

4
1.5y(t)
2

2
0

-2

t
signal x(t)

-2

t
signal x(t)

-2

2
t

-2

t
time expanded signal

4
y(0.5*t
2
-2

4
y(t-2)
2

2
0

t
delayed signal

4
y(t)

-2

4
y(2*t)
2

2
0

4
0.5y(t)
2

t
time compressed signal

4
y(t)

Attenuated signal x2(t)

-2

t
advanced signal
4
y(t+2
2

-2

2
t

-2

DEPT.OF EC.E., LITS.KMM

COMPUTATION ENERGY AND AVERAGE


POWER OF SIGNAL
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 signal
tmin = -3; tmax = 5; dt = 0.2; %setting of time vector
x = y(t);
x_fold = y(-t);
ymin = min([min(x),min(x_fold)]);
ymax = max([max(x),max(x_fold)]);
%plot of signal
subplot(2,1,1);plot(t,x);
axis([tmin tmax ymin ymax]);
xlabel('t');ylabel('y(t)');
title('signal x(t)');
%plot of folded signal
subplot(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 vector
t = -tmax:dt:tmax;
x = 10*sin(10*pi*t);
xsq = x.^2;
E = trapz(t,xsq); % computation of energy
P = E /(2*T0); % computation of power
disp([' Energy, E = ',num2str(E),'Joules']); %printing of energy value
disp([' power, P = ',num2str(P),'Watts']); %printing of power value

10

DEPT.OF EC.E., LITS.KMM

OUTPUT OF EXPT:3B
signal x(t)
3

2.5

folded version signal x(t)

2.5

2
y(-t)

y(t)
1.5

1.5

0.5

0.5

-2

-2

Energy E = 1000J, Power P = 50W.

11

DEPT.OF EC.E., LITS.KMM

FINDING EVEN AND ODD PARTS OF SIGNAL


EXPT NO: 4

Date:

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');
end
end
xe = (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);

12

DEPT.OF EC.E., LITS.KMM

plot(t,xo);
axis([tmin tmax ymin ymax]);
xlabel('t');ylabel('xo(t)');
title('odd part of signal x(t)');
OUTPUT OF EXPT: 4

signal x(t)

signal x(-t)

400

x1(t)

400

300

300

x2(t)

200

200

100

100

-2

0
t

-2

even part of signal x(t)


400

xe(t)

0
t

odd part of signal x(t)


400

300

300

xo(t)

200

200

100

100

-2

0
t

-2

0
t

13

DEPT.OF EC.E., LITS.KMM

CONVOLUTION OF TWO SIGNALLS


EXPT. NO: 5

Date:

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<=T
T = 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)');

14

DEPT.OF EC.E., LITS.KMM

OUTPUT OF EXPT: 5
signal x1(t)

signal x2(t)

x1(t)
0.5

x2(t)
0.5

2
t

2
t

convolved signal of x1(t)&x2(t)


150
100
x3(t)
50

100

200

300

400
t

500

600

700

800

extracted signal,x1(t)
1

x1(t)
0.5

0
0

0.5

1.5

2
2.5
t
extracted signal,x2(t)

3.5

0.5

1.5

3.5

x2(t)
0.5

0
2
t

2.5

15

DEPT.OF EC.E., LITS.KMM

PROGRAM TO COMPUTE AUTO CORRELATION AND CROSS CORRELATION


EXPT. NO: 6

Date:

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 correlation
R13 = 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 correlation
R23 = 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
signal x1(t)

signal x2(t)

0.5

x1(t)

x2(t)

-0.5

-1
-2

-1

0
t

0
-2

0
t

auto correlation of x2

cross correlation of x1,x2


200

-1

3000

100
2000

R13(t)

R23(t)

1000

-100
-200

200

400

600

800

200

400
t

600

800

16

DEPT.OF EC.E., LITS.KMM

COMPUTSTION OF LINEARITY AND TIME INVARIANCE OF LTI


SYSTEM
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;
end
h = input('type the samples of h');
N = length(x1) + length(x2)-1;
disp('the length of the out put signal will be');
disp(N);
%time invariance check
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);
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 check
x = 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 ' );
17

DEPT.OF EC.E., LITS.KMM

d = input( ' Desired delay of the signal 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) ' );
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
18

DEPT.OF EC.E., LITS.KMM

input signal x1 is
1

input signal x2 is
4

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

Delayed Input Signal xd(n) is


0

Original Output Signal y(n) is


4

13

28

27

18

Delayed Output Signal yd(n) is


0

13

28

27

18

19

DEPT.OF EC.E., LITS.KMM

Original Input Signal x(n)


3

2
x(n)
1

0.5

0.5

1.5

2
2.5
Time Index n
Delayed Input Signal xd(n)

3.5

3.5

2
xd(n)
1

1.5

2
2.5
Time Index n

Original Output Signal y(n)


30

20
y(n)
10

3
4
Time Index n
Delayed Output Signal yd(n)

30

20
yd(n)
10

3
Time Index n

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 response
num = 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 response
num = 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 realizability
num = 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) >= 1
disp (' ALL the POLES do not lie within the Unit Circle ');
disp(Oooooops..The given LTI system is NOT a stable system ');
else
disp (' 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

DEPT.OF EC.E., LITS.KMM

Pole-Zero Map of the LTI system


1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-1

-0.5

0
Real Part

0.5

Real part
6
Amplitude
4

0.1

0.2

0.3

0.4

0.5
0.6
/

Imaginary part

0.1

0.2

0.3

0.4

0.7

0.8

0.9

0.7

0.8

0.9

0
Amplitude
-1

-2

-3

0.5
/

0.6

23

DEPT.OF EC.E., LITS.KMM

Magnitude Spectrum
6
Magnitude
4

0.1

0.2

0.3

0.4

0.5
0.6
/
Phase Spectrum

0.7

0.8

0.9

0.2

0.3

0.4

0.7

0.8

0.9

0
Phase(radians)
-0.5

-1

0.1

0.5

0.6

/
Impulse Response of LTI system
1
0.9
0.8
0.7
0.6
h(n)

0.5
0.4
0.3
0.2
0.1
0

10

15

20
25
30
time index n

35

40

45

50

24

DEPT.OF EC.E., LITS.KMM

Step Response of LTI system


5
4.5
4
3.5
3
s(n)

2.5
2
1.5
1
0.5
0

10

15

20
25
30
time index n

35

40

45

50

Pole-Zero Map of the LTI system


1
0.8
0.6
0.4

Imaginary Part
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-1

-0.5

0
Real Part

0.5

25

DEPT.OF EC.E., LITS.KMM

GIBB'S PHENOMENON
EXPT. NO: 9

Date:

Aim: To write a program to illustrate Gibbs 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 : 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');
OUTPUT OF EXPT9
No of harmonics = 20
Synthesized Square Wave Using Fourier Series

1.5

0.5

sq(t) 0

-0.5

-1

-1.5

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

t
26

DEPT.OF EC.E., LITS.KMM

No of harmonics = 40
Synthesized Square Wave Using Fourier Series
1.5

0.5
sq(t)

-0.5

-1

-1.5
0

0.1

0.2

0.3

0.4

0.5
t

0.6

0.7

0.8

0.9

No of harmonics = 100
Synthesized Square Wave Using Fourier Series
1.5

0.5

sq(t)
0

-0.5

-1

-1.5

0.1

0.2

0.3

0.4

0.5
t

0.6

0.7

0.8

0.9

27

DEPT.OF EC.E., LITS.KMM

COMPUTATION OF FOURIER TRANSFORM OF A SIGNSAL


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 omega
x = 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
2
3
2.5
2
1.5
1
-2

-1.5

-1

-0.5

0
x

0.5

1.5

4/t sin(2 t)
8
6
4
2
0
-2
-6

-4

-2

t
.

28

DEPT.OF EC.E., LITS.KMM

WAVE FORM SYNTHESIS


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
(-1)floor
(2 t)
1

0.

-0.5

-1

-6

-4

-2

0
t

29

DEPT.OF EC.E., LITS.KMM

POLE ZERO PLOT OF Z.T


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)) >= 1
disp (' All poles DO NOT LIE in the Left Half of S-Plane ');
disp (' Oooooops..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;
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.t
clc; 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) >= 1
disp (' 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

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

DEPT.OF EC.E., LITS.KMM

radius of Zeros ,radzero = 0.8944,

poles are at : 0 + 0.7000i ,


radius of poles

0.8944

0 - 0.7000i

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
Pole-Zero Map
0.8

0.6

Imaginary Axis
0.4

0.2

-0.2

-0.4

-0.6

-0.8
-0.4

-0.35

-0.3

-0.25

-0.2

-0.15

-0.1

-0.05

Real Axis
Impulse Response of the LTI system

32

DEPT.OF EC.E., LITS.KMM

1
0.8
0.6
0.4
0.2
h(t)
0
-0.2
-0.4
-0.6
-0.8
-1

0.5

1.5

2.5
t

3.5

4.5

Pole-Zero Map of the LTI system in Z-Plane


1
0.8
0.6

Imaginary Part

0.4
0.2
0

-0.2
-0.4
-0.6
-0.8
-1
-1

-0.5

0.5

Real Part

33

DEPT.OF EC.E., LITS.KMM

Impulse Response
1

0.8

0.6
Amplitude
0.4

0.2

-0.2

-0.4
0

10

15

20

25

n (samples)

34

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

DEPT.OF EC.E., LITS.KMM

Scatter Plot of Gaussian Distributed Random Numbers

3
2
1
0
-1
-2
-3
-4
-4

-3

-2

-1

36

DEPT.OF EC.E., LITS.KMM

Uniform Distribution
15000

10000

5000

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

Gaussian Distribution

x 10

3
2
1
0
-5

-4

-3

-2

-1

37

DEPT.OF EC.E., LITS.KMM

VERIFICATUION OF SAMPLING THEORM


EXPT. NO: 14
Aim: To write a program to verify sampling theorem.

Date:

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 1
Fs1 = 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 off
xlabel('Time Sample (n)'), ylabel('Amplitude');
title ('Discrete Time Signal');
legend( ' Fs < 2Fmax ' );
% Case 2
Fs2 = 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 off
xlabel('Time Sample (n)'), ylabel('Amplitude');
title ('Discrete Time Signal');
legend( ' Fs = 2Fmax ' );
% Case 3
Fs3 = 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 off
xlabel('Time Sample (n)'), ylabel('Amplitude');
38

DEPT.OF EC.E., LITS.KMM

title ('Discrete Time Signal'); legend( ' Fs > 2Fmax ' );


OUTPUT OF EXPT 14
Continuous time signal: x(t) = cos(2
F t)

F2t)
1 + cos(2

2
1.5

0.5
x(t)

0
-0.5

-1

-1.5
-2
-0.4

-0.3

-0.2

-0.1

0.1

0.2

0.3

0.4

Time t (sec)

Discrete Time Signal


2
Fs < 2Fmax
1.5
1
0.5
Amplitude
0
-0.5
-1
-1.5
-2
-0.4

-0.3

-0.2

-0.1
0
0.1
Time Sample (n)

0.2

0.3

0.4

39

DEPT.OF EC.E., LITS.KMM

Discrete Time Signal


2
Fs = 2Fmax
1.5
1
0.5
Amplitude
0
-0.5
-1
-1.5
-2
-0.4

-0.3

-0.2

-0.1

0.1

0.2

0.3

0.4

Time Sample (n)

Discrete Time Signal


2
Fs > 2Fmax
1.5
1
0.5
Amplitude
0
-0.5
-1
-1.5
-2
-0.4

-0.3

-0.2

-0.1
0
0.1
Time Sample (n)

0.2

0.3

0.4

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 ); 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 l' ); ylabel( 'R_y_y(l)' );
title( 'Autocorrelation Signal R_y_y(l)' )
[ rxx , lag ] = xcorr( x , x ); figure(2);stem( lag , rxx ); grid
axis( [ -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 ); grid
axis( [ -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

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 dB30
px =1.0101 ;pn = 8.6937e-004
The calculated SNR
SNRdb = 30.6516
Sinusoidal Signal x(n)

1.5

0.5

x(n)

-0.5

-1

-1.5

10

15

20

25

30

35

40

45

50

42

DEPT.OF EC.E., LITS.KMM

Autocorrelation Signal R

xx

(l)

100
80
60
40
20
(l)
x

Rx

0
-20
-40
-60
-80
-20

-15

-10

-5

0
Lag Index l

10

15

20

43

DEPT.OF EC.E., LITS.KMM

44

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 : M
if rem(i-1,N) == 0
d(i) = 1;
45

DEPT.OF EC.E., LITS.KMM

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

OUTPUT OF EXPT 16:


Type the desired SNR 30 px = 1.0039 an = 0.0317
pn = 9.3657e-004 SNRdb = 30.3016
Periodic Signal x(n)

46

DEPT.OF EC.E., LITS.KMM

x(n)
0

-1

-2

-3

10

20

30

40
n

50

60

70

80

Noisy Signal y(n)


2
y(n)

-2
10

20

30

10

20

30

40

50
60
n
Impulse Train d(n)

70

80

90

70

80

90

1.5
1
d(n)

0.5
0

-0.5

40

50
n

60

Extracted Periodic Signal r(n)

47

DEPT.OF EC.E., LITS.KMM

r(n)

-1

-2

-3

10

20

30

40
n

50

60

70

80

3
x(n)
r(n)
2

-1

-2

-3

10

20

30

40

50

60

70

80

VERIFICATION OF WEINER-KHINCHINE RELATION


48

DEPT.OF EC.E., LITS.KMM

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

DEPT.OF EC.E., LITS.KMM

Power Spectrum through Fourier Transform


120

100

80
Power
60

40

20

10

20

30

40

50
60
Frequency f

70

80

90

100

OUTPUT OF EXPT:17
4

3.5

Fourier Transform of Autocorrelation

x 10

2.5

abs(Sxx)2

1.5

0.5

10

20

30

40

50
60
Frequency( f)

70

80

90

100

50

You might also like