Experiment-3: %linear Convolution Using Circular Convolution
Experiment-3: %linear Convolution Using Circular Convolution
EXPERIMENT-3
THEORY: Consider two finite duration sequences x(n) and h(n) of duration L samples
and M samples. The linear convolution of these two sequences produces an output
sequence of duration L+M-1 samples, whereas, the circular convolution of x(n) and h(n)
give N samples where N=max(L, M).In order to obtain the number of samples in circular
convolution equal to L+M-1, both x(n) and h(n) must be appended with appropriate
number of zero valued samples. In other word by increasing the length of the sequences
x(n) and h(n) to L+M-1 points and the circularly convolving the resulting sequences we
obtain the same result as that of linear convolution.
PROGRAM:
%linear convolution using circular convolution
x=input('first sequence to be convoluted');
h=input('second sequence to be convoluted');
N1=length(x);
N2=length(h);
n1=0:N1-1;
n2=0:N2-1;
subplot(3,1,1);
stem(n1,x);
xlabel('time');
ylabel('Amplitude');
title('first sequence x(n)');
subplot(3,1,2);
stem(n2,h);
xlabel('time');
ylabel('Amplitude');
title('seconf sequence h(n)');
if N1>N2
N3=N1-N2;
h=[h,zeros(1,N3)];
elseif N2>N1
N3=N2-N1;
x=[x,zeros(1,N3)];
end
N=N1+N2-1;
y=cconv(x,h,N);
n3=0:N-1;
subplot(3,1,3);
stem(n3,y);
xlabel('time');
ylabel('amplitude');
SHIVAM 00970211219 MET
title('circular convolution sequence');
OUTPUT
:
GRAPH:
SHIVAM 00970211219 MET
PROGRAM:
% Perform circular convolution using linear convolution
x=input('first sequence');
h=input('second sequence');
N1=length(x);
N2=length(h);
n1=0:N1-1;
subplot(3,1,1);
stem(n1,x);
xlabel('Time');
ylabel('Amplitude');
title('First sequence response x(n)');
n2=0:N2-1;
subplot(3,1,2);
stem(n2,h);
xlabel('Time');
ylabel('Amplitude');
title('Second sequence response h(n)');
N=N2+N2-1;
if N1>N2
N3=N1-N2;
h=[h,zeros(1,N3)];
elseif n2>n1
N3=N2-N1;
x=[x,zeros(1,N3)];
end
x=[x,zeros(1,N-N1)];
h=[h,zeros(1,N-N2)];
for n=1:N
y(n)=0;
for i=1:n
j=n-i+1;
if(j<=0)
j=n+j;
end
y(n)=y(n)+x(i)*h(j);
end
end
disp('circular convolution of x&h is'); disp(y);
n3=0:N-1;
subplot(3,1,3);
stem(n3,y);
xlabel('Time');
ylabel('Amplitude');
title('Circular convoluted sequence response');
SHIVAM 00970211219 MET
OUTPUT:
GRAPH: