% Compute the discrete measurement for the one-dimensional convolution
% example on a coarse grid avoiding inverse crime.
% However, the reconstruction is still naive.
%
% Samuli Siltanen September 2008
% Plot parameters
lwidth = .2;
redlwidth = 1;
fsize = 10;
msize = 7;
sigma = .02; % Noise level
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create data on finer grid to avoid inverse crime
% Construct signal
Nf = 1499;
sf = linspace(0,1,Nf);
Dsf = sf(2)-sf(1);
xf = zeros(size(sf));
xf((sf>(1/4))&(sf<(1/2))) = 1;
xf((sf>(3/4))&(sf<(7/8))) = 2;
% Construct normalized point spread function
a = .05;
nPSFf = ceil(a/Dsf);
sPSFf = [-nPSFf:nPSFf]*Dsf;
PSFf = zeros(size(sPSFf));
PSFf((sPSFf>(-a))&(sPSFf(-a))&(sPSF(1/4))&(s<(1/2))) = 1;
x((s>(3/4))&(s<(7/8))) = 2;relerr = round(norm(rec(:)-x(:))/norm(x(:))*100);
disp(['relative error of reconstruction from ideal data is ', num2str(relerr), '%'])
% Reconstruct from noisy data
recn = inv(A)*mn;
relerr = round(norm(recn(:)-x(:))/norm(x(:))*100);
disp(['relative error of reconstruction from noisy data is ', num2str(relerr), '%'])
% Construct continuum quantities for visual comparison
% Construct signal
Nc = 5000;
sc = linspace(-2,2,2*Nc+1);
Xc = zeros(size(sc));
Xc((sc>(1/4))&(sc<(1/2))) = 1;
Xc((sc>(3/4))&(sc<(7/8))) = 2;
PSFc = zeros(size(sc));
PSFc((sc>(-a))&(sc