%
%
%
% Optical Imaging and Spectroscopy
%
% David J. Brady
% Duke University
% www.opticalimaging.org
%
% Figure 9.7
%
% Script to compare Poisson noise in identity and multiplex systems
%
% Definition of spectral signature
%
%
clear all;
figure(1);set(gcf,'color','white');
lambda=linspace(400,700,511);
hMat=(1+hadamard(512))/sqrt(2);
hMat=hMat(2:512,2:512);
spec=exp(-(lambda-450).^2/10^2);
spec=spec+.7*exp(-(lambda-480).^2/5^2);
spec=spec+.5*exp(-(lambda-510).^2/7^2);
spec=spec+.25*exp(-(lambda-550).^2/3^2);
spec=spec+.1*exp(-(lambda-600).^2/5^2);
spec=spec+.05*exp(-(lambda-650).^2/10^2);
spec1=poissrnd(1000*spec)./1000;
spec2=nnls(hMat,poissrnd(hMat*(1000*spec')))/1000;spec2=spec2';
lev = 5;
spec1Den = wden(spec1,'minimaxi','s','sln',lev,'sym8');
spec2Den = wden(spec2,'minimaxi','s','sln',lev,'sym8');
subplot(3,1,1);plot(lambda,[spec;spec1+.5;spec2+1],'-k');axis([400,700, 0,2.2]); 
title(['(a) \sigma_{slit}^2=' num2str((spec1-spec)*(spec1-spec)',2) '     \sigma_{CA}^2=' num2str((spec2-spec)*(spec2-spec)',2)]);
xlabel('\lambda (nm)');ylabel('Spectral density');
set(gca,'Ytick',[]);
subplot(3,1,2);plot(lambda,[spec1Den+.1;spec2Den+.6],'-k');axis([400,700, 0,1.8]); 
title(['(a) \sigma_{slit}^2=' num2str((spec1Den-spec)*(spec1Den-spec)',2) '     \sigma_{CA}^2=' num2str((spec2Den-spec)*(spec2Den-spec)',2)]);
xlabel('\lambda (nm)');ylabel('Spectral density');
set(gca,'Ytick',[]);
a=spec1Den+.1;b=spec2Den+.6;
subplot(3,2,5);plot(lambda(50:120),[a(50:120);b(50:120)],'-k'); 
title('(c)');set(gca,'Ytick',[]);axis([430,470, 0,1.8]); 
a=spec1Den+.1;b=spec2Den+.2;
subplot(3,2,6);plot(lambda(400:450),[a(400:450);b(400:450)],'-k'); 
title('(d)');set(gca,'Ytick',[]);axis([635,665, 0,.3]); 
