# phased.LRTDetector

## Description

The likelihood ratio test (LRT) detector performs binary signal detection in the presence
of noise. The binary detector chooses between the null hypothesis
*H*_{0 } and the alternative hypothesis
*H*_{1} based on data measurements. The null hypothesis
denotes the absence of any signal while the alternative hypothesis denotes the presence of
some signal.

## Creation

### Description

creates a
likelihood ratio test `detector`

= phased.LRTDetector`detector`

System object™ with default properties.

creates a likelihood ratio test `detector`

= phased.LRTDetector(`Name`

= `Value`

)`detector`

System object with the specified property `Name`

set to the specified
`Value`

. You can specify additional name-value pair arguments in any
order as (`Name1`

= `Value1`

, …
,`NameN`

= `ValueN`

).

## Properties

Unless otherwise indicated, properties are *nontunable*, which means you cannot change their
values after calling the object. Objects lock when you call them, and the
`release`

function unlocks them.

If a property is *tunable*, you can change its value at
any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

`DataComplexity`

— Data complexity

`'Complex'`

(default) | `'Real'`

Data complexity, specified as `'Complex'`

or `'Real'`

.
Complexity defines the format used to report output data. When
`DataComplexity`

is `'Complex'`

, data is
complex-valued. When `DataComplexity`

is `'Real'`

,
data is real-valued.

**Example: ** `'Real'`

**Data Types: **`char`

| `string`

`ProbabilityFalseAlarm`

— Probability of false alarm

`1e-1`

(default) | nonnegative scalar

Probability of false alarm, specified as a positive scalar between 0 and 1, inclusive.

**Example: **`1e-6`

**Data Types: **`single`

| `double`

`ThresholdOutputPort`

— Output detection statistics and threshold

`false`

(default) | `true`

Output detection statistics and detection threshold, specified as `false`

or `true`

. Set this property to `true`

to output the detection statistics in the `stat`

argument and the detection threshold in the `th`

argument. Set this property to `false`

to suppress the output of detection statistics and threshold.

**Data Types: **`logical`

`OutputFormat`

— Format of output data

`'Detection result'`

(default) | `'Detection index'`

Format of output data, specified as `'Detection result'`

or `'Detection index'`

. Output data is returned in the `Y`

argument.

**Example: **`'Detection index'`

**Data Types: **`char`

| `string`

## Usage

### Description

### Input Arguments

`X`

— Input data

real-valued *N*-by-*1* vector | complex-valued *N*-by-*1* vector | real-valued *N*-by-*M* matrix | complex-valued *N*-by-*M* matrix

Input data, specified as a real-valued or complex-valued
*N*-by-*1* vector, or an
*N*-by-*M* real-valued or complex-valued matrix.
*N* is the signal length and *M* is the number of
data channels. Each data channel has *N* samples to yield an
*N*-by-*M* matrix. Each row represents the
components of a length-*M* data vector. When *M =
1*, `X`

represents a single channel of data. When
*M > 1*, `X`

can represent *N*
samples from *M* data channels. The detector processes input data
along the columns of `X`

. The size of each row *M*
cannot change during the simulation.

The LRT detector assumes the same signal model in each column of
`X`

. `Xknown`

contains the
*N*-dimensional noise-free signal. `ncov`

defines the power of additive Gaussian noise added to each column. For this signal
model, the LRT detector determines whether or not to reject the null hypothesis
`Xknown`

` = 0`

. Because there is only one known
signal model, the LRT detector outputs one detection result for each column of
`X`

.

**Data Types: **`single`

| `double`

**Complex Number Support: **Yes

`Xknown`

— Known noise-free signal

real-valued *N*-by-1 vector | complex-valued *N*-by-1 vector

Known noise-free signal, specified as a real-valued or complex-valued
*N*-by-1 vector.

**Data Types: **`single`

| `double`

**Complex Number Support: **Yes

`ncov`

— Noise power or covariance

positive scalar

Noise power or covariance, specified as a positive scalar.

**Example: **`2.0`

**Data Types: **`single`

| `double`

### Output Arguments

`Y`

— Detection results

1-by-*M* logical-valued vector | 1-by-*L* integer-valued vector

Detection results, returned as a 1-by-*M* logical-valued vector
or a 1-by-*L* integer-valued vector. The format of
`Y`

depends on the value of the `OutputFormat`

property. By default, the `OutputFormat`

property is set to
`'Detection result'`

.

When the

`OutputFormat`

property is set to`'Detection result'`

,`Y`

is a 1-by-*M*vector containing logical detection results, where*M*is the number of columns of`X`

.`Y`

is`true`

if there is a detection in the corresponding column of`X`

. Otherwise,`Y`

is`false`

.When the

`OutputFormat`

property is set to`'Detection index'`

,`Y`

is a 1-by-*L*integer-valued vector containing detection indices, where*L*is the number of detections found over all*M*channels.

**Data Types: **`single`

| `double`

| `logical`

**Complex Number Support: **Yes

`stat`

— Detection statistics

*1*-by-*M* vector (default) | 1-by-*L* vector

Detection statistics, returned as a *1*-by-*M*
vector or 1-by-*L* vector. *M* is the number of
columns of `X`

. The format of `stat`

depends on
the setting of the `OutputFormat`

property.

When

`OutputFormat`

is`'Detection result'`

,`stat`

has the same size as`Y`

.When

`OutputFormat`

is`'Detection index'`

,`stat`

is a 1-by-*L*vector containing detection statistics for each corresponding detection in*Y*.

#### Dependencies

To enable this argument, set the `ThresholdOutputPort`

property to `true`

.

**Data Types: **`single`

| `double`

`th`

— Detection threshold

scalar

Detection threshold, returned as a scalar.

#### Dependencies

To enable this argument, set the `ThresholdOutputPort`

property to `true`

.

**Data Types: **`single`

| `double`

## Object Functions

To use an object function, specify the
System object as the first input argument. For
example, to release system resources of a System object named `obj`

, use
this syntax:

release(obj)

## Examples

### Likelihood Ratio Test on Complex Data

Perform likelihood ratio test detection on 10 signals in complex Gaussian noise. The input is a known signal vector of ones. The noise covariance is unity. Set the desired probability of false alarm to 0.1. Perform the detection on all samples of the input. Show that the probability of false alarm is close to the desired level.

rng default lrt = phased.LRTDetector('DataComplexity','Complex', ... 'ProbabilityFalseAlarm',0.1); N = 10; M = 1000; x = 1/sqrt(2)*(randn(N,M) + 1i*randn(N,M)); xknown = 100*ones(N,1); noisecov = 1; dresult = lrt(x,xknown,noisecov); Pfa = sum(dresult)/M

Pfa = 0.1060

**Likelihood Ratio Test on Real Data**

Perform likelihood ratio test detection on 10 signals in real Gaussian noise. The input known signal is a vector of ones. Set the noise covariance to 1 and set the desired probability of false alarm to 0.1. Perform the detection on all samples of the input. Show that the probability of false alarm is close to the desired level.

rng default lrt = phased.LRTDetector(DataComplexity = 'Real', ... ProbabilityFalseAlarm = 0.1,ThresholdOutputPort = true); N = 10; M = 1000; x = randn(N,M); xknown = 100*ones(N,1); noisecov = 1; [dresult,stat,th] = lrt(x,xknown,noisecov);

Display the proobability of false alarm, the first 10 values of *stat*, and the threshold *th*.

Pfa = sum(dresult)/M

Pfa = 0.1060

stat(1:10)

`ans = `*1×10*
1.9742 2.2291 1.0325 -1.3958 0.6511 -0.3462 0.4053 -0.8368 0.9581 -0.7792

th

th = 1.2816

### False Alarm Rate for Real-Valued Signal in White Gaussian Noise

This example shows how to empirically compute the probability of false alarm for real-valued data in white Gaussian noise.

Determine the required signal-to-noise ratio (SNR) in decibels for the NP detector (also known as the LRT detector) when the maximum tolerable false-alarm probability is $${10}^{-3}$$.

% Probability of false alarm pfa = 1e-3; % SNR threshold in dB snrThdB = npwgnthresh(pfa,1,'real'); % SNR threshold snrThNP = sqrt(db2pow(snrThdB));

Assume the variance is 2 and generate 1 million samples of real Gaussian noise under the null hypothesis.

rng default % Noise variance variance = 2; % Number of independent samples M = 1e6; % Data under null hypothesis x = sqrt(variance) * randn(1,M);

Verify empirically that the detection threshold results in the desired false-alarm rate under the null hypothesis. This can be verified by determining the proportion of normalized samples that exceed the required SNR threshold.

```
% Empirical false-alarm rate
falseAlarmRateNP = sum(x/sqrt(variance) > snrThNP)/M
```

falseAlarmRateNP = 9.9500e-04

Alternatively, use `phased.LRTDetector`

to empirically calculate the detection result and false alarm rate. The LRT detector requires inputting the noise-free signal under the alternative hypothesis. As we test the null hypothesis, the amplitude of the noise-free signal under the alternative hypothesis is irrelevant to the testing and can be set to any real value. Set the noise-free signal under the alternative hypothesis to be 10.

% Configure the LRT detector lrt = phased.LRTDetector('DataComplexity','Real',... 'ProbabilityFalseAlarm',pfa,'ThresholdOutputPort',true); % Known noise-free signal under the alternative hypothesis xnoisefree = 10; % LRT detection [dresult,stat,snrThLRT] = lrt(x,xnoisefree,variance); % Empirical false-alarm rate falseAlarmRateLRT = sum(dresult)/M

falseAlarmRateLRT = 9.9500e-04

The false alarm rates estimated using the above two methods are consistent.

```
% Difference between SNR thresholds calculated by npwgnthresh and LRT detector
thmse = abs(snrThNP-snrThLRT)^2
```

thmse = 1.9722e-31

The SNR thresholds generated from npwgnthresh and phased.LRTDetector are also consistent.

Plot the first 10,000 samples of detection statistics. The red horizontal line shows the detection threshold of the LRT detector. The yellow circle shows the detected false alarm.

% Plot detection statistics x1 = stat(1:1e4); plot(x1) % Plot detection threshold line([1 length(x1)],[snrThLRT snrThLRT],'Color','red') hold on % Plot detection results dindex = find(dresult(1:1e4)); plot(dindex,stat(dindex),'o'); xlabel('Sample') ylabel('Value')

You can see that few sample values exceed the threshold. This result is expected because of the low false-alarm probability.

### False Alarm Rate for Complex-Valued Signals in Complex White Gaussian Noise

This example shows how to empirically verify the probability of false alarm in a system that uses *coherent detection* of complex-valued signals. Coherent detection means that the system utilizes information about the phase of the complex-valued signals.

Determine the required SNR for the NP detector (the LRT detector) in a coherent detection scheme with one sample. Use a maximum tolerable false-alarm probability of $${10}^{-3}$$.

% Probability of false alarm pfa = 1e-3; % SNR threshold in dB snrThdB = npwgnthresh(pfa,1,'coherent'); % SNR threshold snrThNP = sqrt(db2pow(snrThdB));

Test that this threshold empirically results in the correct false-alarm rate. The sufficient statistic in the complex-valued case is the real part of the received sample.

rng default % Noise variance variance = 5; % Number of independent samples M = 1e6; % Data under null hypothesis x = sqrt(variance/2)*(randn(1,M)+1j*randn(1,M)); % Empirical false-alarm rate falseAlarmRateNP = sum(real(x)/sqrt(variance)>snrThNP)/M

falseAlarmRateNP = 9.9500e-04

Alternatively, use `phased.LRTDetector`

to empirically calculate the detection result and false alarm rate. The LRT detector requires inputting the noise-free signal under the alternative hypothesis. As we test the null hypothesis, the complex amplitude of the noise-free signal under the alternative hypothesis is irrelevant to the testing and can be set to any real value. Set the noise-free signal under the alternative hypothesis to be amplitude 10 with random phase.

% Configure the LRT detector lrt = phased.LRTDetector('DataComplexity','Complex',... 'ProbabilityFalseAlarm',pfa,'ThresholdOutputPort',true); % Known noise-free signal under the alternative hypothesis xnoisefree = 10*exp(1j*2*pi*rand); % LRT detection [dresult,~,snrThLRT] = lrt(x,xnoisefree,variance); % Empirical false-alarm rate falseAlarmRateLRT = sum(dresult)/M

falseAlarmRateLRT = 9.6300e-04

The false alarm rates estimated using the above two methods are consistent.

```
% Difference between SNR thresholds calculated by npwgnthresh and LRT detector
thmse = abs(snrThNP-snrThLRT)^2
```

thmse = 0

The SNR thresholds generated from `npwgnthresh`

and `phased.LRTDetector`

are also consistent.

## More About

### Data Precision

This System object supports single and double precision for input data, properties, and arguments. If any input data is single precision, the non-logical outputs are also single precision. If any input data is double precision, the non-logical outputs are double precision. The precision of the non-logical output is independent of the precision of the properties and other arguments.

### Signal Model

The LRT detector assumes a linear deterministic signal model data with known white noise
covariance. In each case, the LRT detector assumes the same known signal model for each
column of `X`

. The LRT detector assumes that the
*N*-dimensional data follows the known signal model

`X = Xknown + noise`

where `Xknown`

is the *N*-by-1 signal vector
specified by the `Xknown`

argument. `noise`

is an
*N*-by-1 white Gaussian noise vector specified only by the noise
covariance scalar `ncov`

.

The input data `X`

contains *M* independent data
samples along each row. The data is processed along each column of `X`

.
For radar applications, each column of the input data `X`

can be:

an

*N*-dimensional fast-time signal for range processing.an

*N*-dimensional array signal for spatial processing,an

*N*-dimensional slow-time signal for Doppler processing.a stacked

*N*-dimensional space-time signal for range-angle/Doppler-angle processing.

The LRT detector processes data column-by-column. Each column is a separate data channel
containing identical signals `Xknown`

in random noise. The LRT detector
determines whether to reject the null hypothesis given by *Xknown = 0*.
Because there is only one known signal model, the LRT detector outputs one detection result
for each channel of `X`

.

### Detection Statistics and Threshold

The detector employs the Neyman-Pearson detection criterion. If the
*H*_{0 } hypothesis best accounts for the data, the
detector declares that a target is not present. If the *H*_{1
} hypothesis best accounts for the data, the detector declares that a target is
present. In either case, the decision may be erroneous leading to false alarms and false
dismissals. The LRT detector requires full knowledge of the likelihood functions
*p(x,H*_{0}*)* and
*p(x,H*_{1}*)*. The LRT detector
creates a detection statistics based on the ratio of the likelihood functions under
*H*_{1} and
*H*_{0}. The detector compares the detection
statistics with the detection threshold – the detector decides
*H*_{1} if the likelihood ratio
*p(x,H*_{1})*/p(x,H*_{0}*)
> γ*. If the detection statistics is larger than the threshold, then it decides
*H*_{1} to be true; otherwise, it decides
*H*_{0} to be true. The LRT detector is the optimal
detector in noise when the likelihood function of each hypothesis is known. LRT detector
assumes the signal and noise model is known. The detector that maximizes the probability of
detection for a given probability of false alarm is the LRT detector or Neyman-Pearson (NP)
detector.

For a real data model with known white Gaussian noise σ², the detection statistic is

$$T(x)=\frac{{a}^{T}x}{\sigma \sqrt{{a}^{T}a}}$$

while for complex data the test statistic is

$$T(x)=\text{real(}\frac{{a}^{\u2020}x}{\sigma \sqrt{{a}^{\u2020}a}})$$

For a given probability of false alarm *Pfa*, the detection threshold
η is determined by solving

$$\eta =\text{erfcinv(2}{P}_{fa})$$

for complex data and

$$\eta =\sqrt{2}\text{erfcinv(2}{P}_{fa})$$

for real data.

## References

[1] Steven M. Kay,
*Fundamentals of Statistical Signal Processing, Detection Theory*,
Prentice-Hall PTR, 1993.

[2] Mark A. Richards,
*Fundamentals of Radar Signal Processing*, Third edition, McGraw-Hill
Education, 2022.

## Extended Capabilities

### C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

## Version History

**Introduced in R2023b**

## See Also

`npwgnthresh`

| `rocsnr`

| `rocpfa`

| `phased.GLRTDetector`

| `phased.CFARDetector`

| `phased.CFARDetector2D`

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)