function Pd = pdNonfluctuatingNoncoherent(Pfa, SNR, N)
%This function is for internal use only. It may be removed in the future.

%   Copyright 2020 The MathWorks, Inc.

%#codegen

SNRlen = numel(SNR);
Pd = zeros(numel(Pfa), SNRlen);  % preallocate
T = real(gammaincinv(1 - Pfa, N));
T = T(:);
N = round(N);
r = 1:N - 1;
rr = repmat(r, numel(Pfa), 1);

for k = 1:SNRlen
    NX = N * SNR(k);
    Pd(:, k) = marcumq(sqrt(2 * NX), sqrt(2 * T));
    SQRTNXT2 = 2 * sqrt(NX * T);
    if SNR(k) ~= 0 && SNR(k) ~= inf && numel(r) > 0
        A = bsxfun(@minus, log(T / NX) * r/2, ((T + NX) - SQRTNXT2));
        Pdtemp = exp(A) .* real(besseli(rr, repmat(SQRTNXT2, 1, N - 1), 1));
        Pdtemp(~isfinite(Pdtemp)) = 0;
        Pd(:, k) = Pd(:, k) + sum(Pdtemp, 2);
    end
end

Pd(Pd > 1) = 1;
