Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 8

qwertyuiopasdfghjklzxcvbnmqwe

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

Task 1
Code
function lab3_q1()
x=[1 2 3 4 5 6 7 6 5 4 3 2 1]
orig_n=-2:10;
x1=2*x
x2=-3*x;
n1=orig_n+5;
n2=orig_n-4;
n=min(min(n1),min(n2)):max(max(n1),max(n2))
y1=zeros(1,length(n))
y2=y1
y1(find((n>=min(n1)) & (n<=max(n1))==1))=x1;
y2(find((n>=min(n2)) & (n<=max(n2))==1))=x2;
y=y1+y2;
subplot(2,2,1)
stem(n1,x1)
title('2x(n-5)')
subplot(2,2,2)
stem(n2,x2)
title('- 3x(n+4)')
subplot(2,2,[3 4])
stem(n,y)
title('y=2x(n-5) - 3x(n+4)')
end

Ouput

Task 2
Code
function lab3_q2()
x=[1 2 3 4 5 6 7 6 5 4 3 2 1]
orig_n=-2:10;
n1=orig_n+2;
n2=orig_n+3;
x_flip=fliplr(x);
n=min(min(n1),min(n2)):max(max(n1),max(n2))
y1=zeros(1,length(n))
y2=y1
y3=y1
y1(find((n>=min(n1)) & (n<=max(n1))==1))=x;
y2(find((n>=min(n2)) & (n<=max(n2))==1))=x_flip;
for i=1:1:length(x)
y3(i)=x(i);
end
subplot(2,2,1)
stem(n1,x)
title('x(3-n)')
subplot(2,2,2)
stem(n,y2.*y3)
title('x(n)x(n-2)')
y=y1+y3.*y2
subplot(2,2,[3 4])
stem(n,y)
title('y=x(3-n)+x(n)x(n-2)')
end

Output

Task 3
Code
function lab3_q3()
n1=[-6:6]
n2=[0:7]
unit=zeros(1,length(n1));
temp=find(n1>=0);
unit(temp)=1;
ramp=zeros(1,length(n2));
temp=find(n2>=0);
ramp(temp)=n2(temp);
n=min(min(n1),min(n2)):max(max(n1),max(n2))
y1=zeros(1,length(n))
y2=y1
y1(find((n>=min(n1)) & (n<=max(n1))==1))=unit;
y2(find((n>=min(n2)) & (n<=max(n2))==1))=ramp;
y=y1+y2
subplot(2,2,1)
stem(n1,unit)
title('u[n]')
subplot(2,2,2)
stem(n2,ramp)
title('ramp(n)')
subplot(2,2,[3 4])
stem(n,y)
title('y=u[n]+ramp(n)')

Ouput

Task 4
Code
function lab3_q4()
n1=[-6:6]
n2=[0:7]
unit=zeros(1,length(n1));
temp=find(n1>=0);
unit(temp)=1;
ramp=zeros(1,length(n2));
temp=find(n2>=0);
ramp(temp)=n2(temp);
n=min(min(n1),min(n2)):max(max(n1),max(n2))
y1=zeros(1,length(n))
y2=y1
y1(find((n>=min(n1)) & (n<=max(n1))==1))=unit;
y2(find((n>=min(n2)) & (n<=max(n2))==1))=ramp;
y=y1-y2
subplot(2,2,1)
stem(n1,unit)
title('u[n]')
subplot(2,2,2)
stem(n2,ramp)
title('ramp(n)')
subplot(2,2,[3 4])
stem(n,y)
title('y=u[n]-ramp(n)')

Output

Task 5
Code
function lab3_q5()
n1=[-6:6]
n2=[0:7]
unit=zeros(1,length(n1));
temp=find(n1>=0);
unit(temp)=1;
ramp=zeros(1,length(n2));
temp=find(n2>=0);
ramp(temp)=n2(temp);
n=min(min(n1),min(n2)):max(max(n1),max(n2))
y1=zeros(1,length(n))
y2=y1
y1(find((n>=min(n1)) & (n<=max(n1))==1))=unit;
y2(find((n>=min(n2)) & (n<=max(n2))==1))=ramp;
y=y1.*y2
subplot(2,2,1)
stem(n1,unit)
title('u[n]')
subplot(2,2,2)
stem(n2,ramp)
title('ramp(n)')
subplot(2,2,[3 4])
stem(n,y)
title('y=u[n]*ramp(n)')

Output

Task 6

Code
function lab3_q6()
n1=[-6:6]
n2=[0:7]
unit=zeros(1,length(n1));
temp=find(n1>=0);
unit(temp)=1;
ramp=zeros(1,length(n2));
temp=find(n2>=0);
ramp(temp)=n2(temp);
n=min(min(n1),min(n2)):max(max(n1),max(n2))
y1=zeros(1,length(n))
y2=y1
y1(find((n>=min(n1)) & (n<=max(n1))==1))=unit;
y2(find((n>=min(n2)) & (n<=max(n2))==1))=ramp;
y=y1./y2
subplot(2,2,1)
stem(n1,unit)
title('u[n]')
subplot(2,2,2)
stem(n2,ramp)
title('ramp(n)')
subplot(2,2,[3 4])
stem(n,y)
title('y=u[n]/ramp(n)')

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

You might also like