% Calculo de la curva de perdidas

R = 7000000;
%%%%precision3
R = 9000000;
R = 8500000;
% R = 8000000;
bins = 10;
oversampling = 10;
periodo = 1/25;

load Mawi1999B_40ms1h
load Mawi1999B_T1h
tramas = 10000; % length(Mawi1999B_40ms1h);
simulacion = tramas;
T = Mawi1999B_40ms1h(1:tramas);
maxiter = 100;

fprintf('\n\nR = %g \n\n', R);



clf

Plosss = [];
Plossh = [];
Plossp = [];

periodos = 1000;
k = 1;
for buffer = 10000:10000:1000000

    % Calculo por simulación paquetes
    fprintf('\n %g ', buffer);
    [B, Ploss, CLR, T2 ] = HML_BufferT( Mawi1999B_T1h, R, buffer, periodo, simulacion*periodo*1e6);
    fprintf(' Plosss =%g  ', Ploss);
    Plosss(1,k) = buffer;
    Plosss(2,k) = Ploss;


    % Calculo por histograms 
    LH = HML_Hist2( T2, bins);
    LHO = HML_HStretch(LH, oversampling);
    [RFBH, Ploss, i] = HML_HBufferSP(LHO, R, buffer, periodo,maxiter);
    fprintf(' Plossh =%g  ', Ploss);
    Plossh(1,k) = buffer;
    Plossh(2,k) = Ploss;
    
    % calcula por periodos
    Ploss = HML_PeriodLoss( T2, R, buffer, periodo, 10);
    fprintf(' Plossp =%g', Ploss);
    Plossp(1,k) = buffer;
    Plossp(2,k) = Ploss;

    
    k = k + 1;
    
end




clf
semilogy(Plosss(1,:),Plosss(2,:));
hold all;
semilogy(Plossh(1,:),Plossh(2,:));
hold all;
semilogy(Plossp(1,:),Plossp(2,:));
legend('simulation','histogram','period');
xlabel('buffer');

