clear all
close all

D_max = 0.75;       %Maximaler Duty Cycle
V_in_min = 350;     %Minimale Eingangsspannung [V]
V_in_nom = 511;     %Nominelle Eingangsspannung [V]
V_FET = 0.3;        %Spannungsabfall an FETs
V_D = 0.7;          %Durchlassspannung Diode [V]
V_out = 24;         %Ausgangsspannung
P_out = 1e3;        %Maximale <Ausgangsleistung
eta = 0.95;         %Effizienz
P_loss = (1-eta) * P_out;  %Akzeptable Verlustleistung [W]
I_out = P_out/V_out;    %Ausgangsstrom [A]
n = ceil(((V_in_min-2*V_FET)*D_max)/(V_out+V_D)); %Windungszahlverhältnis
D_nom = n * (V_out+V_D)/(V_in_nom-2*V_FET); %Nominaler Duty cycle
fs = 100e3;         %Schaltfrequenz [Hz]
lam_max = V_in_nom * D_max /fs; %Maximaler Fluss [Vs]

delta_I_out = 0.2 * I_out;  %Maximaler Rippel am Ausgang [A]
L_m = (V_in_nom*(1-D_nom)*n) / (delta_I_out*0.5*fs); %Minimale Magnetisierungsinduktivität [H]

%Calculate Secondary RMS Current
I_PS = I_out +delta_I_out/2;
I_MS = I_out -delta_I_out/2;
I_MS2 = I_PS - delta_I_out/4;

I_SRMS1 = sqrt((D_max/2)*(I_PS*I_MS+power(I_PS-I_MS,2)/3)); %Sekundärer RMS Strom, wenn Energie übertragen wird
I_SRMS2 = sqrt((1-D_max)/2 * (I_PS*I_MS+power(I_PS-I_MS,2)/3)); %Sekundärer RMS Strom, wenn beide Sekundärdioden leiten
I_SRMS3 = delta_I_out/2 * sqrt((1-D_max)/6);
I_SRMS = sqrt(I_SRMS1*I_SRMS1 + I_SRMS2*I_SRMS2 + I_SRMS3*I_SRMS3); %Total secondary RMS current

%Calculate primary RMS Currents
delta_I_m = V_in_min * D_max /(L_m*fs);
I_PP = 1/n * (I_out/eta + delta_I_out/2) + delta_I_m;
I_MP = 1/n * (I_out/eta - delta_I_out/2) + delta_I_m;
I_PRMS1 = sqrt(D_max * (I_PP*I_MP+power(I_PP-I_MP,2)/3));
I_MP2 = I_PP - delta_I_out/(2*n);
I_PRMS2 = sqrt((1-D_max)*(I_PP*I_MP2+power(I_PP-I_MP2,2)/3));
I_PRMS = sqrt(I_PRMS1*I_PRMS1 + I_PRMS2*I_PRMS2);   %Total primary RMS current



