Engee documentation
Notebook

Signal detection against a background of white noise

This example examines the detection of a deterministic signal against a background of complex Gaussian noise. This situation is often found in radar, sonar, and communications systems.

Introduction

There are many different types of detectors for use in various applications. Among the most popular are the Bayesian detector, the maximum likelihood detector, and the Neiman-Pearson criterion (NCP) detection. In radar and sonar systems, KNP is the most popular choice because it can provide a given level of false alarm probability.

In this example, we will limit ourselves to a scenario in which the signal is deterministic and the noise is white and Gaussian.

The example covers the following sections: coherent detection, incoherent detection, matched filtering, and receiver detection curves (ROC).

Signal and noise model

It is assumed that the received signal corresponds to the model:

\begin{align}
x(t)=s(t)+n(t)
\end{align}
where "A signal, eh - noise.

Let's assume that the signal power is 1 watt, and the noise power is determined accordingly based on the signal-to-noise ratio (SNR). For example, for an SNR of 10 dB, the noise power, that is, the noise dispersion, will be 0.1 watts.

Consistent filtering

A matched filter is often used by the receiver to boost the SNR. From the point of view of a discrete signal, the coefficients of a matched filter are set as complex conjugate values relative to the emitted signal.

When dealing with complex signals and noise, there are two types of receivers. The first type is a coherent receiver, which assumes that the amplitude and phase of the received signal are known. This leads to a perfect match between the coefficients of the matched filter and the s signal. Therefore, the coefficients of the matched filter can be considered as a conjugate signal s. Then the operation of the matched filter can be modeled as

\begin{align}
y = s^x = s^(s+n) = |s|^2 + s^*n\ .
\end

Note that although the general output is It is still a complex quantity, and the signal is fully characterized by , which is a real number and is contained in the common - mode component . Therefore, a detector following a matched filter in a coherent receiver usually uses only the real part of the received signal. This receiver usually provides the best performance. However, a coherent receiver is vulnerable to phase errors. In addition, a coherent receiver requires additional equipment to perform phase detection. For an incoherent receiver, the received signal is modeled as a copy of the original signal with a random phase error. In case of incoherent detection, the power of the signal is used after the matched filter to account for the common-mode and quadrature components.

The Detector

The objective function of the decision rule CNP can be written as

\begin{align}
J = P_d + g(P_{fa} - a),
\end

that is, to maximize the probability of detection , while limiting the probability of a false alarm , at a given level a. The variable g in the equation is the Lagrange multiplier. The NP detector can be formed as a likelihood ratio test. as follows:

\begin{align}
\frac{p_y(y|H_1)}{p_y(y|H_0)}{{H_1 \atop >}\atop {< \atop H_0}} Th\ .
\end

In this particular situation since the false alarm is caused only by noise, the threshold determined by noise to ensure a fixed . General view The one shown above is often difficult to evaluate. In real-world applications, we often use an easily calculated value from a signal, i.e. sufficient statistics to replace the ratio of two probability density functions. For example, sufficient statistics it can be as simple as

\begin{align}
z = |y|
\end

then the simplified detector becomes

\begin{align}
z {{H_1 \atop >}\atop {< \atop H_0}} T\ .
\end

T is the threshold for sufficient z statistics, acting in the same way as the Th threshold for LRT. Thus, the threshold is not only related to probability distributions, but also depends on the choice of sufficient statistics.

Detection of a single sample using a coherent receiver

First, we will look at an example of detecting a signal in noise using a single sample.

Let's assume that the signal is a unit power sample, and the SNR is 3 dB. Using a 100,000-attempt Monte Carlo simulation, we generate the signal and noise as follows

In [ ]:
Pkg.add(["DSP"])
In [ ]:
using Random,DSP
# fix the random number generator
seed = 2024
rstream =  Xoshiro(seed)

Ntrial = Int64(1e5); #  количество попыток Монте-Карло
snrdb = 3; # ОСШ в dB
snr = db2pow(snrdb);# ОСШ в абсолютных единицах
spower = 1;               # мощность сигнала, Вт
npower = spower/snr; # мощность шума
namp = sqrt(npower/2); # амплитуда шума в каждом канале
s = ones(1,Ntrial);       # генерация сигнала
n = namp*(randn(rstream,1,Ntrial)+1im*randn(rstream,1,Ntrial));  # шум

Note that the noise is complex, white, and Gaussian distributed.

If the received signal contains a target, then its value is

In [ ]:
x = s + n; # смесь сигнал с шумом

A matched filter is trivial in this case, since the signal itself is a single sample.

In [ ]:
mf = 1;

In this case, the gain of the matched filter is 1, so there is no gain in SNR.

Now we will perform the detection and check the detector operation. For a coherent receiver, the received signal after a matched filter has the form

In [ ]:
y = mf'*x; # применение согласованного фильтра;

A sufficient statistic, i.e. the value used for comparison with the detection threshold, for a coherent detector is the real part of the received signal after the matched filter, i.e.,

In [ ]:
z = real(y);

Suppose that we want to fix at the level of . Given sufficient statistics The decision-making rule looks like this

\begin{align}
z {{H_1 \atop >}\atop {< \atop H_0}} T
\end

where is the threshold associated with as follows:

\begin{align}
P_{fa}=\frac{1}{2}\left[ 1 - {\rm
erf}\left(\frac{T}{\sqrt{NM}}\right)\right]
\end

In this equation, N is the signal power and M is the gain of the matched filter. Note that T is the threshold of the signal after the matched filter, and NM is the noise power after the matched filter, so It can be considered as the ratio between the magnitude of the signal and the noise, i.e. it is related to the signal-to-noise ratio, SNR. Since SNR is usually referred to as the ratio between signal power and noise, given the units of measurement of each quantity in this expression, we can see that

\begin{align}
\frac{T}{\sqrt{NM}}=\sqrt{\rm SNR}\ .
\end

Since N and M are fixed after selecting the shape of the noise and signal, there is a correspondence between T and SNR. Given that T is the threshold of the signal, SNR can be considered as the threshold of the signal-to-noise ratio. Thus, the threshold equation can be rewritten as

\begin{align}
P_{fa}=\frac{1}{2}\left[ 1 - {\rm
erf}\left({\sqrt{SNR}}\right)\right]
\end

The required SNR threshold for complex white Gaussian noise for the NP detector can be calculated using the npwgnthresh function as follows:

In [ ]:
Pfa = 1e-3;
snrthreshold = db2pow(npwgnthresh(Pfa, 1,"coherent"));

Note that this threshold, although it also has the form of an SNR value, differs from the SNR of the received signal. The SNR threshold value is a calculated value based on the desired detection efficiency, in this case Pfa; while the SNR of the received signal is the physical characteristic of the signal, determined by the propagation medium, waveform, transmission power, etc.

The true threshold T can be obtained from this SNR threshold as

\begin{align}
T=\sqrt{NM}\cdot\sqrt{\rm SNR}.
\end

In [ ]:
mfgain = mf'*mf;
# Для соответствия уравнению в тексте выше:
# npower - N 
# mfgain - M 
# snrthreshold - SNR
threshold = sqrt(npower*mfgain*snrthreshold);

Detection is performed by comparing the signal with a threshold value. Since the original signal, s, is represented in the received signal, successful detection occurs when the received signal passes the threshold, i.e. z>T. The detector's ability to detect a target is often measured by Pd. In Monte Carlo simulation, Pd can be calculated as the ratio of the number of times a signal passes a threshold to the total number of tests.

In [ ]:
Pd = sum(z.>threshold)/Ntrial
print("Pd = $(Pd)")
Pd = 0.13665

On the other hand, a false alarm occurs when the detection indicates that there is a target, but in fact there is none, i.e. the received signal passes the threshold when only noise is present. The probability of a detector error when detecting a target when there is none is defined as Pfa.

In [ ]:
x = n;
y = mf'*x;
z = real(y);
Pfa = sum(z.>threshold)/Ntrial
print("Pfa = $(Pfa)")
Pfa = 0.00098

which meets our requirements.

To see the relationship between SNR, Pd, and Pfa on the graph, we can plot a theoretical ROC curve using the rocsnr function for a 3 dB SNR value as

In [ ]:
rocsnr(snrdb,SignalType="NonfluctuatingCoherent",MinPfa=1e-4)
Out[0]:

It can be seen from the figure that the measured values Pd=0.1390 and Pfa=0.0009, obtained above for the SNR value of 3 dB, correspond to the theoretical point on the ROC curve.

Detection of a single sample using an incoherent receiver

An incoherent receiver takes into account the phases of the received signal, therefore, for the case under consideration, the signal x contains a phase term and is defined as

In [ ]:
# simulate the signal
x = s.*exp.(1im*2*pi*rand(rstream,1,Ntrial)) .+ n;
y = mf'*x;

When using an incoherent receiver, the power (or magnitude) of the received signal after the matched filter is used to compare with the threshold. In this simulation, we choose a value as a sufficient statistic.

In [ ]:
z = abs.(y);

Given our choice of sufficient z statistics, the threshold is related to the Pfa equation

\begin{align}
P_{fa}={\rm exp}\left(-\frac{T^2}{NM}\right)=-{\rm SNR}\ .
\end

The threshold value of the signal-to-noise ratio SNR for the NP detector can be calculated using npwgnthresh as follows:

In [ ]:
snrthreshold = db2pow(npwgnthresh(Pfa, 1,"noncoherent"));

The threshold, T, is determined from the SNR as follows

In [ ]:
mfgain = mf'*mf;
threshold = sqrt(npower*mfgain*snrthreshold);

Again, Pd can be obtained using

In [ ]:
Pd = sum(z.>threshold)/Ntrial
print("Pd = $(Pd)")
Pd = 0.06156

Note that the resulting Pd is inferior to the performance that we get from a coherent receiver.

If there is no target, the received signal contains only noise. We can calculate the Pfa using Monte Carlo simulation as

In [ ]:
x = n;
y = mf'*x;
z = abs.(y);
Pfa = sum(z.>threshold)/Ntrial
print("Pfa = $(Pfa)")
Pfa = 0.00096

The ROC curve for an incoherent receiver is plotted as

In [ ]:
rocsnr(snrdb,SignalType="NonfluctuatingNoncoherent",MinPfa=1e-4)
Out[0]:

We see that the detector performance of an incoherent receiver is inferior to that of a coherent receiver.

Conclusion

This example shows how to model and perform various detection methods using Engee. The example illustrates the relationship between several common variables in signal detection, namely probability of detection (Pd), probability of false alarm (Pfa), and signal-to-noise ratio (SNR). In particular, in the example, the detector performance is calculated using Monte Carlo simulation and the metric results are checked using receiver operating characteristic curves (ROC).

There are two SNR values that we encounter when detecting a signal. The first is the SNR of a single data sample. This is the SNR value displayed on the graph of the ROC curve. A point on the ROC gives the required SNR of a single sample needed to achieve the corresponding Pd and Pfa. However, this is NOT the SNR threshold used for detection. According to the Neiman-Pearson decision rule, the SNR threshold-the second SNR value that we see during detection-is determined by the noise distribution and the desired Pfa level. Therefore, such an SNR threshold really corresponds to the Pfa axis on the ROC curve. If we fix the SNR of one sample, as shown in the above graphs of ROC curves, then each point on the curve will correspond to the Pfa value, which, in turn, is translated into the threshold SNR value. Using this SNR threshold value for detection will result in the corresponding Pd value.

Note that the SNR threshold may not match the threshold used directly in the actual detector. In a real detector, an easily calculated sufficient statistical value is usually used for detection. Thus, the true threshold should be derived from the above-mentioned SNR threshold in such a way that it corresponds to the choice of sufficient statistics.