Berikut ini yaitu script MATLAB untuk convolution tanpa memakai function conv().
x = input('First signal ');
h = input('Second signal ');
a = length(x);
b = length(h);
n = a + b - 1;
y = zeros(1,n);
l = 1:n;
c = 0:a - 1;
d = 0:b - 1;
for i = 0:n
for j = 0:n
if((i - j + 1)>0 && (i - j + 1)<=b && (j + 1)<=a)
y(i+1) = y(i+1) + x(j+1).*h(i - j +1);
end
end
end
disp(y);
subplot(3,1,1)
stem(c,x)
grid on
ylabel('magnitude')
title('\bf First Input')
subplot(3,1,2)
stem(d,h)
grid on
ylabel('magnitude')
title('\bf Second Input')
subplot(3,1,3)
stem(l,y)
grid on
ylabel('magnitude')
xlabel('t')
title('\bf Output')
h = input('Second signal ');
a = length(x);
b = length(h);
n = a + b - 1;
y = zeros(1,n);
l = 1:n;
c = 0:a - 1;
d = 0:b - 1;
for i = 0:n
for j = 0:n
if((i - j + 1)>0 && (i - j + 1)<=b && (j + 1)<=a)
y(i+1) = y(i+1) + x(j+1).*h(i - j +1);
end
end
end
disp(y);
subplot(3,1,1)
stem(c,x)
grid on
ylabel('magnitude')
title('\bf First Input')
subplot(3,1,2)
stem(d,h)
grid on
ylabel('magnitude')
title('\bf Second Input')
subplot(3,1,3)
stem(l,y)
grid on
ylabel('magnitude')
xlabel('t')
title('\bf Output')
Sumber http://lang8088.blogspot.com
EmoticonEmoticon