Pages

Monday, December 13, 2010

MATLAB PROGRAM FOR IMPLEMENTING THE COMPARISON OF LINEAR AND CIRCULAR CONVOLUTION


clear all;
close all;
x= input ('enter the first sequence');
h= input ('enter the second sequence');
N1= length(x);
N2= length(h);
x1=x;
h1=h;
x=[x zeros(1,N2-1)];  %modified first sequence
h=[h zeros(1,N1-1)];  %modified second sequence

for k=1:N1+N2-1;
    s=0;
    for j=1:k
       p(j)=h(j);
    end
    u=eye(k);
    v=flipud(u);
    m=(p)*(v);
    for i=1:k
        s=s+x(i)*m(i);
    end;
    d(k)=s;
end
disp(d);
subplot(211);
stem(d);
xlabel('time index');
ylabel('amplitude');
title('linear convolution');
%circular convolution
N=max(N1,N2);
x1=[x1 zeros(1,N-N1)];
h1=[h1 zeros(1,N-N2)];
z=x1';
for i=1:N-1
    k=x1(N);
    for i=N-1:-1:1;
        x1(i+1)=x1(i);
    end
x1(1)=k;
z=[z x1'];
end
m=z*h1';
disp(m);
subplot(212);
stem(m);
title('circular convolution');
xlabel('time');
ylabel('amplitude'); 
 
 OUTPUT WAVEFORM
 

No comments:

Post a Comment