function [] = growingHconstantT_N(BW,PLrr,PLrsi,Trr,N,H)
T_RTCP(1)=(N*PLrr/(0.0375*BW));

for h = 1:H
    T(h)=nthroot(((N*PLrr*power(PLrsi,h-1))/(power(0.0375*BW,h))),h);
end
for h = 2:H
    if(T(h)<Trr)
    T_RTCP(h)=nthroot(((N*PLrr*power(PLrsi,h-1))/(Trr*power(0.0375*BW,h))),h-1);
    else
        T_RTCP(h)=T(h);
    end
end

T_RTCP



T



for k = 1:H
    if(T_RTCP(k)>Trr)
        Tcel_RTCP(k) = T_RTCP(k)*k ;
    else
        Tcel_RTCP(k) = Trr + T_RTCP(k)*(k-1) ;
    end
end

Tcel_RTCP

for k = 1:H
    TcelOptim(k) = T(k)*k ;

end
TcelOptim

for i = 1:H
    
    if(T(i)>Trr)
    Told(i) = T(i);
    else
        Told(i)=Trr;
    end
    TcelOld(i) = Told(i)*i;
    
end
Told
TcelOld
figure

semilogy(1:H,Tcel_RTCP,'LineWidth',2)
hold on
grid on
semilogy(1:H,TcelOptim,'--r','LineWidth',2)
semilogy(1:H,TcelOld,'.-.g','LineWidth',2);

% title('Celkove zpozdení zavisle na vysce stromu ')
% xlabel('Vyska stromu \rightarrow')
% ylabel('celkove zpozdeni [s]')


FT_RTCP(1)= (N*PLrr)/(Trr*0.0375*BW);
for h = 2:H
   
    FT_RTCP(h)= FT_RTCP(h-1)*PLrsi/(0.0375*BW*T_RTCP(H));

end
FT_RTCP

FTcel_RTCP = sum(FT_RTCP)

FT(1)= (N*PLrr)/(T(H)*0.0375*BW);
FTold(1) = (N*PLrr)/(BW*0.0375*Told(H));
for h = 2:H
   
    FT(h)= (FT(h-1)*PLrsi)/(0.0375*BW*T(H));
    
    if(FTold(h-1)>1)
    FTold(h)= (N*PLrr*power(PLrsi,h-1))/(power((BW*0.0375),h)*power(Told(H),h));
    else
        FTold(h)=0;
     
        for g = h:H
            Told(g)=0;
        end
        if(FTold(h-1)> 0)
            FTold(h-1)=1;
        end
        
    end   
end


FT
FTcel = sum(FT)
FTold



for t = 1:H
    RTCP_one(t)=TcelOld(1);
end

semilogy(1:H,RTCP_one,'y','LineWidth',2)
% semilogy(1:H,FT_RTCP,'+','LineWidth',2);
% semilogy(1:H,FT,'r+','LineWidth',2);
% semilogy(1:H,FTold,'g+','LineWidth',2)

% text(h/2,RTCP_one(1),'Delay in RTCP')

% legend('TTP_o_p_t_(_R_T_C_P_)','TTP_o_p_t','TTP_(_R_T_C_P_)','RTCP','pocet FT (TTP_o_p_t _(_R_T_C_P_))','pocet FT (TTP_o_p_t)','pocet FT (TTP_R_T_C_P)');
legend('TTP_o_p_t_(_R_T_C_P_)','TTP_o_p_t','TTP_(_R_T_C_P_)','RTCP');
