% Example computations related to one-dimensional deconvolution.
% Demonstration of Tikhonov regularization.
%
% The following routines must be computed before this one:
% DC2_discretedata_comp.m
%
% Samuli Siltanen February 2012

% Regularization parameter
alpha = .2;

% Plot parameters
lwidth = .5;
thickline = 2;
fsize = 20;
msize = 4;

% Load data computed using a very fine grid, avoiding inverse crime
load data/DC2_discretedata A x xx n m mn mIC sigma

% Choose data 
data = mn;

% Construct the regularization matrix L.
% In this case of classical Tikhonov regularization it is just identity.
L = eye(n);

% Construct original signal for comparison
signal = DC_target(xx);

% Reconstruct from noisy data using Tikhonov regularization.
syst  = [A; sqrt(alpha)*L];
m_aug = [data(:);zeros(n,1)];
rec   = syst\m_aug;

% Calculate relative error
truth  = DC_target(x);
relerr = round(norm(rec(:)-truth(:))/norm(truth(:))*100);

% Take a look at the reconstruction
figure(6)
clf
plot(xx,signal,'k','linewidth',lwidth)
hold on
plot(x,rec,'k','linewidth',thickline)
text(0.9,1.5,[num2str(relerr),'%'],'fontsize',fsize)

% Axis settings
axis([0 1 -.5 2])
set(gca,'xtick',[0 1/2 1],'fontsize',fsize)
set(gca,'ytick',[0  1 2],'fontsize',fsize)
set(gca,'PlotBoxAspectRatio' , [2 1 1])
box off
