% Studying convolution in dimension 1
%
% Samuli Siltanen November 2014

% Parameters for controlling the plot
fsize = 14;

% Create evaluation points 
Ny = 256;
y  = linspace(0,2*pi,Ny);

% Construct original signal f
f = MyFun1(y);

% Construct "point spread function"
% and normalize it so that its elements sum to 1
psf = [1 1 1];
psf = conv2(psf,psf);
psf = conv2(psf,psf);
psf = conv2(psf,psf);
psf = conv2(psf,psf);
psf = psf/sum(psf);

% Compute convolution
p_f = conv2(f,psf,'same');

figure(1)
clf
% Plot the original function
subplot(2,1,1)
plot(y,f,'k')
hold on
plot(y,p_f,'r')
MAX = max(max(f),max(p_f));
MIN = min(min(f),min(p_f));
axis([0 2*pi 1.1*MIN 1.1*MAX])
title('Signal f (black) and convolution p*f (red)','fontsize',fsize)

subplot(2,1,2)
plotpsf = zeros(size(f));
plotpsf(end/2+[1:length(psf)]) = psf;
plot(y,plotpsf,'r')
xlim([0 2*pi])
title('Point Spread Function (red)','fontsize',fsize)
