Understand a part of code Detection CFAR

2 views (last 30 days)
Rémy RODRIGUES on 24 May 2022
Answered: Walter Roberson on 24 May 2022
Hello everyone , i'm a beginner in matlab i need for a exam to understand a port of code ( the project its the detection CFAR )
i hope somoene can help me its very important for me <3
The following code is this part for generating a PFA :
I juste need to understand what do the " case " in the code
%=============================================== ================================================ =%
%======== Function that generates a PFA from a threshold T2Pfa = Gpfa ======%
%=============================================== ================================================ =%
% From a given threshold, a corresponding pfa is generated
% T: threshold factor
% window: size of the observation window for the pfa estimation
% technical: method used to estimate the pfa of the signal
% Pfa: Probability of false alarm
function Pfa = Gpfa(T, window, technique)
% The following is used to ensure minimization
T(T <= 0) = realmin; %the smallest double-precision positive normalized floating-point number. This is equal to 2^(-1022)
n = window/2; % half window size
if ( n ~= round(window/2) ) % round(X) rounds each element of X to the nearest integer
error('Window size must be an even number in CFAR')
% To process arrays of T, the following is used
orig_size = size(T); %size(A) returns a row vector whose elements are the lengths of the corresponding dimensions of T
T = T(:).'; % vector processing for internal sums to work, x(:) is exactly equivalent to reshape(x, [], 1)
switch upper(technical)
case 'AC'
% Except modified T
Pfa = (1 + T).^(-window);
case 'CAGO'
% Note use of n = window/2;
isum = repmat([0:n-1].',1,length(T)); %repmat(A,n) returns an array containing n copies of A in row and column dimensions. The size of B is size(A)*n when A is a matrix
Tvec = repmat(T,n,1); %L = length(X) returns the length of the largest dimension of the array in X. For vectors, the length is simply the number of elements
Pfa = 2 * (1 + T).^(-n) - 2 .* sum(bin(n + isum - 1, isum) .* (2 + Tvec).^ (-(n + isum)));
case 'CASO'
% Simplified Note use of n = window/2;
isum = repmat([0:n-1].',1,length(T));
Tvec = repmat(T,n,1);
Pfa = 2 .* sum(bin(n + isum - 1, isum) .* (2 + Tvec).^ (-(n + isum)));
Pfa = reshape(Pfa,orig_size); %removes the effect of T(:).';
function val = bin(top, bot)
% internal binomial function
val = exp( gammaln(top + 1) - gammaln(bot + 1) - gammaln(top - bot + 1) );

Answers (1)

Walter Roberson
Walter Roberson on 24 May 2022
switch upper(technical)
case 'AC'
is like
if isequal(upper(technical), 'AC')
and the next case would be "elseif isequal..."
That is, the user is expected to pass in a character vector that is one of the three possibilities, in whatever case they want, and the code executes the appropriate section.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by