www.gusucode.com > phased 案例源码 matlab代码程序 > phased/DetectionProbabilityForCFARDetectorExample.m

    %% Detection Probability for CFAR Detector
% This example shows how to compare the probability of detection resulting
% from two CFAR algorithms. In this scenario, the order statistic algorithm
% detects a target that the cell-averaging algorithm does not.
%%
% *Note:* This example runs only in R2016b or later. If you are using an earlier
% release, replace each call to the function with the equivalent |step|
% syntax. For example, replace |myObject(x)| with |step(myObject,x)|.
%%
% Create a CFAR detector that uses the cell-averaging CFAR algorithm.
Ntraining = 10;
Nguard = 2;
Pfa_goal = 0.01;
detector = phased.CFARDetector('Method','CA',...
    'NumTrainingCells',Ntraining,'NumGuardCells',Nguard,...
    'ProbabilityFalseAlarm',Pfa_goal);
%%
% The detector has 2 guard cells, 10 training cells, and a false-alarm
% probability of 0.01. This object assumes a square-law detector with no
% pulse integration.
%%
% Generate a vector of input data based on a complex-valued white Gaussian
% random variable.
Ncells = 23;
Ntrials = 100000;
inputdata = 1/sqrt(2)*(randn(Ncells,Ntrials) + ...
    1i*randn(Ncells,Ntrials));
%%
% In the input data, replace rows 8 and 12 to simulate two targets for the
% CFAR detector to detect.
inputdata(8,:) = 3*exp(1i*2*pi*rand);
inputdata(12,:) = 9*exp(1i*2*pi*rand);

%%
% Because the example implements a square-law detector, take the squared
% magnitudes of the elements in the input data vector.
Z = abs(inputdata).^2;
%%
% Perform the detection on rows 8 through 12.
Z_detect = detector(Z,8:12);
%%
% The |Z_detect| matrix has five rows. The first and last
% rows correspond to the simulated targets. The three middle rows
% correspond to noise.

%%
% Compute the probability of detection of the two targets. Also, estimate
% the probability of false alarm using the noise-only rows.
Pd_1 = sum(Z_detect(1,:))/Ntrials
Pd_2 = sum(Z_detect(end,:))/Ntrials
Pfa = max(sum(Z_detect(2:end-1,:),2)/Ntrials)

%%
% The |0| value of |Pd_1| indicates that
% this detector does not detect the first target.
%%
% Change the CFAR detector so it uses the order statistic CFAR algorithm
% with a rank of 5.
release(detector);
detector.Method = 'OS';
detector.Rank = 5;
%%
% Repeat the detection and probability computations.
Z_detect = detector(Z,8:12);
Pd_1 = sum(Z_detect(1,:))/Ntrials
Pd_2 = sum(Z_detect(end,:))/Ntrials
Pfa = max(sum(Z_detect(2:end-1,:),2)/Ntrials)
%%
% Using the order statistic algorithm instead of the cell-averaging
% algorithm, the detector detects the first target in about 58% of the
% trials.