Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
805 B
2
Indexable
Never
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
#Q4 -- (a)
#given parameters

P_FA = 1e-8
sigma_n_sq = 1 #variance of WGN Noise

A_samples = np.linspace(0, 10, 100)
P_D = np.zeros(100)

N_1=50
f_1=0.2
j=0;
for A in A_samples:
  #under H0
  mu_0 = 0
  var_0 = 0
  for i in range(0,N_1):
    var_0 = var_0 + 4*(A**2)*(np.cos(2*np.pi *f_1*i)**2)*(sigma_n_sq**2)
  
  #under H1
  mu_1 = 0
  for i in range(0,N_1):
    mu_1 = mu_1 + 2*(A**2)*(np.cos(2*np.pi *f_1*i)**2)
  var_1 = var_0

  #threshold
  gamma = norm.ppf(P_FA, loc=mu_0, scale=np.sqrt(var_0))

  P_D[j] = norm.cdf(gamma, loc=mu_1, scale=np.sqrt(var_1))
  j=j+1


plt.figure(figsize=(5,5))
plt.plot(A_samples, P_D, color='red')
plt.xlabel('A')
plt.ylabel('P_D')
plt.show()

Leave a Comment