%Calibration Data					

%V0	Vactual	Vadc	m	b	Conversion Formula
%0	3.028	620	0.004883871	0	=N28*$O$28+$P$28
%					
%I0	Iactual	Iadc	m	b	Conversion Formula
%2	19.8	862	0.022969838	0	=N31*$O$31+$P$31
%% Calibration
V0 = 0;
V1 = 3.028;
V1adc=620;
Vm = V1/V1adc;
Vb=V1-Vm*V1adc;

I0 = 2;
I1=19.8;
I1adc=862;
Im = (0-I1)/(2-I1adc);
Ib=I1-Im*I1adc;

%23C is 716
%6C is 671
TR1 = 23;
TADC1 = 716;
TR2 = 6;
TADC2 = 671; 
Tm = (TR1-TR2)/(TADC1-TADC2);
Tb = TR1-Tm*TADC1;

%% Apply calibration and extract
Time = data(:,1);
Temp = Tm*data(:,2)+Tb;
Vsun = Vm*data(:,4)+Vb;
Isun = (Im*data(:,5)+Ib)/1000;



%% Plot data
%plotyy(Time, Isun, Time, Vsun);
%hold on
plotyy(Time,Temp,Time,data(:,3));
%hold off;

%% Calculate power
Wsun = Vsun.*Isun; %watts
Psun = Wsun / 0.00387096;
Pideal = Psun / .04;
max(Pideal)
plot(Time, Pideal);