Pages

Thursday, 21 February 2013

Circular Convolution (Matlab 2012a)

Program:

clc;
clear all;
x1 = input('Enter the first sequence = ');
x2 = input('Enter the second sequence = ');
l1 = length(x1);
l2 = length(x2);
n1 = max(l1,l2);
l = l1-l2;
if(l>=0)
x2 = [x2,zeros(1,l)];
else
    x1 = [x1,zeros(1,-l)];
end%circular shifting and convolution
for n = 1:n1
    y(n) = 0;
    for i = 1:n1
        j = n-i+1;
        if(j<=0)
            j = n1+j;
        end
        y(n) = [y(n)+x1(i)*x2(j)];
    end
end%plot the inputs and output
n = 0:n1-1;
subplot(3,1,1);
stem(n,x1);
grid on;
xlabel('Time--->');
ylabel('Amplitude--->');
title('First Sequence');
subplot(3,1,2);
stem(n,x2);
grid on;
xlabel('Time--->');
ylabel('Amplitude--->');
title('Second Sequence');
subplot(3,1,3);
disp('Convolved Sequence = ');
disp(y);
stem(n,y);
grid on;
xlabel('Time--->');
ylabel('Amplitude--->');
title('Convolved Output');



Output:

Enter the first sequence  = [1 2 3 4]
Enter the second sequence  = [1 2 3]

Convolved Sequence =
    18    16    10    16 


Waveforms:

No comments:

Post a Comment