Pages

Showing posts with label CONVOLUTION. Show all posts
Showing posts with label CONVOLUTION. Show all posts

Monday, December 13, 2010

MATLAB PROGRAM FOR IMPLEMENTING CIRCULAR CONVOLUTION OF TWO SEQUENCES


function y=circular_convolution(x,h)
x= input ('enter the first sequence');
h= input ('enter the second sequence');
N1= length(x);
N2= length(h);
N=max(N1,N2);%length of sequence
x=[x zeros(1,N-N1)];  %modified first sequence
h=[h zeros(1,N-N2)];  %modified second sequence

for n=0:N-1;
    y(n+1)=0;
    for i=0:N-1
       j=mod(n-i,N);
       y(n+1)=y(n+1)+x(i+1)*h(j+1);  %shifting and adding
    end
end
%to display and plot circular convolution
n=1:N;
disp('output sequence of circular convolution');
disp(y);%to view output in command window
pause;
stem(n,y);%plotting circular convolution
grid minor;
xlabel('time index');
ylabel('amplitude');
title('circular convolution sequence of x and h');
 
 
OUTPUT WAVEFORM 
 

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