% 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 = length(Mawi1999B_40ms1h);
simulacion = tramas;
T = Mawi1999B_40ms1h(1:tramas);
maxiter = 100;
    
fprintf('\n\nR = %g \n\n', R);



clf

Plosss = [];
Plossh = [];
Plossp10 = [];
Plossp100 = [];
Plossp1000 = [];
Plossp10000 = [];

k = 1;
for buffer = 10000:10000:200000

    % 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(' Plossp10 =%g', Ploss);
    Plossp10(1,k) = buffer;
    Plossp10(2,k) = Ploss;

    % calcula por periodos
    Ploss = HML_PeriodLoss( T2, R, buffer, periodo, 100);
    fprintf(' Plossp100 =%g', Ploss);
    Plossp100(1,k) = buffer;
    Plossp100(2,k) = Ploss;

    % calcula por periodos
    Ploss = HML_PeriodLoss( T2, R, buffer, periodo, 1000);
    fprintf(' Plossp1000 =%g', Ploss);
    Plossp1000(1,k) = buffer;
    Plossp1000(2,k) = Ploss;
    
    % calcula por periodos
    Ploss = HML_PeriodLoss( T2, R, buffer, periodo, 10000);
    fprintf(' Plossp10000 =%g', Ploss);
    Plossp10000(1,k) = buffer;
    Plossp10000(2,k) = Ploss;

    k = k + 1;
    
end




clf
plot(Plosss(1,:),Plosss(2,:),'LineStyle','-','LineWidth',1,'Marker','none');
hold all;
plot(Plossh(1,:),Plossh(2,:),'LineStyle','--','LineWidth',1,'Marker','*');
hold all;
plot(Plossp10(1,:),Plossp10(2,:),'LineStyle',':','LineWidth',1,'Marker','.');
hold all;
plot(Plossp100(1,:),Plossp100(2,:),'LineStyle',':','LineWidth',1,'Marker','+');
hold all;
plot(Plossp1000(1,:),Plossp1000(2,:),'LineStyle',':','LineWidth',1,'Marker','diamond');
hold all;
plot(Plossp10000(1,:),Plossp10000(2,:),'LineStyle',':','LineWidth',1,'Marker','square');
legend('Simulation','HBsP method','10 samples','100 samples','1000 samples','10000 samples');
xlabel('buffer');
ylabel('cell loss ratio')
set(gca,'FontSize',22);

