This example introduces the basic idea behind constant false alarm rate (CFAR) detection and shows how to use the CFARDetector class in the Phased Array System Toolbox™ to perform cell averaging CFAR detection.

**Introduction**

One important task a radar system performs is target detection. The detection itself is fairly straightforward. It compares the signal to a threshold. Therefore, the real work on detection is coming up with an appropriate threshold.

In general, the threshold is a function of both the probability of detection and the probability of false alarm. In many phased array systems, because of the cost associated with a false detection, it is desirable to have a detection threshold that not only maximize the probability of detection but also keep the probability of false alarm below a preset level.

There is an extensive literature on how to determine the detection threshold. Readers might be interested in the Signal Detection in White Gaussian Noise and Signal Detection Using Multiple Samples examples for some well known results. However, all these classical results are based on theoretical probabilities and they are limited to white Gaussian noise with known variance (power). In real applications, the noise is often colored and its power is unknown.

CFAR technology is developed to address these issues. In CFAR, when the detection is needed for a given cell, often termed as the cell under test (CUT), the noise power is estimated from neighboring cells. Then the detection threshold, , is given by

where is the noise estimate and is a scaling factor called the threshold factor.

From the equation, it is clear that the threshold is now adaptive to the data. It can be shown that with the appropriate threshold factor, , the resulting probability of false alarm can be kept at a constant, hence the name CFAR.

**Cell Averaging CFAR Detection**

Cell averaging CFAR detector is probably the most widely used CFAR detector. It is also used as a baseline comparison for other CFAR techniques. In a cell averaging CFAR detector, noise samples are extracted from both leading and lagging cells (called training cells) around the CUT. The noise estimate can be computed as [1]

where is the number of training cells and is the sample in each training cell. If happens to be the output of a square law detector, then represents the estimated noise power. In general, the number of leading and lagging training cells are the same. There are also guard cells, both leading and lagging the CUT, present in the CFAR detector. The purpose of these guard cells is to avoid having leaked signal component in the training cell, which could adversely affect the noise estimate.

The following figure shows the relation among these cells.

With the above cell averaging CFAR detector, assuming the data fed into the detector is from a single pulse, i.e., no pulse integration involved, the threshold factor can be written as [1]

where is the desired false alarm rate.

**CFAR Detection Using Automatic Threshold Factor**

In the rest of this example, we show how to use Phased Array System Toolbox to perform a cell averaging CFAR detection. To keep things simple, without losing any generality, we still assume that the noise is white Gaussian. It also enables the comparison between the CFAR and classical detection theory.

We can instantiate a CFAR detector using the following command

hdetector = phased.CFARDetector('NumTrainingCells',20,'NumGuardCells',2);

In this detector we are using 20 training cells and 2 guard cells in total. This means that there are 10 training cells and 1 guard cell on each side of the CUT. As mentioned above, if we assume that the signal is from a square law detector with no pulse integration, the threshold can be calculated based on the number of training cells and the desired probability of false alarm. Assuming the desired false alarm rate is 0.001, we can configure the CFAR detector as follows so that this calculation can be carried out for us.

```
exp_pfa = 1e-3;
hdetector.ThresholdFactor = 'Auto';
hdetector.ProbabilityFalseAlarm = exp_pfa;
```

The configured CFAR detector is shown below.

hdetector

hdetector = System: phased.CFARDetector Properties: Method: 'CA' NumGuardCells: 2 NumTrainingCells: 20 ThresholdFactor: 'Auto' ProbabilityFalseAlarm: 0.001 ThresholdOutputPort: false

We now simulate the input data. Since the focus is to show that the CFAR detector can keep the false alarm rate under a certain value, we just simulate the noise samples in those cells. Here are the settings:

The data sequence is 23 samples long, and the CUT is cell 12. This leaves 10 training cells and 1 guard cell on each side of the CUT.

The false alarm rate is calculated using 100 thousand Monte Carlo trials

rs = RandStream('mt19937ar','Seed',2010); npower = db2pow(-10); % Assume 10dB SNR ratio Ntrials = 1e5; Ncells = 23; CUTIdx = 12; % Noise samples after a square law detector rsamp = randn(rs,Ncells,Ntrials)+1i*randn(rs,Ncells,Ntrials); x = abs(sqrt(npower/2)*rsamp).^2;

To perform the detection, we simply pass the data through the detector. In this example, there is only one CUT, so the output is a logical vector containing the detection result for all the trials. If the result is true, it means that a target is present in the corresponding trial. In our example, these are false alarms because we are only passing in the noise. The resulting false alarm rate can then be calculated based on the number of false alarms and the number of trials.

x_detected = step(hdetector,x,CUTIdx); act_pfa = sum(x_detected)/Ntrials

act_pfa = 9.4000e-04

The result shows that the resulting probability of false alarm is below 0.001, just as we specified.

**CFAR Detection Using Custom Threshold Factor**

As explained in the earlier part of this example, there are only a few cases in which the CFAR detector can automatically compute the appropriate threshold factor. For example, using the previous scenario, if we employ a 10-pulses noncoherent integration before the data goes into the detector, the automatic threshold can no longer provide the desired false alarm rate.

npower = db2pow(-10); % Assume 10dB SNR ratio xn = 0; for m = 1:10 rsamp = randn(rs,Ncells,Ntrials)+1i*randn(rs,Ncells,Ntrials); xn = xn + abs(sqrt(npower/2)*rsamp).^2; % noncoherent integration end x_detected = step(hdetector,xn,CUTIdx); act_pfa = sum(x_detected)/Ntrials

act_pfa = 0

One may be puzzled why we think a resulting false alarm rate of 0 is worse than a false alarm rate of 0.001. After all, isn't a false alarm rate of 0 a great thing? The answer to this question lies in the fact that when the probability of false alarm is decreased, so is the probability of detection. In this case, because the true false alarm rate is far below the allowed value, the detection threshold is set too high. Hence, the same probability of detection can be achieved with lower cost; for example, with lower transmitter power.

In most cases, the threshold factor needs to be estimated based on the specific environment and system configuration. To use these proprietary threshold factors, we can configure the CFAR detector to use a custom threshold factor, as shown below.

```
release(hdetector);
hdetector.ThresholdFactor = 'Custom';
```

Continuing with the pulse integration example and using empirical data, we found that we can use a custom threshold factor of 2.35 to achieve the desired false alarm rate. Putting this threshold factor into action, we see that the resulting false alarm rate matches our expectation.

hdetector.CustomThresholdFactor = 2.35; x_detected = step(hdetector,xn,CUTIdx); act_pfa = sum(x_detected)/Ntrials

act_pfa = 9.6000e-04

**Comparison Between CFAR and Classical Neyman-Pearson Detector**

In this section, we compare the performance of a CFAR detector with the classical detection theory using Neyman-Pearson principle. Using the example above, assuming the true noise power is known, the theoretical threshold can be calculated as

T_ideal = npower*db2pow(npwgnthresh(exp_pfa));

The false alarm of this classical Neyman-Pearson detector rate can be calculated using this theoretical threshold.

act_Pfa_np = sum(x(CUTIdx,:)>T_ideal)/Ntrials

act_Pfa_np = 9.5000e-04

Because we know what the noise power is, classical detection theory also offers good detection performance. The false alarm rate achieved by the CFAR detector is similar.

```
release(hdetector);
hdetector.ThresholdFactor = 'Auto';
x_detected = step(hdetector,x,CUTIdx);
act_pfa = sum(x_detected)/Ntrials
```

act_pfa = 9.4000e-04

Next, assume that both detectors are deployed to the field and for some reason, the noise power is 1 dB more than what we thought it is. In this case, if we still use the detector based on the theoretical threshold, the resulting probability of false alarm becomes

```
npower = db2pow(-9); % Assume 9dB SNR ratio
rsamp = randn(rs,Ncells,Ntrials)+1i*randn(rs,Ncells,Ntrials);
x = abs(sqrt(npower/2)*rsamp).^2;
act_Pfa_np = sum(x(CUTIdx,:)>T_ideal)/Ntrials
```

act_Pfa_np = 0.0043

Note that this is four times more than what we desire. On the contrary, the CFAR detector's performance is not affected.

x_detected = step(hdetector,x,CUTIdx); act_pfa = sum(x_detected)/Ntrials

act_pfa = 9.8000e-04

Hence, the CFAR detector offers much better performance in real field applications.

Finally, we conduct a CFAR detection against colored noise. We first apply the classical detection threshold to the data,

npower = db2pow(-10); fcoeff = maxflat(10,'sym',0.2); x = abs(sqrt(npower/2)*filter(fcoeff,1,rsamp)).^2; % colored noise act_Pfa_np = sum(x(CUTIdx,:)>T_ideal)/Ntrials

act_Pfa_np = 0

Note that the resulting false alarm rate cannot meet the requirement. However, using the CFAR detector with a custom threshold factor, we can obtain the desired false alarm rate.

```
release(hdetector);
hdetector.ThresholdFactor = 'Custom';
hdetector.CustomThresholdFactor = 12.85;
x_detected = step(hdetector,x,CUTIdx);
act_pfa = sum(x_detected)/Ntrials
```

act_pfa = 9.0000e-04

**Summary**

In this example, we presented the basic idea behind CFAR detectors. In particular, we explored how to use the Phased Array System Toolbox to perform cell averaging CFAR detection. The comparison between the performance offered by a cell averaging CFAR detector and a detector equipped with the theoretically calculated threshold shows clearly that the CFAR detector is more suitable for real field applications.

**Reference**

[1] Mark Richards, *Fundamentals of Radar Signal Processing*, McGraw Hill, 2005

Was this topic helpful?