close all
clear all

Vemf = 40;

Rfets = .08;
Rw = .15;
Lw = .00087;


N = [500:1500:5000];

SP = 2;
Rload = (300^2)./(SP*N);

Vg = 1.35*Vemf*N/1000;

Rreal = ones(1,length(N))*(Rw+2*Rfets);
Rcomplex = (Lw*2*pi*N*5/60);
Rabs = (Rcomplex.^2+Rreal.^2).^.5;


Dbar = 1:-.01:0';
D = 1-Dbar;

for n = 1:length(N)
Vg(n) =  1.35*Vemf*N(n)/1000;
VReal(n,:) = Vg(n)*(1./Dbar)./(1+ones(1,length(Dbar))*Rreal(n)./((Dbar.^2)*Rload(n)));
VAbs(n,:) =  Vg(n)*(1./Dbar)./(1+ones(1,length(Dbar))*Rabs(n)./((Dbar.^2)*Rload(n)));
leg_str{n} = ['N = ' num2str(N(n)) ' rpm    Rload = ' num2str(Rload(n),3) ' Ohms    Power @ 300V = ' num2str(300*300/Rload(n)) ' W']; 

EffReal(n,:) = 1./(1+ones(1,length(Dbar))*Rreal(n)./((Dbar.^2)*Rload(n)));
EffAbs(n,:) = 1./(1+ones(1,length(Dbar))*Rabs(n)./((Dbar.^2)*Rload(n)));
end


TestDC = [1:-.1:.2 .15];
TestVolt = [51 56.8 64 73.8 86 102 130 163 230 291]

figure('Position',[1000 388 1509 1110]);
subplot(2,1,1)
plot(Dbar,VReal)
grid on;
title(['Winding Resistance Alone:  Rfets = ' num2str(Rfets) ' Ohms'  '      ' num2str(SP) ' W/RPM']);
legend(leg_str,'Location','NorthEast');
xlabel('Dbar');
ylabel('Bus Voltage');
ylim([0 500]);

subplot(2,1,2)
plot(Dbar,VAbs,TestDC,TestVolt,'ko')
title(['Including Impedance of Inductor:  Rfets = ' num2str(Rfets) ' Ohms']);
legend(leg_str,'Location','NorthEast');
xlabel('Dbar');
ylabel('Bus Voltage');
grid on;
ylim([0 500]);



figure('Position',[1000 388 1509 1110]);
subplot(2,1,1)
plot(Dbar,EffReal)
grid on;
title(['Winding Resistance Alone:  Rfets = ' num2str(Rfets) ' Ohms']);
legend(leg_str,'Location','NorthEast');
xlabel('Dbar');
ylabel('Efficiency');
subplot(2,1,2)
plot(Dbar,EffAbs)
title(['Including Impedance of Inductor:  Rfets = ' num2str(Rfets) ' Ohms']);
legend(leg_str,'Location','NorthEast');
xlabel('Dbar');
ylabel('Efficiency');
grid on;


figure('Position',[1000 388 1509 1110]);
plot(Dbar,VReal);
hold all;
plot(Dbar,VAbs,TestDC,TestVolt,'ko');
grid on;
title(['Winding Resistance Alone:  Rfets = ' num2str(Rfets) ' Ohms']);
legend('Real Resistance','Complex Impedance','Test Data','Location','NorthEast');



