% Simulation of "continuum model" measurement data. We evaluate the
% desired convolution between functions of real variable at quite many
% point and save the result to a .mat file. Then later evaluation can be
% done quickly by interpolation.
%
% Samuli Siltanen Jan 2017

% Choose many evaluation points
xvec = linspace(0,1,10000);

% Parameter determining the width of the PSF
a = .025;

% Create integration points for the interval [-a,a].
% Here we just use the midpoint rule.
Ny = 2048;
y  = linspace(-a,a,Ny);
Dy = y(2)-y(1);

% Initialize the result
convres = zeros(size(xvec));

% Loop over x values
for iii = 1:length(xvec)
    % Evaluate the integrand with the current x
    x = xvec(iii);
    intgnd = PSF(y,a).*targetf(x-y);
    
    % Compute the integral
    convres(iii) = Dy*sum(intgnd);
end

% Save the results
mkdir data
save data/convdata xvec a convres