close all
clear all

K = 3.2277e6;
T = 5e-5;
R0 = 7.5;

Vout = 325;

DC_1 = [30:10:110 140 170];  DC_1 = DC_1/4095;
I_Reported_1 = [.08 .2 .27 .34 .42 .58 .66 .75 .83 1.16 1.5];
I_Measured_1 = ones(1,length(DC_1))*NaN;

DC_adjusted = DC_1-(1-exp(-K*T*DC_1))/(K*T);
I_Predicted_1 = Vout*DC_adjusted/R0;




figure
plot(100*DC_1,[I_Reported_1 ; I_Predicted_1 ; I_Measured_1])
ylabel('Current (A)')
xlabel('Load Dump Duty Cycle (%)');
legend('Reported by controller','Predicted by Cal curve','Measured');
title('Boosting from 100V->325V, no independent measurement made');




DC_2 = [0 10 20:10:120 210];  DC_2 = DC_2/4095;
I_Reported_2 = [NaN NaN .04 .08 .2 .27 .34 .42 .58 .66 .75 .83 1.0 1.91];
I_Measured_2 = [NaN NaN 3.5 8.8 14.2 19.6 25 30.4 35.7 41.2 46.6 52 57.4 105];  I_Measured_2 = I_Measured_2/50;

DC_adjusted = DC_2-(1-exp(-K*T*DC_2))/(K*T);
I_Predicted_2 = Vout*DC_adjusted/R0;

C = 700;
C2 = 350;
R0_adjusted = 7.48
%DC_adjusted = DC_2-(1-exp(-C*DC_2))/(C2);
DC_adjusted = DC_2-2*(1-exp(-C*DC_2))/C;
I_Adjusted_2 = Vout*DC_adjusted/R0_adjusted;



figure
plot(100*DC_2,[I_Reported_2 ; I_Predicted_2 ; I_Measured_2; I_Adjusted_2],'-x')
ylabel('Current (A)')
xlabel('Load Dump Duty Cycle (%)');
legend('Reported by controller','Predicted by Cal curve','Measured');
title('Boosting from 100V->320V, independent measurement made');



Vout = 320;
DC_3 = [0 5 9 14 18 23 32 41 50 59 68 77 86 96 105 114 123 132 232 332 446];  DC_3 = DC_3/4095;
I_Reported_3 = [0 0 .01 .01 .04 .04 .13 .18 .25 .32 .39 .47 .54 .7 .78 .85 .93 1.01 2.04 2.98 4.08];
I_Measured_3 = [0 0 0 0 2.5 5.3 9.7 14.2 18.7 23.1 27.5 31.9 36.3 41.3 46 50.5 55.1 59.7 110.6 160.5 219];  I_Measured_3 = I_Measured_3/50;

DC_adjusted = DC_3-(1-exp(-K*T*DC_3))/(K*T);
I_Predicted_3 = Vout*DC_adjusted/R0;

DC_adjusted = DC_3-(1-exp(-C*DC_3))/(C);
I_Adjusted_3 = Vout*DC_adjusted/R0_adjusted;


figure
plot(100*DC_3,[I_Reported_3 ; I_Predicted_3 ; I_Measured_3 ; I_Adjusted_3 ],'-x')
ylabel('Current (A)')
xlabel('Load Dump Duty Cycle (%)');
legend('Reported by controller','Predicted by Cal curve','Measured','Adjusted Cal Curve');
title('No Boost, Vin = 320V, independent measurement made');

figure(2)

