Professional Documents
Culture Documents
Electronics Engineering
%Experiment no 1
clc;
clear all;
close all;
fs=8000;
N=input('Enter no of DFT co efficients needed ');
n=0:19;
xn=2*cos(2*pi*1000*n/fs)+cos(2*pi*2000*n/fs+pi/6);
subplot(411);
stem(xn);
title('Sampled signal');
y1=fft(xn,N);
l=0:N-1;
subplot(423);
stem(l,abs(y1));
title('Magnitude response');
subplot(424);
stem(l,angle(y1));
title('Phase response');
w=(2*pi*l)/N;
subplot(425)
stem(w,abs(y1));
title('Magnitude response');
subplot(426);
stem(w,angle(y1));
title('Phase response');
f=(fs*l)/N;
subplot(427)
stem(f,abs(y1));
title('Magnitude response');
subplot(428);
stem(f,angle(y1));
title('Phase response');
OBSERVATION
SP 109 DSP Lab
S1 M.Tech SP 2011
Dept: of
Dept: of
5
0
-5
20
10
0
20
10
0
2
4
6
Magnitude response
20
10
5
10
15
Freq: in "n" --->
Magnitude response
20
2
4
Freq: in "w"--->
Magnitude response
2
0
-2
2
0
-2
14
16
18
Phase response
20
5
10
15
Freq: in "n"--->
Phase response
20
2
4
Freq: in "w"--->
Phase response
10
0
12
0
0
-2
8000
2000
4000
6000
8000
5
0
-5
20
10
0
20
10
0
2
4
6
Magnitude response
20
10
5
Freq: in "n" --->
Magnitude response
10
2
4
Freq: in "w"--->
Magnitude response
5
0
-5
5
0
-5
14
16
18
Phase response
20
5
Freq: in "n"--->
Phase response
10
2
4
Freq: in "w"--->
Phase response
8000
10
0
12
0
0
8000
-5
S1 M.Tech SP 2011
Dept: of
5
0
-5
40
20
0
40
20
0
2
4
6
Magnitude response
40
10
10
20
30
Freq: in "n" --->
Magnitude response
40
2
4
6
Freq: in "w"--->
Magnitude response
12
2
0
-2
2
0
-2
20
10
20
30
Freq: in "n"--->
Phase response
40
2
4
6
Freq: in "w"--->
Phase response
8000
20
0
14
16
18
Phase response
0
0
8000
-2
5
0
-5
40
20
0
40
20
0
40
2
4
6
Magnitude response
10
50
Freq: in "n" --->
Magnitude response
100
2
4
6
Freq: in "w"--->
Magnitude response
5
0
-5
5
0
-5
14
16
18
Phase response
20
50
Freq: in "n"--->
Phase response
100
2
4
6
Freq: in "w"--->
Phase response
2000
4000
6000
Freq: in "Hz"--->
8000
20
0
12
0
0
8000
S1 M.Tech SP 2011
-5
Dept: of
>>
Sampled signal
5
0
-5
40
20
0
40
20
0
2
4
6
Magnitude response
500
Freq: in "n" --->
Magnitude response
1000
40
2
4
6
Freq: in "w"--->
Magnitude response
10
5
0
-5
5
0
-5
14
16
18
Phase response
20
500
Freq: in "n"--->
Phase response
1000
2
4
6
Freq: in "w"--->
Phase response
2000
4000
6000
Freq: in "Hz"--->
8000
20
0
12
0
0
8000
-5
%Experiment no 2
clc;
clear all;
S1 M.Tech SP 2011
Dept: of
close all;
n=0:20;
num=[1];
den=[1 -.25];
h=impz(num,den,n);
subplot(211);
stem(n,h);
title('Impulse response h(n)')
x=ones(1,10);
y=conv(x,h);
n1=0:length(y)-1;
subplot(212);
stem(n1,y);
title('Output y(n)')
OBSERVATION
0.5
10
12
14
16
18
20
Output y(n)
1.5
1
0.5
0
10
15
%Experiment no 3
clc;
S1 M.Tech SP 2011
20
25
30
Dept: of
rxx(k)')
rxx(-k)');
OBSERVATION
100
50
0
10
15
100
50
0
10
15
Energy
100
50
0
y=
5
11
0.2
11
25
0.4
17
0.6
41
0.8
23
58
1.2
23
a=
58
>>
S1 M.Tech SP 2011
41
1.4
17
1.6
25
1.8
11
11
Dept: of
%Experiment No 4
clc;
clear all;
close all;
n=0:20;
num=[6.6 1.5];
den=[1 -.4];
h=impz(num,den,n);
subplot(211);
stem(n,h);
title('Impulse response h(n)');
num1=[0.5 1.5];
den1=[1 -7/5 2/5];
y1=impz(num1,den1,n);
num2=[6.1];
den2=[1 -2/5];
y2=impz(num2,den2,n);
y=y1+y2;
n1=0:length(y)-1;
subplot(212);
stem(n1,y);
title('Step response of y(n)')
OBSERVATION
8
6
4
2
0
10
12
14
16
18
20
14
16
18
20
8
6
4
2
0
10
12
%Experiment No 5
% TIME DOMINE ANALYSIS
S1 M.Tech SP 2011
Dept: of
clc;
clear all;
close all;
x=[1 5 3 2 8 6 1];
h=[1 2 1 3 1];
N=7;M=5;
x1=[zeros(1,M-1) x zeros(1,M-1)];
h1=fliplr(h);
h1=[h1 zeros(1,M+N-2)];
for i=1:M+N-1
x2=x1.*h1;
y(i)=0;
for j=1:(N+2*M-2)
y(i)=y(i)+x2(j);
end
t=[0 h1];
n=numel(h1);
h1=t(1:n);
end
disp(y);
f=0:N+M-2;
subplot(211);
stem(f,y);
title ('Linear convolution by Time domain analysis');
% DFT method
a=N+M-1;
x3=[x zeros(1,M-1)];
h3=[h zeros(1,N-1)];
X=fft(x3,a);
H=fft(h3,a);
Y=X.*H;
y=ifft(Y,a);
c=0:length(y)-1;
subplot(212);
stem(c,y)
title ('Linear convolution by DFT Method');
OBSERVATION
Linear convolution by Time domain analysis
40
30
20
10
0
10
10
40
30
20
10
0
1
>>
14
16
31
38
30
34
27
% Experiment No 6
clc;
S1 M.Tech SP 2011
Dept: of
clear all;
close all;
n=0:20;
x=(1/4).^n
h=[1 .5 .25];
N=21;M=3;
x1=[zeros(1,M-1) x zeros(1,M-1)];
h1=fliplr(h);
h1=[h1 zeros(1,M+N-2)];
for i=1:M+N-1
x2=x1.*h1;
y(i)=0;
for j=1:(N+2*M-2)
y(i)=y(i)+x2(j);
end
t=[0 h1];
n1=numel(h1);
h1=t(1:n1);
end
disp(y);
f=1:N+M-1;
stem(f,y);
OBSERVATION
Output of the system y(n)
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
10
15
%Experiment no 7
clc;
S1 M.Tech SP 2011
20
25
Dept: of
clear all;
close all;
n=0:20;
num=[1 0.5];
den=[1 -.25];
h=impz(num,den,n);
h
stem(n,h);
title('Impulse response h(n)');
OBSERVATION
Impulse response h(n)
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
10
%Experiment no 8
clc;
S1 M.Tech SP 2011
12
14
16
18
20
10
Dept: of
clear all;
close all;
n=0:20;
num=[1];
den=[1 -.25];
h=impz(num,den,n);
h
stem(n,h);
title('Impulse response h(n)');
OBSERVATION
Impulse response h(n)
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
10
12
%Experiment No 9
clc;
S1 M.Tech SP 2011
14
16
18
20
11
Dept: of
clear all;
close all;
n=0:20;
N=4;
x=sin(2*pi*n/N);
h=fliplr(x);
y=conv(x,h);
n=-20:20;
stem(n,y);
title('Auto correlation rxx(k)');
[h1,i]=find(y==max(y));
disp('Energy of Auto correlation rxx(0)')
Energy=y(i)
OBSERVATION
Energy of Auto correlation is rxx(0)
Energy =
10
>>
10
8
6
4
2
0
-2
-4
-6
-8
-10
-20
-15
-10
-5
%Experiment No 10
clc;
S1 M.Tech SP 2011
10
15
20
12
Dept: of
13
clear all;
close all;
n=0:20;
N=4;
x1=[1 3 -2 1 2 -1 4 4 2];
x2=[2 -1 4 1 -2 3];
y=conv(x1,fliplr(x2))
n=-6:7;
subplot(411);
stem(n,y);
title('Cross correlation rxy(l)');
y1=fliplr(y);
n1=-7:6;
subplot(412);
stem(n1,y1);
title('Cross correlation rxy(-l)');
k=input('Enter value for shifting ');
y3=xcorr(x1);
x3=[zeros(1,k) x1];
y2=conv(x3,fliplr(x1));
n2=-8:8;
n3=-8:8+k;
subplot(413);
stem(n2,y3);
title('Auto correlation of x(n)');
subplot(414);
stem(n3,y2);
title('Auto correlation of x(n) and x(n-k)');
OBSERVATION
Enter value for shifting 2
>>
Cross correlation rxy(l)
50
0
-50
-6
-4
-2
0
2
Cross correlation rxy(-l)
-6
-4
-2
0
Auto correlation of x(n)
50
0
-50
-8
100
0
-100
-8
-6
-4
100
-2
0
2
Auto correlation of x(n) and x(n-k)
0
-100
-8
-6
-4
-2
%Experiment No 11
clc;
S1 M.Tech SP 2011
10
Dept: of
clear all;
close all;
n=0:19;
num=[1];
den=[1 -.8];
h1=impz(num,den,n);
x=cos(0.05*pi*n);
y1=conv(x,h1);
m=0:length(y1)-1;
stem(m,y1);
title('Steady state response');
OBSERVATION
Steady state response
4
3
2
1
0
-1
-2
-3
-4
10
15
20
25
%Experiment No 12
clc;
clear all;
S1 M.Tech SP 2011
30
35
40
14
Dept: of
close all;
n=0:7;
num1=[1 .5 .5 -.5];
den1=[3 -5.85 8.55 -5.55 2.7];
h1=impz(num1,den1,n);
num2=[1.47 2.138];
den2=[1 -.95 .9025];
h2=impz(num2,den2,n);
h=h1+h2;
stem(n,h);
title('First 8 samples of Impulse response h(n)');
OBSERVATION
First 8 samples of Impulse response h(n)
-2
-4
-6
%Experiment no 13
clc;
clear all;
close all;
S1 M.Tech SP 2011
15
Dept: of
OBSERVATION
Enter an i/p seq; [1 2 3 4 5]
Enter starting point of seq; -2
>>
Input x(n)
0
-2
-1.5
-1
-0.5
0
x(n-3)
0.5
1.5
1.5
2.5
3
x(2n+3)
3.5
4.5
4
2
0
-2
-1.8
-1.6
-1.4
-1.2
-1
-0.8
x(n/2-4)
% Experiment No 14
clc;
clear all;
S1 M.Tech SP 2011
-0.6
-0.4
10
-0.2
11
12
16
Dept: of
close all;
x=[1 2 0 -2 2 3];
nx=-2;
N=0:length(x)-1;
a=N+nx;
subplot(311);
stem(a,x);
title('Input x(n)');
subplot(312);
c=a-3;
stem(-c,x);
title('x(-n+3)');
for i=0:length(x)-1
a=i+nx;
r=rem((a+2),2);
if r==0
l(i+1)=(a+2)/2;
y(i+1)=x(i+1);
end
end
subplot(313);
stem(l,y);
title('x(2n-2)');
OBSERVATION
Input x(n)
5
0
-5
-2
-1.5
-1
-0.5
0.5
1.5
2.5
3.5
4.5
1.2
1.4
1.6
1.8
x(-n+3)
5
0
-5
0.5
1.5
2.5
x(2n-2)
2
1
0
0.2
0.4
0.6
0.8
% Experiment No 15
clc;
clear all;
S1 M.Tech SP 2011
17
Dept: of
close all;
n=0:10;
x=cos(n*pi/3);
y=fft(x,512);
subplot(211);
stem(abs(y));
title('Spectrum by DFT');
w=0:pi/256:pi*2;
a=freqz(x,1,w);
subplot(212);
stem(abs(a));
title('Spectrum by DTFT');
OBSERVATION
Spectrum by DFT
6
4
2
0
50
100
150
200
250
300
200
250
300
Spectrum by DTFT
6
4
2
0
50
100
150
%Experiment No 16
%Linearity
clc;
S1 M.Tech SP 2011
18
S1 M.Tech SP 2011
Dept: of
19
Dept: of
end
end;
y=fft(y,N);
Y1
y
%Parseval's Relation
disp('Parseval s Relation');
y5=0
for n=0:N-1
y5=y5+x1(n+1).*conj(x1(n+1));
end
y5
y6=0;
for n=0:N-1
y6=y6+X1(n+1).*conj(X1(n+1));
end
Y6=y6/N
OBSERVATION
Enter first seq: [1 2 3 4]
Enter second seq: [1 1 1 1]
q =
40.0000
-4.0000 + 4.0000i
-4.0000
-4.0000 - 4.0000i
-4.0000 + 4.0000i
-4.0000
-4.0000 - 4.0000i
-2.0000 - 2.0000i
10.0000 - 0.0000i
-2.0000 + 2.0000i
-2.0000 - 2.0000i
10.0000
-2.0000 + 2.0000i
-2.0000 + 2.0000i
-2.0000
-2.0000 - 2.0000i
-2.0000 + 2.0000i
-2.0000
-2.0000 - 2.0000i
r =
40.0000
40
y =
S1 M.Tech SP 2011
20
Dept: of
Parseval s Relation
y5 =
0
y5 =
30
Y6 =
30
>>
DFT of x(n-n0)
10
5
0
-5
0.5
1.5
2.5
2.5
X(k)* e -j2pi*k*n0/N
10
5
0
-5
0.5
1.5
%Experiment No 17
clc;
clear all;
S1 M.Tech SP 2011
21
Dept: of
close all;
x=input('Enter an i/p seq: ');
N=length(x);
y=fft(x,N);
n=0:N-1;
subplot(211);
stem(n,y);
title('X(k)');
for i=0:N-1
y1(i+1)=conj(y(N-i));
end
subplot(212);
stem(n,fliplr(y1));
title('X*(N-k)');
OBSERVATION
Enter an i/p seq: [1+i 2 3 4-i -2 5-2i 1 0]
>>
X(k)
20
10
0
-10
X*(N-k)
20
10
0
-10
S1 M.Tech SP 2011
22
Dept: of
X(k)
30
20
10
0
-10
X*(N-k)
30
20
10
0
-10
%Experiment No 18
clc;
clear all;
S1 M.Tech SP 2011
23
Dept: of
close all;
x=[1 0.5 1];
h=[0.5 1];
a=length(x);
b=length(h);
m=max(a,b);
x=[x zeros(m-a)];
h=[h zeros(m-b)];
X=fft(x,m);
H=fft(h,m);
Y=X.*H;
y=ifft(Y);
n=0:length(y)-1;
stem(n,y);
title('Circular convolution in freq: domain')
OBSERVATION
Circular convolution in freq: domain
1.5
0.5
0.2
0.4
0.6
0.8
1.2
S1 M.Tech SP 2011
1.4
1.6
1.8
24