You are on page 1of 12

qwertyuiopasdfghjklzxcvbnmqwe

rtyuiopasdfghjklzxcvbnmqwertyui
opasdfghjklzxcvbnmqwertyuiopa
sdfghjklzxcvbnmqwertyuiopasdfg
M.Bilal Junaid
hjklzxcvbnmqwertyuiopasdfghjklz
LAB 2
xcvbnmqwertyuiopasdfghjklzxcvb
nmqwertyuiopasdfghjklzxcvbnmq
wertyuiopasdfghjklzxcvbnmqwert
yuiopasdfghjklzxcvbnmqwertyuio
pasdfghjklzxcvbnmqwertyuiopas
dfghjklzxcvbnmqwertyuiopasdfgh
jklzxcvbnmqwertyuiopasdfghjklzx
cvbnmqwertyuiopasdfghjklzxcvb
nmqwertyuiopasdfghjklzxcvbnmq
wertyuiopasdfghjklzxcvbnmqwert
yuiopasdfghjklzxcvbnmrtyuiopas
02/02/2010
Sec:H

Task 1
Code
function lab2_q1( )
n=[-5:5];
u=zeros(1,length(n));
u(find(n==0))=1;
stem(n,u)
title('Impulse function','color','r')
Ouput

Task 2
Code
function lab2_q2()
n=[-6:6];
u=zeros(1,length(n));
temp=find(n>=0);
u(temp)=1;
stem(n,u)
end
Output

Task 3
Code
function lab2_q3()
n=[-6:6];
u=zeros(1,length(n));
temp=find(n>=0);
u(temp)=n(temp);
stem(n,u)
end
Ouput

Task 4
Code
function lab2_q4()
n=-2:6
unit=zeros(1,length(n));
e=zeros(1,length(n));
temp=find(n>=1)
unit(temp)=1
e(temp) = pow2(unit(temp),n(temp))
stem(n,e,'r')
Output

Task 5
Code
function lab2_q5(a,f,n,phy)
y=a*sin(2*pi*f*n+phy)
plot(n,y)
Output
n=0:63
lab2_q5(.5,1/20,n,0)

Task 6
Code
function lab2_q6()
n=[-5:5];
u=zeros(1,length(n));
u(find(n==0))=1;
subplot(1,2,1)
stem(n,u,'r')
title('Impulse function','color','r')
ns=n+2;
subplot(1,2,2,'r')
stem(ns,u)
title('Impulse function shifted by 2','color','r')

Ouput

Task 7

Code
function lab2_q7()
n=[-6:6];
u=zeros(1,length(n));
temp=find(n>=0);
u(temp)=1;
subplot(1,2,1)
stem(n,u)
title('Unit impulse')
ns=n+2;
subplot(1,2,2)
stem(ns,u)
title('Shifted unit impulse by 2')
end

Output

Task 8

Code
function lab2_q8()
n=[-6:6];
u=zeros(1,length(n));
temp=find(n>=0);
u(temp)=n(temp);
subplot(1,2,1)
stem(n,u)
title('Unit ramp')
ns=n+2;
subplot(1,2,2)
stem(ns,u)
title('Unit ramp shifted by 2')
end

Output

Task 9

Use of loops
For Loop
n=0:20
for i=1:1:5
n(i)=2
end

While loop
b=5
While(b>2)
b=b-1;
end

PTO

Task 10

Code
Use of signal shift is shown in task 6,7 and 8.
Use of fliplr
function lab2_q9(signal,n)
subplot(1,2,1)
stem(n,signal,'r')
title('orignal signal')
subplot(1,2,2)
n=-fliplr(n)
signal=fliplr(signal)
stem(n,signal,'r')
title('flipped signal')

Output
n=0:2
signal=[5 4 3]
lab2_q9(signal,n)

You might also like