%Subtracts acquired dark at each pixel
close all
clear
load('dat_d2ki19i17_f4all58ms');

pn1=18; %peak d2k
pn2=34; %peak i19
pn3=54; %peak 117

mx8v=mean(x8v);  sx8v=std(x8v(:,pn1));
mx9v=mean(x9v);  sx9v=std(x9v(:,pn2));
mx10v=mean(x10v);  sx10v=std(x10v(:,pn3));
%mx11v=mean(x11v(:,pn2));  sx10v=std(x10v(:,pn2));
%mx12v=mean(x12v(:,pn2));  sx10v=std(x10v(:,pn2));
%mx13v=mean(x13v(:,pn2));  sx10v=std(x10v(:,pn2));
%mx14v=mean(x14v(:,pn2));  sx10v=std(x10v(:,pn2));

x1s=x1v-mx8v; 
x2s=x2v-mx9v;
x3s=x3v-mx10v;
%x4s=x3v-mx10v;
%x5s=x3v-mx10v;
%x3s=63v-mx10v;
%x7s=x3v-mx10v;

mx1s=mean(x1s(:,pn1)); %sx1s=std(x1s(:,pn1));
mx2s=mean(x2s(:,pn2)); %sx2s=std(x2s(:,pn2));
mx3s=mean(x3s(:,pn3)); %sx3s=std(x3s(:,pn3));
%mx4s=mean(x4(:,pn2)); sx4s=std(x4s(:,pn2));
%mx5s=mean(x5s(:,pn2)); sx5s=std(x5s(:,pn2));
%mx6s=mean(x6s(:,pn2)); sx6s=std(x6s(:,pn2));
%mx7s=mean(x6s(:,pn2)); sx6s=std(x6s(:,pn2));

px1s=mean(x1s(:,pn1));
px2s=mean(x2s(:,pn2));
px3s=mean(x3s(:,pn3));
%px4s=mean(x4s(:,pn2));
%px5s=mean(x5s(:,pn2));
%px6s=mean(x6s(:,pn2));
%px7s=mean(x7s(:,pn2));

%figure; plot(x1s'); axis([-50 300 0 3]); grid on; grid minor; title('d2k spectrum at low gain 58ms'); 
figure; plot(x2s'); axis([-50 300 0 3]); grid on; grid minor; title('i19 spectrum at high gain 58ms'); 
figure; plot(x3s'); axis([-50 300 0 3]); grid on; grid minor; title('i17 spectrum at high gain 58ms'); 
%figure; plot(x5s'); axis([-50 300 0 3]); grid on; grid minor;
%figure; plot(x5s'); axis([-50 300 0 3]); grid on; grid minor;
%figure; plot(x6s'); axis([-50 300 0 3]); grid on; grid minor;
%figure; plot(x7s'); axis([-50 300 0 3]); grid on; grid minor;
%xlabel('Wavelength [nm]'); ylabel('A/D In [volts]');

%figure;  plot(x8v'); axis([-50 300 1.2 1.3]); grid on; grid minor; title('d2k dark at low gain 58ms');
figure; plot(x9v'); axis([-50 300 0 0.5]); grid on; grid minor; title('i19 time dark at low gain 58ms');
figure; plot(x10v'); axis([-50 300 0 0.5]); grid on; grid minor; title('i17 time dark at low gain 58ms');

%figure; plot(x1s); title('d2k time signal at low gain 58ms');
figure; plot(x2s); title('i19 time signal at low gain 58ms');
figure; plot(x3s); title('i17 time signal at low gain 58ms');

save('dat_d2ki19i17_f4all58msa');
%save('dat_d2ki19i17_f4all58msa.csv','-ascii'); %remove arrays first
