Professional Documents
Culture Documents
M.Bilal Junaid: 02/02/2010 Sec:H
M.Bilal Junaid: 02/02/2010 Sec:H
rtyuiopasdfghjklzxcvbnmqwertyui
opasdfghjklzxcvbnmqwertyuiopa
sdfghjklzxcvbnmqwertyuiopasdfg
M.Bilal Junaid
hjklzxcvbnmqwertyuiopasdfghjklz
LAB 4
xcvbnmqwertyuiopasdfghjklzxcvb
nmqwertyuiopasdfghjklzxcvbnmq
wertyuiopasdfghjklzxcvbnmqwert
yuiopasdfghjklzxcvbnmqwertyuio
pasdfghjklzxcvbnmqwertyuiopas
dfghjklzxcvbnmqwertyuiopasdfgh
jklzxcvbnmqwertyuiopasdfghjklzx
cvbnmqwertyuiopasdfghjklzxcvb
nmqwertyuiopasdfghjklzxcvbnmq
wertyuiopasdfghjklzxcvbnmqwert
yuiopasdfghjklzxcvbnmrtyuiopas
02/02/2010
Sec:H
Task 1
Code
function DSP_q1()
n=0:10;
k=-500:500;
w=pi/250*k;
x=(0.9*exp(j*pi/3)).^n;
XK=x*(exp(-j*pi/250)).^(n'*k);
MagX=abs(XK);
PhaseX=angle(XK);
subplot(1,2,1)
plot(w/pi,MagX)
title('Magnitude')
subplot(1,2,2)
plot(w/pi,PhaseX)
title('Phase')
Ouput
1.5
0.5
4
0
3
-0.5
-1
1
0
-2
-1
-1.5
-2
-1
Task 2
Code
function DSP_q2()
x1=rand(1,11);
x2=rand(1,11);
s1=1;
s2=1;
x1=s1*x1;
x2=s2*x2;
n=0:10;
k=0:10;
w=pi/5*k;
XK1=x1*(exp(-j*pi/10)).^(n'*k);
XK2=x2*(exp(-j*pi/10)).^(n'*k);
XK1=s1*XK1;
XK2=s2*XK2;
x=x1+x2;
XK3=x*(exp(-j*pi/10)).^(n'*k);
XK=XK1+XK2;
subplot(1,2,1)
plot(w/pi,XK3)
title('Fourier of added signal')
subplot(1,2,2)
plot(w/pi,XK)
title('fourier of both thn add')
error=max(abs(XK-XK3))
Output
(error =
12
10
-2
0.5
1.5
12
10
-2
7.4476e-016)
0.5
1.5
Task 3
Code
function DSP_q3()
x=rand(1,11);
k=-500:500;
w=(pi/500)*k;
orig_n=0:10;
n1=orig_n+2;
n=min(orig_n):max(n1);
y1=zeros(1,length(n));
for i=3:length(n)
y1(i)=x(i-2);
end
XK1=y1*(exp(-j*pi/500)).^(n'*k);
subplot(1,2,1)
plot(k,XK1)
title('fourier of shifted')
XK2=x*(exp(-j*pi/500)).^(orig_n'*k);
XK3=XK2.*exp(-j*w*2)
subplot(1,2,2)
plot(k,XK3)
title('fourier and than shifted')
error=max(abs(XK3-XK1))
Ouput
error = 7.9967e-015
6
fourier of shifted
-1
-1
-2
-2
-3
-500
500
-3
-500
Task 4
500
Code
function DSP_q4()
n=0:100;
k=-500:500;
x=cos((pi*n)/2);
y=exp(j*pi/4*n).*x;
XK1=x*(exp(-j*pi/500)).^(n'*k);
XK2=y*(exp(-j*pi/500)).^(n'*k);
subplot(1,2,1)
plot(k,XK1)
title('original')
subplot(1,2,2)
plot(k,XK2)
title('shifted')
Output
60
original
60
50
50
40
40
30
30
20
20
10
10
-10
-10
-20
-500
500
-20
-500
shifted
500