% We plot naive reconstructions (deconvolutions) from simulated 1D
% convolution data with and without inverse crime.
%
% The routines DC1_cont_data_comp.m and DC2_discretedata_comp.m must be 
% executed before running this code.
%
% Jennifer Mueller and Samuli Siltanen, January 2014

% Parameters for formatting the plotted figures. Modify if the linewidth, 
% font size or point size in the plots are not optimal in the figures.
fsize  = 10;
lwidth = 1;
msize = 6;

% Load precomputed results. The routines DC1_cont_data_comp.m and 
% DC2_discretedata_comp.m must be executed before running this code.
load DC2_discretedata A x n m mn mIC sigma

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


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Compute reconstruction from data with inverse crime
reco  = inv(A)*mIC(:);
recon = inv(A)*(mIC(:)+0.00001*randn(size(mIC)));

% Create plot window
figure(2)
clf
subplot(2,1,1)
% Plot original target 
plot(xx,targ,'k','linewidth',lwidth)
hold on

% Plot the naive reconstruction
plot(x,reco,'r.','markersize',msize)
plot(x,reco,'r')

% Axis settings
axis([0 1 -.2 1.6])
box off
set(gca,'ytick',[0,.5,1,1.5],'fontsize',fsize)
set(gca,'xtick',[0,.5,1],'fontsize',fsize)
set(gca,'PlotBoxAspectRatio' , [2 1 1])
title('Naive reconstruction (red) from ideal data with inverse crime')

subplot(2,1,2)
% Plot original target 
plot(xx,targ,'k','linewidth',lwidth)
hold on

% Plot the naive reconstruction
plot(x,recon,'r.','markersize',msize)
plot(x,recon,'r')

% Axis settings
axis([0 1 -.2 1.6])
box off
set(gca,'ytick',[0,.5,1,1.5],'fontsize',fsize)
set(gca,'xtick',[0,.5,1],'fontsize',fsize)
set(gca,'PlotBoxAspectRatio' , [2 1 1])
title('Naive reconstruction (red) from ideal data with inverse crime')



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Compute reconstruction from ideal data without inverse crime
reco = inv(A)*m(:);

% Create plot window
figure(3)
clf

% Plot original target 
plot(xx,targ,'k','linewidth',lwidth)
hold on

% Plot the naive reconstruction
plot(x,reco,'r.','markersize',msize)
plot(x,reco,'r')

% Axis settings
axis([0 1 -.2 1.6])
box off
set(gca,'ytick',[0,.5,1,1.5],'fontsize',fsize)
set(gca,'xtick',[0,.5,1],'fontsize',fsize)
set(gca,'PlotBoxAspectRatio' , [2 1 1])
title('Naive reconstruction (red) from ideal data without inverse crime')


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Compute reconstruction from noisy data without inverse crime
recon = inv(A)*mn(:);

% Create plot window
figure(4)
clf

% Plot original target 
plot(xx,targ,'k','linewidth',lwidth)
hold on

% Plot the naive reconstruction
plot(x,recon,'r.','markersize',msize)
plot(x,recon,'r')

% Axis settings
axis([0 1 -.2 1.6])
box off
set(gca,'ytick',[0,.5,1,1.5],'fontsize',fsize)
set(gca,'xtick',[0,.5,1],'fontsize',fsize)
set(gca,'PlotBoxAspectRatio' , [2 1 1])
title('Naive reconstruction (red) from noisy data without inverse crime')
