Sie sind auf Seite 1von 5

Experiment-6

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

can be found by using the following steps

1. Graph N samples of h (n) as equally spaced points around an outer circle in


counterclockwise direction.
2. Start at the same point as h (n) graph N samples of x (n) as equally spaced points
around an inner circle in clock wise direction.
3. Multiply corresponding samples on the two circles and sum the products to
produce output.
4. Rotate the inner circle one sample at a time in counter clock wise direction and go
to step 3 to obtain the next value of output.
5. Repeat step No.4 until the inner circle first sample lines up with first sample of the
exterior circle once again.

In lab Exercise

Divyansh Gaur|Hitesh Kumar Sharma


Write your own MATLAB function mycirconv to compute circular convolution of two
sequences.

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

Post lab Exercise

Q 1. Find circular convolution of the following signals x(n)={1,2,1,2},


h(n)={4,3,2,1}
Q 2. Find circular convolution of the following signals x(n)={1,2,0,1},
h(n)={2,2,1,1}
Q3. Find circular convolution of the following signals x(n)={1,-1,1,1},
h(n)={1,2,3,4}
Q4. Find circular convolution of the following signals x(n)={1,3,4,5},
h(n)={2,1,4,1}
Q 5. Find linear convolution of the following signals using circular convolution
x(n)={1,2,4}, h(n)={2,5}
Q 6. Find linear convolution of the following signals using circular convolution x(n)={5,3},
h(n)={2,4,6}

Answers

1) x=[1 2 1 2];

>> h=[4 3 2 1];

>> mycircconv(x,h)

ans =

Divyansh Gaur|Hitesh Kumar Sharma


14 16 14 16

2) >> x=[1 2 0 1];


>> h=[2 2 1 1];
>> mycircconv(x,h)

ans =

6 7 6 5

3)>> x=[1 -1 1 1];


>> h=[1 2 3 4];
>> mycircconv(x,h)

ans =

2 8 6 4

Divyansh Gaur|Hitesh Kumar Sharma


4)>> x=[1 3 4 5];
>> h=[2 1 4 1];
>> mycircconv(x,h)

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->');

Divyansh Gaur|Hitesh Kumar Sharma


end

>> x=[1 2 4];


>> h=[2 5];
>> circtolin(x,h)

ans =

2 9 18 20

6) >> x=[5 3];


>> h=[2 4 6];
>> circtolin(x,h)

ans =

10 26 42 18

RESULT: We created a MATLAB function to compute circular convolution of two sequences.

Divyansh Gaur|Hitesh Kumar Sharma

Das könnte Ihnen auch gefallen