www.gusucode.com > phased 案例源码 matlab代码程序 > phased/CFARDetectorAdaptationToNoisyInputDataExample.m
%% CFAR Detector Adaptation to Noisy Input Data % This example shows how to create a CFAR detector and test its ability to % adapt to the statistics of input data. The test uses noise-only trials. % By using the default square-law detector, you can determine how close the % empirical false-alarm rate is to the desired false-alarm probability. %% % *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 object with two guard cells, 20 training cells, % and a false-alarm probability of 0.001. By default, this object assumes a % square-law detector with no pulse integration. detector = phased.CFARDetector('NumGuardCells',2,... 'NumTrainingCells',20,'ProbabilityFalseAlarm',1e-3); %% % There are 10 training cells and 1 guard cell on each side of the _cell % under test_ (CUT). Set the CUT index to 12. CUTidx = 12; %% % Seed the random number generator for a reproducible set of input data. rng(1000); %% % Set the noise variance to 0.25. This value corresponds to an approximate % -6 dB SNR. Generate a 23-by-10000 matrix of complex-valued, white % Gaussian rv's with the specified variance. Each row of the matrix % represents 10,000 Monte Carlo trials for a single cell. Ntrials = 1e4; variance = 0.25; Ncells = 23; inputdata = sqrt(variance/2)*(randn(Ncells,Ntrials)+1j*randn(Ncells,Ntrials)); %% % Because the example implements a square-law detector, take the squared % magnitudes of the elements in the data matrix. Z = abs(inputdata).^2; %% % Provide the output from the square-law operator and the index of the cell % under test to the CFAR detector. Z_detect = detector(Z,CUTidx); %% % The output, |Z_detect|, is a logical vector with 10,000 elements. Sum % the elements in |Z_detect| and divide by the total number of trials to % obtain the empirical false-alarm rate. pfa = sum(Z_detect)/Ntrials %% % The empirical false-alarm rate is 0.0013, which corresponds closely to % the desired false-alarm rate of 0.001.