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

    %% Detect Targets in Background Noise
% Perform cell-averaging CFAR detection on a 41-by-41 matrix of cells
% containing five closely-spaced targets in Gaussian noise. Perform this detection on a
% simulation of 1000 images. Use two detectors with different guard band
% regions. Set the thresholds manually using the |Custom| threshold factor.
% Assume that the data is processed throught a square law-detector and that
% no pulse integration is performed. Use a training cell band of 2 cells in
% width and 2 cells in height. For the first detector, use a guard band of 1 cell
% all around to separate the CUT cells from the training cells. For the
% second detector, use a guard band of 8 cells all around.
%%
% *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)|.
p = 5e-4;
rs = RandStream.create('mt19937ar','Seed',5);
N = 41;
ntrials = 1000;

%%
% Create 1000 41-by-41 images of complex random noise with standard deviation of 1.
s = 1;
x = s/sqrt(2)*(randn(rs,N,N,ntrials) + 1i*randn(rs,N,N,ntrials));
%%
% Set the target cells values to 1.5. Then, square the cell values.
A = 1.5;
x(23,20,:) = A;
x(23,18,:) = A;
x(23,23,:) = A;
x(20,22,:) = A;
x(21,18,:) = A;
x2 = abs(x).^2;

%%
% Display the target cells.
xtgt = zeros(N,N);
xtgt(23,20,:) = A;
xtgt(23,18,:) = A;
xtgt(23,23,:) = A;
xtgt(20,22,:) = A;
xtgt(21,18,:) = A;
imagesc(xtgt)
axis equal
axis tight
%%
% Set the CUT cells to be the target cells. 
cutidx(1,1) = 23;
cutidx(2,1) = 20;
cutidx(1,2) = 23;
cutidx(2,2) = 18;
cutidx(1,3) = 23;
cutidx(2,3) = 23;
cutidx(1,4) = 20;
cutidx(2,4) = 22;
cutidx(1,5) = 21;
cutidx(2,5) = 18;

%%
% Perform the detection on all CUT cells using two CFAR 2-D detectors. The
% first detector has a small guard band region. The training region can
% include neighboring targets which can affect the computation of the noise
% power. The second detector has a larger guard band region, which precludes
% target cells from being used in the noise computation.
%%
% Create the two CFAR detectors.
detector1 = phased.CFARDetector2D('TrainingBandSize',[2,2], ...
    'GuardBandSize',[1,1],'ThresholdFactor','Custom','Method','CA', ...
    'CustomThresholdFactor',2,'ThresholdOutputPort',true);
detector2 = phased.CFARDetector2D('TrainingBandSize',[2,2], ...
    'GuardBandSize',[8,8],'ThresholdFactor','Custom','Method','CA', ...
    'CustomThresholdFactor',2,'ThresholdOutputPort',true);
%%
% Return the detection classifications and the thresholds used to classify
% the cells. Then, compute the probabilities of detection.
[dets1,th1] = detector1(x2,cutidx);
ndets = numel(dets1(:));
pd1 = sum(dets1(:))/ndets
[dets2,th2] = detector2(x2,cutidx);
pd2 = sum(dets2(:))/ndets
%%
% The detector with the larger guard-band region has a higher pfa because
% the noise is more accurately estimated.