%Expanded original to process new d2k data. Subtracts acquired dark. Best Functionality
close all
clear
load('dat_d2ki19i17_f4');

pn1=8; %offset
pn2=138; %peak spectralon
pn3=19; %peak finger

mx8v=mean(x8v(:,pn2));  sx8v=std(x8v(:,pn2));
mx9v=mean(x9v(:,pn2));  sx9v=std(x9v(:,pn2));
mx10v=mean(x10v(:,pn2));  sx10v=std(x10v(:,pn2));
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(:,pn2)); sx1s=std(x1s(:,pn2));
mx2s=mean(x2s(:,pn2)); sx2s=std(x2s(:,pn2));
mx3s=mean(x3s(:,pn2)); sx3s=std(x3s(:,pn2));
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(:,pn2));
px2s=mean(x2s(:,pn2));
px3s=mean(x3s(:,pn2));
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;
figure; plot(x2s'); axis([-50 300 0 3]); grid on; grid minor;
figure; plot(x3s'); axis([-50 300 0 3]); grid on; grid minor;
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;
save('dat_d2ki19i17_f4a');
%save('dat_d2ki19i17_f4a.csv','-ascii'); %remove arrays first
