0% found this document useful (0 votes)
28 views6 pages

Activity8 Stats

The document presents MATLAB code for plotting the probability of detection (PD) against the energy-to-noise ratio (ENR) in a white Gaussian noise (WGN) environment, using various false alarm probabilities (PFA). It also includes a task to determine the necessary number of samples (N) for a detection problem given specific parameters, along with the corresponding MATLAB code for the calculation. The final result indicates that approximately 46499.72 samples are required for the specified detection conditions.

Uploaded by

Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views6 pages

Activity8 Stats

The document presents MATLAB code for plotting the probability of detection (PD) against the energy-to-noise ratio (ENR) in a white Gaussian noise (WGN) environment, using various false alarm probabilities (PFA). It also includes a task to determine the necessary number of samples (N) for a detection problem given specific parameters, along with the corresponding MATLAB code for the calculation. The final result indicates that approximately 46499.72 samples are required for the specified detection conditions.

Uploaded by

Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Detection Performance for DC Level

in White Gaussian Noise (WGN)

Submitted By:
Aatika Arshad
aa07993
Stats And Inferencing

Date: th November 2024


Brief Description of the Code
This MATLAB code plots the probability of detection (PD ) versus the energy-to-noise ratio (ENR) in
dB for various false alarm probabilities (PF A ) in a white Gaussian noise (WGN) environment. The code
uses the built-in ‘qfunc‘ and ‘qfuncinv‘ functions in MATLAB to compute the Q-function and its inverse,
which are essential for calculating the detection probability.
The PD is calculated for a range of ENR values, and for each PF A value, a separate curve is generated.
The resulting plot helps visualize how the probability of detection improves as the ENR increases for
different values of PF A .

1
MATLAB Code
1 % MATLAB Code to plot Probability of Detection ( P_D ) vs . SNR for various P_FA
2

3 % Parameters
4 PFA_values = [1 e -1 , 1e -2 , 1e -3 , 1e -4 , 1e -5 , 1e -6 , 1e -7]; % Values of P_FA
5 SNR_dB = linspace (0 , 20 , 100) ; % Range of SNR values in dB
6 N = 1; % Assuming N = 1 for simplicity
7

8 % Plotting
9 figure ;
10 hold on ;
11 colors = lines ( length ( PFA_values ) ) ; % Generate unique colors for each line
12

13 for i = 1: length ( PFA_values )


14 PFA = PFA_values ( i ) ;
15 threshold = qfuncinv ( PFA ) ; % Calculate threshold using built - in qfuncinv
16

17 % Calculate P_D for each SNR


18 PD = arrayfun ( @ ( snr ) qfunc ( threshold - sqrt ( N * 10^( snr / 10) ) ) , SNR_dB ) ;
19

20 % Plot the result with legend entry


21 plot ( SNR_dB , PD , ’ LineWidth ’ , 1.5 , ’ Color ’ , colors (i ,:) , ...
22 ’ DisplayName ’ , sprintf ( ’ P_ { FA } = 10^{% d } ’ , log10 ( PFA ) ) ) ;
23 end
24

25 % Customize the plot


26 xlabel ( ’ Energy - to - noise - ratio ( dB ) 10 log_ {10} ( NA ^2 / \ sigma ^2) ’ , ’ FontSize ’ ,
12) ;
27 ylabel ( ’ Probability of detection , P_D ’ , ’ FontSize ’ , 12) ;
28 title ( ’ Detection performance for DC level in WGN ’ , ’ FontSize ’ , 14) ;
29 legend ( ’ show ’ , ’ Location ’ , ’ southeast ’) ; % Show legend in the bottom right
30 grid on ;
31 set ( gca , ’ FontSize ’ , 12) ; % Set axis font size for readability
32 hold off ;

Listing 1: MATLAB code for plotting PD vs ENR for different PF A values

2
Resulting Plot

Figure 1: Detection performance plot showing PD vs. ENR for various PF A values.

3
Code Explanation
The MATLAB code consists of the following main steps:
1. Parameters Setup: We define an array of values for PF A (False Alarm Probability) and a range
for ENR in dB.
2. Q-function and Threshold Calculation: The threshold for each PF A is calculated using ‘qfuncinv‘.
For each ENR value, the probability of detection, PD , is computed using ‘qfunc‘ and stored.

Task 2
We are tasked with determining the necessary number of samples N for a detection problem in white
Gaussian noise, given the following parameters:

• False Alarm Probability PF A = 10−4

• Detection Probability PD = 0.99


• Signal-to-Noise Ratio (SNR) in dB:

A2
 
10 log10 = −32 dB
σ2

Approach
The formula relating PD , PF A , and N for detection in white Gaussian noise is:
r !
−1 N A2
PD = Q Q (PF A ) −
σ2
Rearranging to solve for N :
r
−1 −1 N A2
Q (PD ) = Q (PF A ) −
σ2
Then,
r
N A2
= Q−1 (PF A ) − Q−1 (PD )
σ2
Squaring both sides,

N A2 2
2
= Q−1 (PF A ) − Q−1 (PD )
σ
Finally, we have:

σ2 2
N= 2
Q−1 (PF A ) − Q−1 (PD )
A

Converting SNR from dB


 
A2
Given 10 log10 σ2 = −32 dB, we can convert this to a linear ratio:

A2 −32

2
= 10 10 = 10−3.2
σ

Substituting Values
Now, we need to compute Q−1 (PF A ) and Q−1 (PD ) using the inverse Q-function and substitute these
values into the equation for N .

4
MATLAB Code
The following MATLAB code can be used to compute the necessary number of samples N :

% Given values
P_FA = 10e-4;
P_D = 0.99;
SNR_dB = -32;

% Convert SNR from dB to linear scale


A2_over_sigma2 = 10^(SNR_dB / 10);

% Calculate Q-inverse values


Q_inv_P_FA = qfuncinv(P_FA);
Q_inv_P_D = qfuncinv(P_D);

% Calculate necessary number of samples N


N = (1 / A2_over_sigma2) * (Q_inv_P_FA - Q_inv_P_D)^2;

% Display result
fprintf(’The necessary number of samples N is: %.2f\n’, N);

Explanation of Code
• **Convert SNR from dB to linear scale**: This step converts the SNR value from dB to a linear
2
ratio to get A
σ2 .

• **Use ‘qfuncinv‘**: The MATLAB function ‘qfuncinv‘ is used to compute the inverse Q-function
values for PF A and PD .
• **Substitute into the equation**: The values of Q−1 (PF A ) and Q−1 (PD ) are substituted into the
equation to compute N .
• **Display result**: The result is displayed as the necessary number of samples N .

Results
After executing the MATLAB code, the result for the necessary number of samples N is calculated. For
the given parameters, the value of N is approximately:

N ≈ 46499.72
Thus, the necessary number of samples required is N ≈ 46499.72.

You might also like