
%Plot the probability of false alarm
%   hPlotFalseAlarmProbability(RUNNINGP,RUNNINGDETECTED)
%   RUNNINGP is an array of probabilities of false alarm.
%   RUNNINGDETECTED is an array of structures, each element contains two
%   fields: Detected (preamble index found during the search) and Offset
%   (offset in number of samples where the preamble was detected).
%   Both arrays must have the same length.

%   Copyright 2020 The MathWorks, Inc.

function hPlotFalseAlarmProbability(runningP,runningDetected)
    numTrials = length(runningP);
    
    for nt = 1:numTrials
        detected = runningDetected(nt).Detected;
        if (~isempty(detected))
            offset = runningDetected(nt).Offset;
            plot(nt,runningP(nt),'ro','LineWidth',2,'MarkerSize',7);
            hold on;
            text(nt,runningP(nt), sprintf(['Preamble index = %d' ...
                '  \nTiming offset = %0.2f samples  '],detected,offset), ...
                'HorizontalAlignment','right');
        end
    end

    plot(1:numTrials,runningP,'b','LineWidth',2);
    axis([0 numTrials+1 -0.1 0.2]);
    xlabel('Trials');
    ylabel('Running false alarm probability (%)');
    title('PRACH False Alarm Detection Probability');
end