close all
clear all


Vout = 300;

DC_1 = [10:10:100 150 200 250];  DC_1 = DC_1/4095;
I_Reported_1 = [0.0 .07 .17 .27 .37 .47 .57 .66 .76 .86 1.35 1.83 2.34];
I_Measured_Zero = -2.38;
I_Measured_1 = [-2.3 2.4 7.3 12.3 17.4 22.4 27.4 32.5 37.5 42.6 67.8 93.2 118.8];  
I_Measured_1 = I_Measured_1-I_Measured_Zero
I_Measured_1 = I_Measured_1/50;



DC_2 = [50:50:150]; DC_2 = DC_2/4095;
I_Reported_2 = [.37 .86 1.35];
I_Measured_Zero = -1.88;
I_Measured_2 = [17.8 43 68.3];
I_Measured_2 = I_Measured_2-I_Measured_Zero
I_Measured_2 = I_Measured_2/50;


DC_3 = [300 501 978 1479 2025]; DC_3 = DC_3/4095;
I_Reported_3 = [2.83 4.78 9.44 14.28 19.53];
I_Measured_Zero = -8.9;
I_Measured_3 = [138.6 241.2 483.8 735 1000];
I_Measured_3 = I_Measured_3-I_Measured_Zero
I_Measured_3 = I_Measured_3/50;



DCC = (0:1:50)/100

figure
plot(100*DC_1,[I_Reported_1 ; I_Measured_1],'-x')
legend('Reported by controller','Measured');
hold on
plot(100*DC_2,[I_Reported_2 ; I_Measured_2],'-x')
plot(100*DC_3,[I_Reported_3 ; I_Measured_3],'-x')

plot(DCC*100,300*DCC/7.5,'-r')
ylabel('Current (A)')
xlabel('Load Dump Duty Cycle (%)');
title('Boosting from 100V->300V, independent measurement made');

R0 = 7.5;
DC_adjusted = R0*I_Measured_1/Vout;

DC = [DC_2 DC_3];
I_Measured = [I_Measured_2 I_Measured_3];

p = polyfit(DC,I_Measured,1);



figure
plot(DC*100,I_Measured)
hold all
plot(DC*100,p(2)+p(1)*(DC))
legend('measured','linear fit');


C_Measured = I_Measured/Vout;

p = polyfit(DC*4095,C_Measured,1);

figure
plot(DC*4095,C_Measured)
hold all
plot(0:4095,(p(2)+p(1)*(0:4095)))
legend('measured','linear fit');