You are on page 1of 4

Q_no1&3

x=input('enter the sequence of x[n]=');


t1=input('enter the index position of x[n]=');
l1=length(x)
h=input('enter the sequence of h[n]=');
t2=input('enter the index position of h[n]=')
l2=length(h);
y=conv(x,h);
disp(y)
a=t1:1:t1+l1-1;
subplot(3,1,1);
stem(a,x);
b=t2:1:t2+l2-1;
subplot(3,1,2);
stem(b,h);
t=t1+t2;
l=l1+l2-1;
m=t:1:l+t-1;
subplot(3,1,3);
stem(m,y);
grid on

Q_no_02
x=input('enter the sequence of x[n]=');
t1=input('enter the index position of x[n]=');
l1=length(x)
h=input('enter the sequence of h[n]=');
t2=input('enter the index position of h[n]=')
l2=length(h);
N=l1+l2-1;
y=[zeros(1,N)];
for i=1:l2 %h[n]
for
k=1:l1 %x[n]
a(i,k)=x(k)*h(i)
y(i+k-1)=y(i+k-1)+a(i,k);
end
end
a=t1:1:t1+l1-1;
subplot(3,1,1);
stem(a,x);
b=t2:1:t2+l2-1;
subplot(3,1,2);
stem(b,h);
t=t1+t2;
l=l1+l2-1;
m=t:1:l+t-1;
subplot(3,1,3);
stem(m,y);
grid on
Q_5&6
%axis boundry

n=-15:1:15;
%building sequence x[n]=2[u[n+2]-u[n-12]]
x_1=[zeros(1,13) 1 ones(1,17)];
x_2=[zeros(1,27) 1 ones(1,3)];
x=2.*[x_1-x_2];
%index of x[n]
t1=-15;
l1=length(x);
%to calulate the axis of x[n]
a=t1:1:t1+l1-1;
%building sequence h[n]=0.9^n[u[n-2]-u[n-13]]
h_1=[zeros(1,17) 1 ones(1,13)];
h_2=[zeros(1,28) 1 ones(1,2)];
h=0.9.^(n).*[h_1-h_2];
%index of h[n]
t2=-15;
%to calulate the axis of x[n]
a=t1:1:t1+l1-1;
%covolving the sequences x[n]*h[n]
y=conv(x,h);
subplot(3,1,1);
stem(a,x,'linewidth',1);
title('x[n]');
grid on
l2=length(h);
%to calulate the axis of h[n]
b=t2:1:t2+l2-1;
subplot(3,1,2);
stem(b,h,'linewidth',1);
title('h[n]');
grid on
t=t1+t2;
l=l1+l2-1;
m=t:1:l+t-1;
subplot(3,1,3);
%ploting the covolved sequence
stem(m,y,'linewidth',1);
title('y=x[n]*h[n]');
grid on

q_no_7a
n=-10:1:10;
x_1=[zeros(1,10) 1 ones(1,10)];
x_2=[zeros(1,13) 1 ones(1,7)];
l1=length(x_1);
t1=-10;
a=t1:1:t1+l1-1;
l2=length(x_2);
t2=-10;
b=t2:1:t2+l2-1;
t=t1+t2;
l=l2+l1-1;
m=t:1:t+l-1;
y=conv(x_1,x_2);
subplot(3,1,1);
stem(a,x_1);

subplot(3,1,2);
stem(b,x_2);
subplot(3,1,3);
stem(m,y);

q_no_7_b
n=-10:1:10;
x_1=[ones(1,12) 1 zeros(1,8)];
x=2.^(n).*[x_1];
h=[zeros(1,13) 1 ones(1,7)];
l1=length(x);
t1=-10;
a=t1:1:t1+l1-1;
l2=length(h);
t2=-10;
b=t2:1:t2+l2-1;
t=t1+t2;
l=l2+l1-1;
m=t:1:t+l-1;
y=conv(x,h);
subplot(3,1,1);
stem(a,x);
subplot(3,1,2);
stem(b,h);
subplot(3,1,3);
stem(m,y);

q_no_7c
n=-10:1:10;
x=[zeros(1,10) 1 ones(1,10)];
h_2=[zeros(1,12) 1 ones(1,8)];
h=(1/2).^(n).*[h_2];
l1=length(x);
t1=-10;
a=t1:1:t1+l1-1;
l2=length(h);
t2=-10;
b=t2:1:t2+l2-1;
t=t1+t2;
l=l2+l1-1;
m=t:1:t+l-1;
y=conv(x,h);
subplot(3,1,1);
stem(a,x);
subplot(3,1,2);
stem(b,h);
subplot(3,1,3);
stem(m,y);

You might also like