Experiment-6: Objective: Write Your Own MATLAB Function "Mycirconv" To Compute Circular Convolution
Experiment-6: Objective: Write Your Own MATLAB Function "Mycirconv" To Compute Circular Convolution
Experiment-6: Objective: Write Your Own MATLAB Function "Mycirconv" To Compute Circular Convolution
Objective: Write your own MATLAB function mycirconv to compute circular convolution
of two sequences.
Theory: Two real N-periodic sequences x(n) and h(n) and their circular or periodic
convolution sequence y(n) is also an N- periodic and given by,
Circular convolution is somet hing different from ordinary linear convolution operation,
as this involves the index ((n-m))N, which stands for a modula-N operation. Basically
both type of convolution involve same six steps. But the difference between the two
types of convolution is that in circular convolution the folding and shifting (rotating)
operations are performed in a circular fashion by computing the index of one of the
sequences with modulo-N operation. Either one of the two sequences may be folded and
rotated without changing the result of circular convolution.That is,
If x (n) contain L no of samples and h (n) has M no of samples and that L > M, then
perform circular convolution between the two using N=max (L,M), by adding (L-M) no of
zero samples to the sequence h (n), so that both sequences are periodic with number.
Two sequences x (n) and h (n), the circular convolution of these two sequences
In lab Exercise
function [y]=mycircconv(g,h)
N1=length(g);
N2=length(h);
N=max(N1,N2);
N3=N1-N2;
if(N3>0)
h=[h,zeros(1,N3)];
else
g=[g,zeros(1,-N3)];
end
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)+(g(i)*h(j))];
end
end
subplot(2,1,1);
stem(y);
xlabel('N->');
ylabel('Amplititude->');
end
Answers
1) x=[1 2 1 2];
>> mycircconv(x,h)
ans =
ans =
6 7 6 5
ans =
2 8 6 4
ans =
26 31 20 27
5)For this problem we use function to compute linear convolution from circular convolution.
function [y]=circtolin(g,h)
N1=length(g);
N2=length(h);
N3=N1+N2-1;
h=[h,zeros(1,N3-N1+1)];
g=[g,zeros(1,N3-N2+1)];
for n=1:N3;
y(n)=0;
for i=1:N3;
j=n-i+1;
if(j<=0)
j=N3+j;
end
y(n)=[y(n)+(g(i)*h(j))];
end
end
subplot(2,1,1);
stem(y);
xlabel('N->');
ylabel('Amplititude->');
ans =
2 9 18 20
ans =
10 26 42 18