MATLAB: How can i convolve a unit ramp and unit step signal without using the ‘conv’ code

function [a,b,m,sum] =convsamp( h )
m=0:h;
a=[0,(0:h)]; %unit ramp sequence
b=[0,ones(1,h)]; %unit step sequence
sum =(h+h)-1;
for i=0:(h+h)-1
y(i)=0;
for j=0:h
if(i-j+1>0)
y(i)=y(i)+a(j)*h(i-j+1);
end
end
end
subplot(3,1,1), stem (m,b), %plots the step signal
title('Unit Step Sequence');
subplot(3,1,2),stem(m,a), %plots the ramp signal
title('Unit Ramp Sequence');
—i used this code but there seems to be a problem in line 6 y(i)=0; can you please help me

Best Answer

An easy way to implement a convolution without using conv is to implement the convolution theorem:
function c = myconv(a, b)
len = numel(a) + numel(b) - 1;
c = ifft(fft(a, len) .* fft(b, len));
end
Probably faster than the built-in conv as well.
Related Question