You are on page 1of 1

%% Convolution Sum

clear all;
close all;
clc;
% initializing arrays_user input
x=[-3 -2 -1 1 2 1];
%x=randn(1,200);
xn=-3:2;
%xn=0:199;
h=[1 2 3 4 5];
%h=randn(1,200);
hn=-2:2;
%hn=0:199;
% defining variables
tic
xlen=length(xn);
hlen=length(hn);
yn=xn(1)+hn(1):xn(end)+hn(end);
ylen=length(yn);
y=zeros(1,ylen);
%Starting loop
for i=1:xlen
for j=1:hlen
y(i+j-1)=y(i+j-1)+ x(i)*h(j);
end
end
toc
% view result
disp(y);
disp(yn);
%% check
tic
y1=conv(x,h);
toc
disp(y1);

You might also like