You are on page 1of 2

‘Linear Convolution’

clear all;
close all;
x=input('Enter the first sequence');
h=input('Enter the Second Sequence');

m=length(x);
n=length(h);
X1=[x,zeros(1,n)];
H1=[h,zeros(1,m)];
Y1=zeros(1,n+m-1);
for i=1:n+m-1
Y1(i)=0;
for j=1:m
if (i-j+1>0)
Y1(i)=Y1(i)+X1(j)*H1(i-j+1);
else
end
end
end
y=conv(x,h);
subplot(2,2,1);
stem(x);
ylabel('Amplitude');
xlabel('n');
title('First Sequence');
subplot(2,2,2);
stem(h);
ylabel('Amplitude');
xlabel('n');
title('second Sequence');
subplot(2,2,3);
stem(y);
ylabel('Amplitude');
xlabel('n');
title('Output Sequence using Function');
Y1
subplot(2,2,4);
stem(Y1);
ylabel('Amplitude');
xlabel('n');
title('Output Sequence without using Function');

DFT- IDFT
close all;
clear all;
xn=input('Enter the sequence x(n) to find DFT');
ln=length(xn);
xk=zeros(1,ln);% Initialise DFT array wth zero%
ixk=zeros(1,ln);% Initialise IDFT array wth zero%
for k=0:ln-1
for n=0:ln-1
xk(k+1)=xk(k+1)+(xn(n+1)*exp((-i)*2*pi*k*n/ln));
end
end
t=0:ln-1;
subplot(2,2,1);
stem(t,xn);
title('Given Sequence');
ylabel('Amplitude');
xlabel('Time Index');

magnitude=abs(xk);
t=0:ln-1;
subplot(2,2,2);
stem(t,magnitude);
ylabel('Amplitude');
xlabel('k');
title('DFT');
for n=0:ln-1
for k=0:ln-1
ixk(n+1)=ixk(n+1)+(xk(k+1)*exp((i)*2*pi*k*n/ln));
end
end

ixk=ixk/ln;
t=0:ln-1;
subplot(2,2,4);
stem(t,ixk);
ylabel('Amplitude');
xlabel('Time Index');
title('IDFT');

MAG- PHASE
clear all;
close all;
b=input('Enter the Numerator co-efficient');
a=input('Enter the denominator co-efficient');
[h,w]=freqz(b,a);
subplot(2,1,1);
semilogx(w,20*log(abs(h)));
grid;
xlabel('Normalized Frequency');
ylabel('Magnitude Plot');
title('Magnitude in db');
subplot(2,1,2);
semilogx(w,angle(h));
grid;
xlabel('Normalized Frequency');
ylabel('Phase in radians');
title('phase response');

You might also like