You are on page 1of 6

1.

LINEAR CONVOLUTION
clc;
clear all;
x=input('enter the input seq ');
h=input('enter the impulse response ');
m=length(x);
n=length(h);
x1=[x,zeros(1,n)];
h1=[h,zeros(1,m)];
subplot(2,2,1);
stem(x);
grid;
title('input seq ');
subplot(2,2,2);
stem(h);
grid;
title('impulse response ');
display('convolition is .... ');
y=zeros(1,m+n-1);
for i=1:m+n-1
for j=1:m+n-1;
if j<(i+1)
y(i)=y(i)+x1(j)*h1(i-j+1);
end
end
end
subplot(2,2,[3,4]);
stem(y);
grid;
title('convolved output');
2. LINEAR CONVOLUTION USING CIRCULAR SHIFT
clear all;
clc;
x=input('enter the input sequence ');
h=input('enter the response ');
m=length(x);
n=length(h);
x=[x,zeros(1,n)];

h=[h,zeros(1,m)];
y=zeros(1,m+n-1);
% make h(n) to h(-n) using fliplr(just mirror image)
hr=fliplr(h);
for i=1:m+n-1;
hrn=circshift(hr,[0,i]);
y(i)=sum(x.*hrn);
end
subplot(2,2,1)
stem(x);
subplot(2,2,2)
stem(h);
subplot(2,2,[3,4])
stem(y);
3. CIRCULAR CONVOLUTION USING LINEAR CONVOLUTION
clear all;
clc;
x=input('enter the input sequence ');
h=input('enter the response ');
m=length(x);
n=length(h);
p=max(m,n);
q=min(m,n);
x1=[x,zeros(1,n)];
h1=[h,zeros(1,m)];
y=zeros(1,m+n-1);
hr=fliplr(h1);
for i=1:m+n-1;
hrn=circshift(hr,[0,i]);
y(i)=sum(x1.*hrn);
end
%zero padding for breaking and adding the linear convolution for
%making it circular convo.(same length needed to add)
ynew=[y,zeros(1,p-q+1)];
for j=1:p
ycir(j)=ynew(j)+ynew(p+j);
end

subplot(2,2,1)
stem(x);
subplot(2,2,2)
stem(h);
subplot(2,2,[3,4])
stem(ycir);
4. DTFT
n=-20:1:20;
k=-200:1:200;
x=(cos(pi/7)).^n;
w=(pi/100)*k;
y=x*(exp(-j*pi/100).^(n'*k));
subplot(2,1,1);
stem(n,x);
subplot(2,1,2);
plot(w/pi,y);
5. DFT
clear all;
clc;
x=[1 2 3 4];
N=4;
n=0:N-1;
k=0:N-1;
WN=exp(-j*2*pi/N);
dftm=(WN).^(n'*k);
XK=x*(dftm);
reX=real(XK);
imgX=imag(XK);
subplot(2,2,1);
stem(n,x);
subplot(2,2,2);
stem(k,reX);
subplot(2,2,3);
stem(k,imgX);

6. DFT PROPERTIES
clear all;
clc;
x=[1 2 3 4];
N=4;
n=0:N-1;
k=0:N-1;
WN=exp(-j*2*pi/N);
dftm=(WN).^(n'*k);
XK=x*(dftm);
%periodic property
reX=real(XK);
imgX=imag(XK);
newReXK=circshift(reX,[0,N]);
newImgXK=circshift(imgX,[0,N]);
subplot(2,3,1);
stem(n,x);
subplot(2,3,2);
stem(k,reX);
subplot(2,3,3);
stem(k,imgX);
subplot(2,3,4);
stem(k,newReXK);
subplot(2,3,5);
stem(k,newImgXK);
circular convolution
clear all;clc;
x1=[1 2 3 4];

x2=[2 3 4 5];
N=4;
n=0:N-1;
k=0:N-1;
WN=exp(-j*2*pi/N);
dftm=(WN).^(n'*k);
XK1=x1*(dftm);
reX1=real(XK1);
imgX1=imag(XK1);
XK2=x2*(dftm);
reX2=real(XK2);
imgX2=imag(XK2);
%circular convolution
circonvolu=cconv(x1,x2,4);
XK1XK2=(XK1).*XK2;
XKC=circonvolu*(dftm);
reXKC=real(XKC);
imgXKC=imag(XKC);
subplot(3,4,1);
stem(n,x1);
subplot(3,4,2);
stem(k,reX1);
subplot(3,4,3);
stem(k,imgX1);
subplot(3,4,4);
stem(n,x2);
subplot(3,4,5);
stem(k,reX2);
subplot(3,4,6);

stem(k,imgX2);
subplot(3,4,7);
stem(n,circonvolu);
reXK1XK2=real(XK1XK2);
imgXK1XK2=imag(XK1XK2);
subplot(3,4,8);
stem(k,reXK1XK2);
subplot(3,4,9);
stem(k,imgXK1XK2);
subplot(3,4,10);
stem(k,reXKC);
subplot(3,4,11);
stem(k,imgXKC);

You might also like