data=load('log');
dac=data(:,1);
adc=data(:,2);
t=1:size(data,1);
calib=1.385419;
length(t)

%% adc to actual current in (A/ADC count)
scale = computeI/1000;
scale = scale(1); % just the gain part only

%% get the dc value
t=50:100;
dc = mean(dac(t)-calib*adc(t));

% extract the part for the light and pc
t=1079950:1080290;
out = [t' - t(1), (dac(t) - calib*adc(t) - dc)/calib*scale, (adc(t) < 400 | adc(t) > 1650)];
save("-ascii","lightpc.dat","out");

% light only
t=100090:100358; 
out = [t' - t(1), (dac(t) - calib*adc(t) - dc)/calib*scale];
save("-ascii","light.dat","out");

% keithley stepping
t=1590000:1680000;
out = [t' - t(1), (dac(t) - calib*adc(t) - dc)];
save("-ascii","keithley.dat","out");

