function [x, Fe, l, ber] = ARQ_error(fileName)
%Parse AQR log file
%    x: Number of re-transmissions vector
%   Fe: Frequency of transmissions vector, where index implies Nbr of
%       transmission
%    l: Average tries per package
%  ber: Bit error rate
%
% author:
%   Christos Choutouridis AEM:8997
%   cchoutou@ece.auth.gr

    pkg_size = 128;
    
    x = [0 1 2 3 4 5 6 7 8 9]';
    Fe = zeros (10, 1);
    data = fopen (fileName);
    A = textscan(data,'%s','Delimiter','\n');
    B = A{1,1};
    fclose(data);
    s = size (B);

    j =1;
    for i = 2:s(1)
        C = textscan(B{i,1},'%s','Delimiter',' ');
        D = C{1};
        e = str2num(D{10});
        E(j) = e;
        j = j+1;
    end
    
    s = size (E);
    for i = 2:s(2)
        if (E(i) == 0) 
            if (E(i-1) == 0)
                Fe(1) = Fe(1) +1;
            else
                if (E(i-1) <= 9)
                    Fe(E(i-1)+1) = Fe(E(i-1)+1) +1;
                end
            end
        end
    end
    
    l =0;
    for i=1:10
        l = l + Fe(i)*i;
    end
    l = l / sum(Fe);
    
    ber = 1 - (1/l)^(1/pkg_size);
end

