convolutions

Contents

rect * rect

do_convolve(@rect,@rect);

shift one of the functions

% note use of anonymous function
do_convolve(@rect,@(x) rect(x-1));

rect * tri

do_convolve(@rect,@tri);

tri * tri

do_convolve(@tri,@tri);

no symmetry

f = @(x) tri(x).*rect(x-0.5);

g = do_convolve(f,f);

x = linspace(-2,2,length(g));
dx = x(2)-x(1);
y = f(x);
farea = trapz(x,f(x));
fprintf('area under f(x): %g\n',farea);
garea = trapz(x,g);
fprintf('area under convolution: %g\n',garea);
area under f(x): 0.5
area under convolution: 0.25

flip second function

do_convolve(f, @(x) f(-x));