Documente Academic
Documente Profesional
Documente Cultură
2011
Faiz Karobari
S.L.N. Engineering College, Raichur.
2011-12
H.K.E. SOCIETYS
LABORATORY CERTIFICATE
DEPARTMENT OF
ELECTRONICS AND COMMUNICATION ENGINEERING
Date : __________
Roll No. :________
USN:___________
Examiners: 1._____________
2._________________
INDEX
A. LIST OF EXPERIMENT USING MATLAB
Page No.
11
4. Difference Equation.
15
18
22
25
29
33
37
42
45
47
51
53
56
Page | 3
DSP LAB 2011/12
Page No.
59
60
61
62
Page | 4
DSP LAB 2011/12
= x(n) * h(n)
Ex:
For x(n)={1,2,3,4} & h(n)={4,3,2,1}. Find the Linear Convolution between x(n) & h(n).
Soln:
x(n)={1,2,3,4}
h(n)={4,3,2,1}
input x(n)
output h(n)
4
amplitude of h(n)
amplitude of x(n)
4
3
2
1
0
1
2
samples of x(n)
input x1(n)
1
2
samples of h(n)
input y1(n)
1
2
samples of y1(n)
amplitude of y1(n)
amplitude of x1(n)
1
0.8
0.6
0.4
0.2
0
-1
-0.5
0
0.5
samples of x1(n)
3
2
1
0
Page | 5
DSP LAB 2011/12
input x(2)
output y2(n)
8
amplitude of y2(n)
amplitude of x(2)
2
1.5
1
0.5
0
0.5
1
1.5
samples of x(2)
input x(3)
2
0
1
2
3
samples of y2(n)
output y3(n)
2
4
samples of y3(n)
15
amplitude of y3(n)
amplitude of x(3)
1
2
samples of x(3)
10
y(n) = y1(n)+y2(n)+y3(n)+y4(n)
= {4,11,20,30,20,11,4}
input y(n)
30
amplitude of y(n)
25
20
15
10
3
samples of y(n)
Page | 6
DSP LAB 2011/12
MATLAB CODE:
clc;
xn =input('Enter the sequence x(n)');
hn =input('Enter the sequence h(n)');
yn =conv(xn,hn);
disp('yn');
disp(yn);
subplot(3,1,1);
n=0:1:(length(xn)-1);
stem(n,xn);
ylabel('amplitude of x(n)');
xlabel('samples of x(n)');
title('input x(n)');
subplot(3,1,2);
n1=0:1:(length(hn)-1);
stem(n1,hn);
ylabel('amplitude of h(n)');
xlabel('samples of h(n)');
title('input h(n)');
subplot(3,1,3);
n2=0:1:(length(yn)-1);
stem(n2,yn);
ylabel('amplitude of y(n)');
xlabel('samples of y(n)');
title('output y(n)');
Output :
Enter the sequence x(n)[1,2,3,4]
Enter the sequence h(n)[4,3,2,1]
yn
4 11 20 30 20 11
Page | 7
DSP LAB 2011/12
amplitude of y(n)
amplitude of h(n)
amplitude of x(n)
Plot :
input x(n)
4
2
0
0.5
1.5
samples of x(n)
input h(n)
2.5
0.5
1.5
samples of h(n)
output y(n)
2.5
3
samples of y(n)
4
2
0
40
20
0
Page | 8
DSP LAB 2011/12
Output :
Page | 9
DSP LAB 2011/12
amplitude of h(n)
amplitude of y(n)
amplitude of x(n)
Plot :
input x(n)
4
2
0
0.5
0.5
1.5
samples of x(n)
input y(n)
2.5
2.5
40
20
0
3
4
samples of y(n)
output impulse response h(n)
4
2
0
1.5
samples of h(n)
Page | 10
DSP LAB 2011/12
A complete characterization of an LTI system can be represented interms of its response to an unit
impulse, which is known as impulse response of the system.
OR
The impulse response is the output of a LTI system due to an impulse input applied at t=0 or n=0.
Ex1:
Find the impulse response for a given sequence x(n)={1,2,3,4} and y(n)={4,11,20,30,20,11,4}.
Soln:
x(n)=
applying ZT on both sides,
= 1 + 2 1 + 3 2 + 4 3
y(n)=
applying ZT on both sides,
= 4 + 11 1 + 20 2 + 30 3 + 20 4 + 11 5 + 4 6
w.k.t.,
Y Z
Z
HZ =X
4 + 3 1 + 2 2 + 3
1 + 2 1 + 3 2 + 4 3 4 + 11 1 + 20 2 + 30 3 + 20 4 + 11 5 + 4 6
4 + 08 1 + 12 2 + 16 3
3 1 + 8 2 + 14 3 + 20 4 + 11 5 + 4 6
3 1 + 6 2 + 9 3 + 12 4
2 2 + 5 3 + 8 4 + 11 5 + 4 6
2 2 + 4 3 + 6 4 + 8 5
3 + 2 4 + 3 5 + 4 6
3 + 2 4 + 3 5 + 4 6
= 4 + 3 1 + 2 2 + 3
On applying inverse Z T
= {4,3,2,1}.
Page | 11
DSP LAB 2011/12
Ex2:
Determine the impulse response when H[Z] is given.
1
Given = 10.5 1
= 0.5
By Power Series Method
1+
0.5
0.25
2
Z-0.5 Z
Z-0.5
0.5
0.5-
0.25
0.25
0.25
0.125
2
0.125
2
Therefore h(n)=,1,0.5,0.125,.-
Page | 12
DSP LAB 2011/12
MATLAB CODE:
clc;
a=input('Enter the coefficients of numerator');
b=input('Enter the coefficients of denominator');
n=input('Enter the length of the sequence');
hn=impz(a,b,n);
disp('hn=');
disp(hn);
n1=0:1:n-1;
stem(n1,hn);
ylabel('amplitude of h(n)');
xlabel('samples of h(n)');
title('output impulse response h(n)');
Output :
Page | 13
DSP LAB 2011/12
Plot :
0.9
0.8
amplitude of h(n)
0.7
0.6
0.5
0.4
0.3
0.2
0.1
3
samples of h(n)
Page | 14
DSP LAB 2011/12
Soln:
3
Page | 15
DSP LAB 2011/12
at n=7,
3
Page | 16
DSP LAB 2011/12
MATLAB CODE:
clc;
a=input('Enter the coefficients of x');
b=input('Enter the coefficients of y');
xn=input('Enter the sequence of x(n)');
yn=filter(a,b,xn);
disp('yn=');
disp(yn);
n=0:1:(length(yn)-1);
stem(n1,yn);
ylabel('amplitude of y(n)');
xlabel('samples of y(n)');
title('output y(n)');
Output :
Enter the coefficients of x[1,-1/3]
Enter the coefficients of y[1,-3/4,1/8]
Enter the sequence of x(n)[1,1,1,1,1,1,1,1,1,1]
yn=
1.0000 1.4167 1.6042 1.6927 1.7357 1.7568 1.7673 1.7726 1.7752 1.7765
Plot :
output y(n)
amplitude of y(n)
1.5
0.5
4
5
samples of y(n)
Page | 17
DSP LAB 2011/12
x l x(n l)
=
For n=0, 1, 2,
1
11
1 2 1
2 1 1
21
11
11
={,,,,,,}
Page | 18
DSP LAB 2011/12
VERFICATION:
Ex:
Find the auto correlation of x(n)={1,2,3,4} and verify its properties
Soln:
Given, x(n)={1,2,3,4}
x(-n)={4,3,2,1}
4
4
3
3
2
2
1
1
12
16
12
= ,,,,,,
Energy of x(n) is
3
=0
2
=1 + 22 + 32 + 42
E =30
Hence the energy E is equal to rxx (0) hence it is an energy signal
left = , ,
right = , ,
Hence rxx is symmetric about the origin (30) hence it is an even signal.
The centre index is 4.
Page | 19
DSP LAB 2011/12
MATLAB CODE:
clc;
xn =input('Enter the input signal x(n)=');
yn =fliplr(xn);
zn =conv(xn,yn);
disp('zn');
disp(zn);
subplot(3,1,1);
n=0:1:(length(xn)-1);
stem(n,xn);
ylabel('amplitude of x(n)');
xlabel('samples of x(n)');
title('input x(n)');
subplot(3,1,2);
n1=-(length(yn)-1):1:0;
stem(n1,yn);
ylabel('amplitude of y(n)');
xlabel('samples of y(n)');
title('input y(n)');
subplot(3,1,3);
n2=-(length(zn)-1)/2:1:(length(zn)-1)/2;
stem(n2,zn);
ylabel('amplitude of z(n)');
xlabel('samples of z(n)');
title('output z(n)');
Output :
Enter the input signal x(n)=[1,2,1,1]
zn
1 3 5 7 5 3 1
Page | 20
DSP LAB 2011/12
amplitude of z(n)
amplitude of y(n)
amplitude of x(n)
Plot :
input x(n)
2
1
0
0.5
1.5
samples of x(n)
input y(n)
2.5
0
-3
-2.5
-2
-1.5
samples of y(n)
output z(n)
-1
-0.5
-2
-1
0
samples of z(n)
2
1
10
5
0
-3
Page | 21
DSP LAB 2011/12
x l y(n l)
=
for n=0, 1, 2,
Ex:
Evaluate cross correlation of the fallowing sequence
x(n)={1,2,1,1} y(n)={1,1,2,1}.
Sol:
x(n)={1,2,1,1}
y(-n)={1,2,1,1}
1
11
2 1 1
2 1 1
22
11
11
={,,,,,,}
Page | 22
DSP LAB 2011/12
MATLAB CODE
clc;
xn=input('Enter the first sequence x(n)=');
yn=input('Enter the second sequence y(n)=');
yn1=fliplr(yn);
zn=conv(xn,yn1);
disp('zn=');
disp(zn);
xlen=length(xn)-1;
n1=0:1:xlen;
subplot(4,1,1);
stem(n1,xn);
xlabel('samples n');
ylabel('amplitude xn');
title('input xn');
ylen=length(yn)-1;
n2=0:1:ylen;
subplot(4,1,2);
stem(n2,yn);
xlabel('samples n');
ylabel('amplitude yn');
title('input yn');
yn1len=-(length(yn1)-1);
n3=yn1len:1:0;
subplot(4,1,3);
stem(n3,yn1);
xlabel('samples n');
ylabel('amplitude yn');
title('input yn');
zlen1=(length(zn)-1)/2;
zlen2=-(length(zn)-1)/2;
n4=zlen2:1:zlen1;
subplot(4,1,4);
stem(n4,zn);
xlabel('samples n');
ylabel('amplitude zn');
title('output zn');
Output :
Plot :
Page | 23
DSP LAB 2011/12
amplitude xn
amplitude yn
amplitude zn
amplitude yn
input xn
2
1
0
0.5
1.5
samples n
input yn
2.5
0.5
1.5
samples n
input yn
2.5
0
-3
-2.5
-2
-1.5
samples n
output zn
-1
-0.5
-2
-1
0
samples n
1
0
10
5
0
-3
Page | 24
DSP LAB 2011/12
N x2 n
x1 l x2 ((m n))N
=
Ex:
ind the circular convolution for x(n)={1,2,3,4} and h(n)={5,6,7,8}
Soln:
y(m) = x(n) N h(n)
y m =
x n y((m n))4
=
For m=0,
3
y 0 =
x n h((n))4
=0
y(0)=x(0)h(0)+x(1)h(3)+X(2)h(2)+x(3)h(3)
=1*5+2*8+3*7+4*6
=66
For m=1,
3
y 1 =
x n h((1 n))4
=0
y(1)=x(0)h(1)+x(1)h(0)+x(2)h(3)+x(3)h(2)
=1*6+2*5+3*8+4*7
=68
Page | 25
DSP LAB 2011/12
For m=2,
3
y 2 =
x n h((2 n))4
=0
y(2)=x(0)h(2)+x(1)h(1)+x(2)h(0)+x(3)h(3)
=1*7+2*6+3*5+4*8
=66
For m=3
3
y 3 =
x n h((3 n))4
=0
=x(0)h(3)+x(1)h(2)+x(2)h(1)+x(3)h(0)
=1*8+2*7+3*6+4*5
=60
Page | 26
DSP LAB 2011/12
MATLAB CODE:
x=input('Enter the sequence of x(n)');
h=input('Enter the sequence of h(n)');
N1=length(x);
N2=length(h);
N=max(N1,N2);
N3=N1-N2;
if(N3>0);
h=[h,zeros(1,N3)];
end
if(N3<0)
x=[x,zeros(1,-N3)];
end
for n=1:N
y(n)=0;
for i=1:N
j=n-i+1;
if(j<=0)
j=N+j;
end
y(n)=y(n)+x(i)*h(j);
end
end
disp('circular convolution output is');
y
N4=0:1:N-1;
subplot(2,1,2);
stem(N4,y);
ylabel('amplitude of y');
xlabel('samples of y');
title('output y');
Output :
Enter the sequence of x(n)[1,2,3,4]
Enter the sequence of h(n)[4,3,2,1]
circular convolution output is
y=
24 22 24 30
Page | 27
DSP LAB 2011/12
Plot :
output y
30
amplitude of y
25
20
15
10
5
amplitude zn
amplitude yn
1
2
samples of y
input yn
2
1
0
-3
-2.5
-2
-1.5
samples n
output zn
-1
-0.5
-2
-1
0
samples n
10
5
0
-3
Page | 28
DSP LAB 2011/12
X(k)
N DFT
N1
x n ej
2
kn
N
=0
Ex:
Find the DFT of the sequence x(n)={0,1,2,3}
Soln:
x(n)={0,1,2,3}
N1
x n ej
2
kn
N
=0
For k=0,
3
0 =
x n 1
=0
= 0+1+2+3= 6
X(0) = 6
For k=1,
3
x n ej
1 =
2
1n
4
=0
=x(0) + x(1) ej
+ x(2) ej
+ x(3) ej
3
2
=(-j)+(-2)+3j
X(1) = -2+2j
Page | 29
DSP LAB 2011/12
For k=2,
3
x n ejn
2 =
=0
X(2) = 0-1+2-3
X(2) = -2
For k=3,
3
x n ej(2 )3n
3 =
=0
=x(0) + x(1) e
3
2
+ x(2) ej
+ x(3) e
9
2
=0+j-2-3j
X(3) = -2-2j
Therefore,
X(k)={6,-2+2j,-2,-2-2j}
Page | 30
DSP LAB 2011/12
MATLAB CODE:
clc;
x=input('Enter the DFT of x(n)=....');
[N,M]=size(x);
if M~=1;
x=x';
N=M;
end
X=zeros(N,1);
n=0:N-1;
for k=0:N-1
X(k+1)=exp(-j*2*pi*k*n/N)*x;
end
disp(X);
subplot(2,1,1);
k=0:N-1;
stem(k,abs(X));
xlabel('k=......');
ylabel('magnitude of X(k)');
title('magnitude of X(k)');
subplot(2,1,2);
k=0:N-1;
stem(k,angle(X)');
xlabel('k....');
ylabel('phaseof X(k)');
title('phase of X(k)');
Output :
Enter the DFT of x(n)=....[0,1,2,3]
6.0000
-2.0000 + 2.0000i
-2.0000 - 0.0000i
-2.0000 - 2.0000i
Page | 31
DSP LAB 2011/12
Plot :
magnitude of X(k)
6
magnitude of X(k)
5
4
3
2
1
0
0.5
1.5
k=......
2.5
2.5
phase of X(k)
4
phaseof X(k)
-2
-4
0.5
1.5
k....
Page | 32
DSP LAB 2011/12
9.
X(k)
N IDFT
1
=
N1
X k ej
2
kn
N
=0
X(k)
N IDFT
1
=
4
X k e
2
kn
4
=0
For n=0,
x(0)=
=
x(0)=
1
4
1
4
[X(0)+X(1)+x(2)+X(3)]
[1+2+3+4]
For n=1,
x(1)=
=
x(1)=-
1
4
1
4
[ X(0) + X(1) ej
+ x(2) ej + X(3) ej
3
2
[1+2j-3+4(-1)]
-
Page | 33
DSP LAB 2011/12
for n=2,
x(2)=
=
4
1
[1 + 2 1 + 3 + 4(10)]
x(2)=
for n=3,
x(3)=
=
[ X(0) + X(1) ej
4
1
9
2
[1 +2(-j) + 3 + 4(-1) ]
x(3) =-
3
2
Therefore,
x(n)= {
Page | 34
DSP LAB 2011/12
MATLAB CODE:
clc;
Xk=input('Enter the DFT of X(k)=....');
[N,M]=size(Xk);
if M~=1;
Xk=Xk.';
N=M;
end
Xn=zeros(N,1);
k=0:N-1;
for n=0:N-1
Xn(n+1)=exp(j*2*pi*k*n/N)*Xk;
end
Xn=Xn/N;
disp('X(n)=....');
disp(Xn);
subplot(2,1,1);
n=0:N-1;
stem(n,abs(Xk));
xlabel('n=......');
ylabel('magnitude of Xn');
title('magnitude of Xn');
subplot(2,1,2);
n=0:N-1;
stem(n,angle(Xk)');
xlabel('n....');
ylabel('phaseof Xk');
title('phase of Xk');
Output :
Enter the DFT of X(k)=....[6,-2+2j,-2,-2-2j]
X(n)=....
0
1.0000 + 0.0000i
2.0000 - 0.0000i
3.0000 - 0.0000i
Page | 35
DSP LAB 2011/12
Plot :
magnitude of Xn
6
magnitude of Xn
5
4
3
2
1
0
0.5
1.5
n=......
2.5
2.5
phase of Xk
4
phaseof Xk
-2
-4
0.5
1.5
n....
Page | 36
DSP LAB 2011/12
1 ()
N DFT
and 2
2 ()
N DFT
Then
1
N DFT
1 () 2 ()
Ex:
Find the circular convolution of x(n)={1,2,3,4} and h(n)={4,3,2} using DFT and IDFT method.
Soln:
Given, x(n)={1,2,3,4}
h(n)={4,3,2}
x(0)=1
x(2)=3
-1
1 (1) = 2
-1
2 (0) = 6
x(1)=2
x(3)=4
X(0)=10
-1
2 (1) = 2
X(1)=-2-2j
X(2)=-2
-1
x(3)=-2-2j
h(0)
h(2)
1 (1) = 2
-1
2 (0) = 3
h(1)
h(3)
H(0)=9
2 (1) = 3
-1
H(1)=2-3j
-1
H(2)=3
-1
H(3)=2+3j
Y(k)=X(k)H(k)
10
2 + 2
=
2
2 2
9
90
2 3 2 + 10
=
3
6
2 + 3 2 10
Y(2)=-6
-1
88
1 (1) = 96
76
2 (0) = 4
Y(1)=2+10j
Y(3)=2-10j
1 (0) = 84
-1
2 (1) = 20
-1
-1
80
116
y(0)=22
y(1)=10
1
4
1
4
y(2)=20
y(3)=29
Page | 38
DSP LAB 2011/12
MATLAB CODE :
clc;
x=input('Enter the sequence x(n)=....');
h=input('Enter the sequence h(n)=....');
N1=length(x);
N2=length(h);
N3=max(N1,N2);
N=N1-N2;
X=fft(x,N3);
disp('dft of x(n) is');
X
H=fft(h,N3);
disp('dft of h(n) is');
H
z=X.*H;
disp('dft of x & h is');
z
subplot(2,1,1);
n=0:N3-1;
stem(n,abs(z));
xlabel('n.....');
ylabel('magnitude of z');
z=ifft(z,N3);
disp('IDFT of z is.....');
z
subplot(2,1,2);
n1=0:N3-1;
stem(n1,abs(z));
xlabel('n.....');
ylabel('magnitude of z');
title('IDFT of z');
Page | 39
DSP LAB 2011/12
Output :
Enter the sequence x(n)=....[1,2,3,4]
Enter the sequence h(n)=....[2,3,4,0]
dft of x(n) is
X=
10.0000
-2.0000 - 2.0000i
dft of h(n) is
H=
9.0000
-2.0000 + 3.0000i
dft of x & h is
z=
90.0000
10.0000 - 2.0000i
IDFT of z is.....
z=
26 23 16 25
Page | 40
DSP LAB 2011/12
Plot :
100
magnitude of z
80
60
40
20
0
0.5
1.5
n.....
2.5
2.5
IDFT of z
30
magnitude of z
25
20
15
10
5
0
0.5
1.5
n.....
Page | 41
DSP LAB 2011/12
Ex:
Find the linear convolution of x(n)={1,2} and h(n)={1,2,3} using DFT and IDFT method.
Soln:
Given, x(n)={1,2}
h(n)={1,2,3}
here L=2, M=3
N=L+M-1
Therefore, N=4
x(n)={1,2,0,0} and h(n)={1,2,3,0}
x(2)=0
1 (0)=1
-1
1 (1)=1
x(1)=2
x(3)=0
X(0)=3
2 (0)=2
-1
2 (1)=2
X(1)=1-2j
-1
-1
X(2)=-1
X(3)=1+2j
h(2)=3
1 (0)=4
-1
1 (1)=--2
h(1)=2
h(3)=0
H(0)=6
H(1)=-2-2j
2 (0)=2
-1
-1
2 (1)=2
H(2)=2
-1
H(3)=-2+2j
Y(k)=x(k)h(k)
10
2 + 2
Y(k)=
2
2 2
9
90
2 3 2 + 10
=
3
6
2 + 3 2 10
Y(2)=-2
-1
Y(1)=2
Y(3)=-6-6j
H(0)=6
20
H(1)=-2-2j
1/4
y(1)=4
H(2)=2
1/4
y(2)=7
-12
-1
y(0)=1
16
4j
-1
-1
H(3)=-2+2j
1/4
1/4
y(3)=6
y(n)={ 22 , 19 , 20 , 29 }
Page | 43
DSP LAB 2011/12
MATLAB CODE:
clc;
x=input('Enter the sequence x(n)=....');
h=input('Enter the sequence h(n)=....');
N1=length(x);
N2=length(h);
N=N1+N2-1;
X=fft(x,N);
H=fft(h,N);
Y=X.*H;
yn=ifft(Y,N);
disp('yn=...');
disp(yn);
n=0:N-1;
stem(n,yn);
xlabel('samples of yn');
ylabel('amplitude of yn');
title('Output yn');
Output :
Enter the sequence x(n)=....[2,3]
Enter the sequence h(n)=....[1,2,3]
yn=...
2
7 12
Plot :
Output yn
12
amplitude of yn
10
8
6
4
2
0
0.5
1.5
samples of yn
2.5
Page | 44
DSP LAB 2011/12
clc;
x=input('Enter the sequence of x(n)');
h=input('Enter the sequence of h(n)');
N1=length(x);
N2=length(h);
N=N1+N2-1;
x=[x,zeros(1,N2-1)];
h=[h,zeros(1,N1-1)];
for n=1:N
y(n)=0;
for i=1:N
j=n-i+1;
if(j<=0)
j=N+j;
end
y(n)=y(n)+x(i)*h(j);
end
end
disp('Linear convolution output is');
y
N3=0:1:length(y)-1;
subplot(2,2,2);
stem(N3,y);
ylabel('amplitude of y');
xlabel('samples of y');
title('output y');
Output :
Page | 45
DSP LAB 2011/12
Plot :
output y
70
60
amplitude of y
50
40
30
20
10
0
3
samples of y
Page | 46
DSP LAB 2011/12
Page | 47
DSP LAB 2011/12
Plot :
Figure 1
original signal
1
0.5
-0.5
-1
0.2
0.4
0.6
0.8
80
100
Figure 2
sampled signal
1
0.5
-0.5
-1
20
40
60
Page | 48
DSP LAB 2011/12
Figure 3
reconstructed signal
1
0.5
-0.5
-1
0.2
0.4
0.6
0.8
Figure 4
under sampled signal
1
0.5
-0.5
-1
10
15
20
Page | 49
DSP LAB 2011/12
Figure 5
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
Page | 50
DSP LAB 2011/12
14. MATLAB CODE FOR SAMPLING THEOREM WITHOUT USING SPLINE FUNCTION
clc;
fs=input('enter the sampling frequency=');
ts=1/fs;
n2=0:1000;
x2=cos(2*pi*0.001*n2);
subplot(2,2,1);
plot(n2,x2);
title('analog signal');
xlabel('t:');
ylabel('x(t)');
n=0:100;
x=cos(2*pi*ts*n);
subplot(2,2,2);
plot(n,x);
title('sampled signal');
xlabel('n:');
ylabel('x(n)');
n1=-100:100;
t1=ts/30;
intf=6*sinc(n1*t1/ts);
subplot(2,2,3);
plot(n1,intf);
title('sinc function');
xlabel('n1');
X1=x(1);
for i=2:length(X1);
X1=[X1,zeros(1,29),x(i)];
end
length(X1);
rect=conv(X1,intf);
subplot(2,2,4);
plot(rect);
title('reconstructed signal');
xlabel('t:');
ylabel('x(t)');
Output:
Enter the Sampling Frequency=25
Page | 51
DSP LAB 2011/12
Plot:
sampled signal
1
0.5
0.5
x(n)
x(t)
analog signal
1
-0.5
-1
-0.5
200
400
600
800
-1
1000
20
40
t:
sinc function
80
100
200
250
reconstructed signal
6
x(t)
-2
-100
60
n:
-50
0
n1
50
100
-2
50
100
150
t:
Page | 52
DSP LAB 2011/12
MATLAB CODE:
clc;
disp('FIR FILTER DESIGN USING KAISER WINDOW');
disp('');
M=input('Enter the Length of the Filter=');
beta=input('Enter the value of beta=');
wc=input('Enter the Digital CutOff Frequency=');
wn=Kaiser(M,beta);
disp('The Kaiser Window Coefficient are as follow');
disp(wn);
hn=fir1(M-1,wc,wn);
disp('The Unit Sample Response of FIR Filter is h(n)=');
disp(hn);
freqz(hn,1,512);
grid on;
xlabel('Normalized Frequency');
ylabel('Gain in dB');
title('Frequency Response of the FIR Filter');
Page | 53
DSP LAB 2011/12
OUTPUT:
The Kaiser Window Coefficient are as follow
0.7175
0.7523
0.7854
0.8166
0.8457
0.8727
0.8973
0.9195
0.9392
0.9563
0.9706
0.9822
0.9909
0.9967
0.9996
0.9996
0.9967
0.9909
0.9822
0.9706
0.9563
0.9392
0.9195
0.8973
0.8727
0.8457
0.8166
0.7854
0.7523
0.7175
Page | 54
DSP LAB 2011/12
PLOT:
Gain in dB
-20
-40
-60
-80
-100
0.1
0.2
0.1
0.2
0.3
0.4
0.5
0.6
Normalized Frequency
0.7
0.8
0.9
0.8
0.9
Phase (degrees)
-200
-400
-600
-800
-1000
0.3
0.4
0.5
0.6
0.7
Normalized Frequency ( rad/sample)
Page | 55
DSP LAB 2011/12
MATLAB CODE:
clc;
Wp=input('Enter the Pass Band Edge Frequency in rad/sec=');
Ap=input('Enter the Pass Band Ripple in dB=');
Ws=input('Enter Stop Band Edge Frequenccy in rad/sec=');
As=input('Enter Stop Band Ripple in dB=');
Fs=input('Enter the Sampling Frequency=');
[n,Wn]=buttord(Wp,Ws,Ap,As,'s');
disp('The Order of the filter is n=');
disp(n);
[num,den]=butter(n,Wn,'s');
[b,a]=bilinear(num,den,Fs);
freqz(b,a,512,Fs);
grid on;
xlabel('Frequency in Hz');
ylabel('Gain in dB');
title('Frequency Response of the Filter');
OUTPUT:
Enter the Pass Band Edge Frequency in rad/sec=1256.63
Enter the Pass Band Ripple in dB=3
Enter Stop Band Edge Frequenccy in rad/sec=2513.27
Enter Stop Band Ripple in dB=15
Enter the Sampling Frequency=2000
The Order of the filter is n=3
Page | 56
DSP LAB 2011/12
PLOT:
Gain in dB
0
-50
-100
-150
-200
100
200
300
400
500
600
Frequency in Hz
700
800
900
1000
100
200
300
400
500
600
Frequency (Hz)
700
800
900
1000
Phase (degrees)
-50
-100
-150
-200
-250
-300
Page | 57
DSP LAB 2011/12
Page | 58
DSP LAB 2011/12
Page | 59
DSP LAB 2011/12
#include<stdio.h>
#include<math.h>
void main(void)
{
short N=8;
short x[8]={1,3,2,4,1,6,4,7};
float pi=3.1412;
float sumre=0, simim=0;
float cosine=0, sine=0;
float out_real[8]={0,0}, out_imag[8]={0,0};
int i=0,k=0,n;
for(k=0;k<n;k++)
{
sumre=0;
sumim=0;
for(n=0;n<N;n++)
{
cosine=cos(2*pi*k*n/N);
sine=sin(2*pi*k*n/N)
sumre=sumre+x[n]*cosine;
sumim=sumim-x[n]*sine;
}
out_real[k]=sumre;
out_imag[k]=sumim;
printf(*%d+%7.3f%7.3f\n,k,out_real*k+,out_imag*k+);
}
}
Page | 60
DSP LAB 2011/12
Page | 61
DSP LAB 2011/12