Open Live Script

This example introduces constant false alarm rate (CFAR) detection and shows how to use CFARDetector and CFARDetector2D 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 maximizes the probability of detection but also keeps the probability of false alarm below a preset level.

There is 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 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 addresses 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, $$T$$, is given by

$$T=\alpha {P}_{n}$$

where $${P}_{n}$$ is the noise power estimate and $$\alpha $$ is a scaling factor called the threshold factor.

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

### Cell Averaging CFAR Detection

The 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]

$${P}_{n}=\frac{1}{N}\sum _{m=1}^{N}{x}_{m}$$

where $$N$$ is the number of training cells and $${x}_{m}$$ is the sample in each training cell. If $${x}_{m}$$ happens to be the output of a square law detector, then $${P}_{n}$$ represents the estimated noise power. In general, the number of leading and lagging training cells are the same. Guard cells are placed adjacent to the CUT, both leading and lagging it. The purpose of these guard cells is to avoid signal components from leaking into the training cell, which could adversely affect the noise estimate.

The following figure shows the relation among these cells for the 1-D case.

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

$$\alpha =N({P}_{fa}^{-1/N}-1)$$

where $${P}_{fa}$$ 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. For simplicity and without losing any generality, we still assume that the noise is white Gaussian. This enables the comparison between the CFAR and classical detection theory.

We can instantiate a CFAR detector using the following command:

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

In this detector we use 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.

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

The configured CFAR detector is shown below.

cfar

cfar = phased.CFARDetector with properties: Method: 'CA' NumGuardCells: 2 NumTrainingCells: 20 ThresholdFactor: 'Auto' ProbabilityFalseAlarm: 1.0000e-03 OutputFormat: 'CUT result' ThresholdOutputPort: false NoisePowerOutputPort: 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 ratioNtrials = 1e5;Ncells = 23;CUTIdx = 12;% Noise samples after a square law detectorrsamp = randn(rs,Ncells,Ntrials)+1i*randn(rs,Ncells,Ntrials); x = abs(sqrt(npower/2)*rsamp).^2;

To perform the detection, 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, all detections are false alarms because we are only passing in noise. The resulting false alarm rate can then be calculated based on the number of false alarms and the number of trials.

x_detected = cfar(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 ratioxn = 0;for m = 1:10 rsamp = randn(rs,Ncells,Ntrials)+1i*randn(rs,Ncells,Ntrials); xn = xn + abs(sqrt(npower/2)*rsamp).^2; % noncoherent integrationendx_detected = cfar(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. The same probability of detection can be achieved with our desired probability of false alarm at 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. We can configure the CFAR detector to use a custom threshold factor, as shown below.

`release(cfar);cfar.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. Using this threshold, we see that the resulting false alarm rate matches the expected value.

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

act_pfa = 9.6000e-04

### CFAR Detection Threshold

A CFAR detection occurs when the input signal level in a cell exceeds the threshold level. The threshold level for each cell depends on the threshold factor and the noise power in that derived from training cells. To maintain a constant false alarm rate, the detection threshold will increase or decrease in proportion to the noise power in the training cells. Configure the CFAR detector to output the threshold used for each detection using the `ThresholdOutputPort`

property. Use an automatic threshold factor and 200 training cells.

`release(cfar);cfar.ThresholdOutputPort = true;cfar.ThresholdFactor = 'Auto';cfar.NumTrainingCells = 200;`

Next, create a square-law input signal with increasing noise power.

rs = RandStream('mt19937ar','Seed',2010);Npoints = 1e4;rsamp = randn(rs,Npoints,1)+1i*randn(rs,Npoints,1);ramp = linspace(1,10,Npoints)';xRamp = abs(sqrt(npower*ramp./2).*rsamp).^2;

Compute detections and thresholds for all cells in the signal.

[x_detected,th] = cfar(xRamp,1:length(xRamp));

Next, compare the CFAR threshold to the input signal.

plot(1:length(xRamp),xRamp,1:length(xRamp),th,... find(x_detected),xRamp(x_detected),'o')legend('Signal','Threshold','Detections','Location','Northwest')xlabel('Time Index')ylabel('Level')

Here, the threshold increases with the noise power of the signal to maintain the constant false alarm rate. Detections occur where the signal level exceeds the threshold.

### 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 the Neyman-Pearson principle. Returning to the first example and assuming the true noise power is known, the theoretical threshold can be calculated as

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

The false alarm rate of this classical Neyman-Pearson detector 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 the noise power, classical detection theory also produces the desired false alarm rate. The false alarm rate achieved by the CFAR detector is similar.

release(cfar);cfar.ThresholdOutputPort = false;cfar.NumTrainingCells = 20;x_detected = cfar(x,CUTIdx);act_pfa = sum(x_detected)/Ntrials

act_pfa = 9.4000e-04

Next, assume that both detectors are deployed to the field and that the noise power is 1 dB more than expected. In this case, if we use the theoretical threshold, the resulting probability of false alarm is four times more than what we desire.

`npower = db2pow(-9); % Assume 9dB SNR ratiorsamp = 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.0041

On the contrary, the CFAR detector's performance is not affected.

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

act_pfa = 0.0011

Hence, the CFAR detector is robust to noise power uncertainty and better suited to field applications.

Finally, use a CFAR detection in the presence of 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 noiseact_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(cfar);cfar.ThresholdFactor = 'Custom';cfar.CustomThresholdFactor = 12.85;x_detected = cfar(x,CUTIdx);act_pfa = sum(x_detected)/Ntrials`

act_pfa = 0.0010

### CFAR Detection for Range-Doppler Images

In the previous sections, the noise estimate was computed from training cells leading and lagging the CUT in a single dimension. We can also perform CFAR detection on images. Cells correspond to pixels in the images, and guard cells and training cells are placed in bands around the CUT. The detection threshold is computed from cells in the rectangular training band around the CUT.

In the figure above, the guard band size is [2 2] and the training band size is [4 3]. The size indices refer to the number of cells on each side of the CUT in the row and columns dimensions, respectively. The guard band size can also be defined as 2, since the size is the same along row and column dimensions.

Next, create a two-dimensional CFAR detector. Use a probability of false alarm of 1e-5 and specify a guard band size of 5 cells and a training band size of 10 cells.

cfar2D = phased.CFARDetector2D('GuardBandSize',5,'TrainingBandSize',10,... 'ProbabilityFalseAlarm',1e-5);

Next, load and plot a range-doppler image. The image includes returns from two stationary targets and one target moving away from the radar.

[resp,rngGrid,dopGrid] = helperRangeDoppler;

Use CFAR to search the range-Doppler space for objects, and plot a map of the detections. Search from -10 to 10 kHz and from 1000 to 4000 m. First, define the cells under test for this region.

`[~,rangeIndx] = min(abs(rngGrid-[1000 4000]));[~,dopplerIndx] = min(abs(dopGrid-[-1e4 1e4]));[columnInds,rowInds] = meshgrid(dopplerIndx(1):dopplerIndx(2),... rangeIndx(1):rangeIndx(2));CUTIdx = [rowInds(:) columnInds(:)]';`

Compute a detection result for each cell under test. Each pixel in the search region is a cell in this example. Plot a map of the detection results for the range-Doppler image.

detections = cfar2D(resp,CUTIdx);helperDetectionsMap(resp,rngGrid,dopGrid,rangeIndx,dopplerIndx,detections)

The three objects are detected. A data cube of range-Doppler images over time can likewise be provided as the input signal to `cfar2D`

, and detections will be calculated in a single step.

### Summary

In this example, we presented the basic concepts behind CFAR detectors. In particular, we explored how to use the Phased Array System Toolbox to perform cell averaging CFAR detection on signals and range-Doppler images. 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

## FAQs

### How to calculate false alarm rate in Matlab? ›

**T_ideal = npower*db2pow(npwgnthresh(exp_pfa));** The false alarm rate of this classical Neyman-Pearson detector can be calculated using this theoretical threshold. Because we know the noise power, classical detection theory also produces the desired false alarm rate.

**What is constant false alarm rate method? ›**

The constant-false-alarm-rate (CFAR) detection algorithm is **used for the detection of an optical target in an image dominated by optical clutter**. The algorithm can he used for many aerial images when a clutter-subtraction technique is incorporated.

**How is CFAR calculated? ›**

The CFAR ratio is calculated using the equation, **X = - log 10 ( PFA )/ NRC** .

**What are the different types of CFAR detectors? ›**

**Radar Basics**

- Cell Averaging CFAR.
- CAGO-CFAR.
- CASO-CFAR.
- CAOS-CFAR oder OS-CFAR.
- CASH-CFAR.
- MAMIS-CFAR.

**What is the CA CFAR algorithm? ›**

An important CFAR algorithm is the cell averaging (CA) CFAR, in which **the mean background level is estimated by averaging the signal level in M neighboring range cells**. The adaptive threshold is set by multiplying the mean background level by a coefficient α.

**What is the Z score in signal detection? ›**

In SDT, a z-score **measures performance in terms of the number of standard deviations that the signal distribution is above the noise distribution**, and a p-value represents the probability of observing a score greater than the observed score if we were sampling from the noise distribution.

**What is a CFAR detector? ›**

Constant false alarm rate (CFAR) detection refers to **a common form of adaptive algorithm used in radar systems to detect target returns against a background of noise, clutter and interference**.

**What is the constant detection rate? ›**

On the other hand, if it is required to guarantee a non-interference probability to the primary users, the probability of detection should be set to a high level (e.g., 95%) and the probability of false alarm should be minimized as much as possible. This is called the constant detection rate (CDR) principle [13,19].

**What is the objective of CFAR? ›**

As a public interest research and advocacy group, CFAR **helps create spaces in the community, in the key institutions and in the media for a dialogue on issues related to social development**.

**How do you find the probability of a false alarm? ›**

The probability of detection is P_{d} and the probability of false alarm is **P _{fa}**. The terms p

_{0}, P

_{fa}and p

_{d}

_{0}, P

_{d}, are related by a binomial function: (8.2) P f a = Σ i = M i = N C N i p 0 i ( 1 − p 0 ) N − i ≈ C N M p 0 M , P d = Σ i = M i = N C N i p d 0 i ( 1 − p d 0 ) N − i .

### What is the difference between hit rate and false alarm rate? ›

The hit rate is the total number of hits (200) divided by the total number of genuinely old items (1000), and the false alarm rate is the total number of false alarms (25) divided by the total number of genuinely new items (1000). This gives us a “hit rate” of 200/1000 = . 20, and a “false alarm rate” of 25/1000 = .

**How do you calculate hit rate and false alarm rate in Excel? ›**

The formula for d prime is **d' = z(H) - z(F)** , where z(H) and z(F) are the z transforms of hit rate and false alarm, respectively. To calculate the z transform, I use the Excel function NORMSINV (i.e., z(H)=NORMSINV(hit rate) ).

**What is the probability of false alarm in radar? ›**

A typical radar system will operate with a detection probability of 0.9 and a probability of false alarm of **10-6**.

**How do you calculate Dprime? ›**

The formula for d prime is **d' = z(H) - z(F)** , where z(H) and z(F) are the z transforms of hit rate and false alarm, respectively.

**What is PFA in Matlab? ›**

pfa — **Probability of false alarm**

Probability of false alarm, specified as a scalar in the range (0, 1) .

**How do you calculate D signal detection? ›**

Calculate d' for this subject using the formula: **d' = z(FA) – z(H)**.

**What is a good D prime score? ›**

It is essentially a standardized score and is computed as the difference between the (Gaussian) standard scores for the false-alarm rate and the hit rate. **A value of d′ = 3** is close to perfect performance; a value of d′ = 0 is chance (“guessing”) performance.