function y = thr(RTT,N,C,rl,WI)

% Variables:
% 
% RTT - roundtrip time (in seconds)
% N - file size (in packets) (equals the window init parameter)
% C - capacity (in Mbits/sec)
% rl - rate-limit  (a number - divide capacity with this)
% 

Tnm1=0;


C=C/rl;

Tnm1 = (N*8*1000)/(C*1000000);
%in seconds


if Tnm1 < RTT
 Tnm1 = RTT;
end

if WI < N
 Tnm1 = (WI*8*1000)/(C*1000000);
  if Tnm1 < RTT
   Tnm1 = RTT;
  end
%  add=log2(N)-log2(WI);
  add=log2(N/WI);
  add=ceil(add);
  add=add*RTT;
  Tnm1=Tnm1+add;
end


if N == 1
 Tm = RTT;
else
 Tm = ceil(log2(N))*RTT;
%Tm = log2(N)*RTT;
end



y=Tnm1;

































