Detecting a signal against white noise¶
This example examines the detection of a deterministic signal against complex Gaussian noise. This situation is often encountered in radar, sonar and communication systems.
Introduction¶
There are many different types of detectors for use in various applications. Among the most popular ones are Bayesian detector, maximum likelihood detector and Neyman-Pearson criterion (KNP) detection. In radar and sonar systems, KNP is the most popular choice because it can provide a given level of false alarm probability (FAP).
In this example, we restrict 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¶
The received signal is assumed to fit the model:
\begin{align} x(t)=s(t)+n(t) \end{align} where $s(t)$ is the signal and $n(t)$ is the noise.
Assume that the signal power is equal to 1 watt, and the noise power is determined appropriately based on the signal-to-noise ratio (SNR). For example, for an SNR of 10 dB, the noise power, i.e. the noise variance, will be 0.1 watts.
Matched filtering¶
A matched filter is often used by a receiver to improve SNR. From a discrete signal perspective, the coefficients of the matched filter are specified as complex conjugate values with respect to the emitted signal.
When dealing with complex signals and noise, there are two types of receivers. The first type is the coherent receiver, which assumes that the amplitude and phase of the received signal are known. This leads to a perfect match between the coherent filter coefficients and the signal s. Therefore, the coefficients of the matched filter can be considered as the conjugate signal s. Then the operation of the matched filter can be modelled as
\begin{align} y = s^*x = s^*(s+n) = |s|^2 + s^*n\ . \end{align}
Note that although the total output $y$ is still a complex quantity, the signal is fully characterised by $∣s∣^2$, which is a real number and is contained in the in-phase component $y$. Consequently, a detector following the matched filter in a coherent receiver typically uses only the real part of the received signal. Such a 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 modelled as a copy of the original signal with random phase error. In incoherent detection, the signal power is used after the matched filter to account for in-phase and quadrature components
Detector¶
The objective function of the decision rule CNR can be written as
\begin{align} J = P_d + g(P_{fa} - a), \end{align}
i.e. maximise the probability of detection $(Pd)$, while limiting the probability of false alarm $(Pfa)$, 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 $(LRT)$ as follows:
\begin{align} \frac{p_y(y|H_1)}{p_y(y|H_0)}{{H_1 \atop >}\atop {< \atop H_0}}} Th\ . \end{align}
In this particular situation $NP$, since the false alarm is caused by noise only, the threshold $Th$ is determined by the noise to provide a fixed $Pfa$. The general view $LRT$, shown above, is often difficult to evaluate. In real-world applications, we often use an easily computable quantity from the signal, i.e., sufficient statistics to replace the ratio of the two probability density functions. For example, a sufficient statistic $z$ can be as simple as
\begin{align} z = |y| \end{align}
then the simplified detector becomes
\begin{align} z {{H_1 \atop >}\atop {< \atop H_0}} T\ . \end{align}
T is the threshold for sufficient statistic z, acting in the same way as the threshold Th 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¶
We first consider an example of detecting a signal in noise using a single sample.
Assume that the signal is a single power sample and the SNR is 3 dB. Using Monte Carlo simulation for 100000 attempts, we generate the signal and noise as follows
Pkg.add(["DSP"])
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, its value is equal to
x = s + n; # смесь сигнал с шумом
The matched filter in this case is trivial, since the signal itself is a single sample.
mf = 1;
In this case, the gain of the matched filter is 1, so there is no gain in SNR.
Now we will perform detection and check the detector performance. For a coherent receiver, the received signal after the matched filter has the following form
y = mf'*x; # применение согласованного фильтра;
The 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,
z = real(y);
Suppose we want to fix $Pfa$ at $10^{-3}$. Given sufficient statistics $z$, the decision rule is as follows
\begin{align} z {{H_1 \atop >}\atop {< \atop H_0}} T \end{align}
where the threshold $T$ is related to $Pfa$ as follows:
\begin{align} P_{fa}=\frac{1}{2}\left[ 1 - {\rm erf}\left(\frac{T}{\sqrt{NM}}\right)\right] \end{align}
In this equation, N is the signal power and M is the gain of the matched filter. Note that T is the signal threshold after the matched filter and NM is the noise power after the matched filter, so $T/√ (NM)$ can be thought of as the ratio between signal and noise magnitudes, i.e., it is related to the signal-to-noise ratio, SNR. Since SNR is usually referred to as the ratio between signal and noise power, given the units of each quantity in this expression, we can see that
\begin{align} \frac{T}{\sqrt{NM}}=\\sqrt{\rm SNR}\ . \end{align}
Since N and M are fixed after selecting the noise and signal waveform, there is a correspondence between T and SNR. Given that T is the threshold of the signal, SNR can be viewed 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{align}
The required SNR threshold at complex white Gaussian noise for the NP detector can be calculated using the npwgnthresh function as follows:
Pfa = 1e-3;
snrthreshold = db2pow(npwgnthresh(Pfa, 1,"coherent"));
Note that this threshold, although it also takes the form of an SNR value, is different 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 a physical characteristic of the signal determined by the propagation medium, waveform, transmission power, etc.
The true threshold T can be derived from this SNR threshold as
\begin{align} T=\sqrt{NM}\cdot\sqrt{\rm SNR}. \end{align}
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 ability of a detector to detect a target is often measured by Pd. In Monte Carlo modelling, Pd can be calculated as the ratio of the number of times the signal passes the threshold to the total number of trials.
Pd = sum(z.>threshold)/Ntrial
print("Pd = $(Pd)")
On the other hand, a false alarm occurs when the detection indicates that there is a target but in fact there is no target, i.e. the received signal passes the threshold when only noise is present. The probability of detector error in detecting a target when there is no target is defined as Pfa.
x = n;
y = mf'*x;
z = real(y);
Pfa = sum(z.>threshold)/Ntrial
print("Pfa = $(Pfa)")
which fulfils our requirements.
To see the relationship between SNR, Pd and Pfa on a graph, we can plot the theoretical ROC curve using the rocsnr function for an SNR value of 3 dB as
rocsnr(snrdb,SignalType="NonfluctuatingCoherent",MinPfa=1e-4)
From the figure, we can see that the measured values of 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¶
The incoherent receiver takes into account the phases of the received signal, so for the considered case the signal x contains a phase term and is defined as
# 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 for comparison with the threshold. In this modelling we choose the magnitude as a sufficient statistic
z = abs.(y);
Given our choice of sufficient statistic z, the threshold is related to Pfa by the equation
\begin{align} P_{fa}={\rm exp}\left(-\frac{T^2}{NM}\right)={\rm exp}(-{\rm SNR})\ . \end{align}
The signal-to-noise ratio threshold SNR for the NP detector can be calculated using npwgnthresh as follows:
snrthreshold = db2pow(npwgnthresh(Pfa, 1,"noncoherent"));
The threshold, T, is determined from the SNR as follows
mfgain = mf'*mf;
threshold = sqrt(npower*mfgain*snrthreshold);
Again, Pd can be obtained using the
Pd = sum(z.>threshold)/Ntrial
print("Pd = $(Pd)")
Note that the resulting Pd is inferior to the performance we get from the coherent receiver.
In the case of no target, the received signal contains only noise. We can calculate Pfa using Monte Carlo simulation as
x = n;
y = mf'*x;
z = abs.(y);
Pfa = sum(z.>threshold)/Ntrial
print("Pfa = $(Pfa)")
The ROC curve for an incoherent receiver is plotted as
rocsnr(snrdb,SignalType="NonfluctuatingNoncoherent",MinPfa=1e-4)
We see that the detector performance of the incoherent receiver is inferior to that of the coherent receiver.
Conclusion¶
This example shows how to model and perform various detection methods using Engee. The example illustrates the relationship between several commonly encountered variables in signal detection, namely probability of detection (Pd), probability of false alarm (Pfa), and signal-to-noise ratio (SNR). In particular, the example calculates detector performance using Monte Carlo simulations and verifies the results of the metrics using receiver operating characteristic (ROC) curves.
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 a plot of the ROC curve. The 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 threshold SNR value used for detection. According to the Neyman-Pearson decision rule, the SNR threshold - the second SNR value we see for detection - is determined by the noise distribution and the desired Pfa level. Therefore, such an SNR threshold does correspond to the Pfa axis on the ROC curve. If we fix the SNR of a single sample, as shown in the ROC curve plots above, each point on the curve will correspond to a Pfa value, which in turn translates to a threshold SNR value. Using this threshold SNR value for detection will result in a corresponding Pd value.
Note that the SNR threshold may not be the same as the threshold used directly in the actual detector. In a real detector, a readily computable sufficient statistical value is usually used for detection. Thus, the true threshold should be derived from the aforementioned SNR threshold in such a way that it matches the choice of sufficient statistic.