Pages

Thursday, 21 February 2013

Linear Convolution Using Function (Matlab 2012a)

Program


clc;
clear all;
x1 = input('Enter the first sequence x1(n) = ');
t1 = input('Enter the starting time of first sequence t1 = ');
x2 = input('Enter the second sequence x2(n) = ');
t2 = input('Enter the starting time of second sequence t2 = ');
l1 = length(x1);
l2 = length(x2);
ln = l1+l2-1;
y = conv(x1,x2);
a = t1+l1-1;
t = t1:a;
subplot(3,1,1);
stem(t,x1);
grid on;
xlabel('Time--->');
ylabel('Amplitude--->');
title('First Sequence');
a = t2+l2-1;
t = t2:a;
subplot(3,1,2);
stem(t,x2);
grid on;
xlabel('Time--->');
ylabel('Amplitude--->');
title('Second Sequence');
tn = t1+t2;
a = tn+ln-1;
t = tn:a;
subplot(3,1,3);
disp('Convolved Sequence = ');
disp(y);
stem(t,y);
grid on;
xlabel('Time--->');
ylabel('Amplitude--->');
title('Convolved Output');



Output:

Enter the first sequence x1(n) = [1 2 1 0]
Enter the starting time of first sequence t1 = 0
Enter the second sequence x2(n) = [1 0 1]
Enter the starting time of second sequence t2 = 0
Convolved Sequence =
     1     2     2     2     1     0


Waveforms:

No comments:

Post a Comment