Advertisement
at3107

matlab code 1

Jun 21st, 2021
1,222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.54 KB | None | 0 0
  1. % This code is to plot receiver operating characteristic curve for simple energy
  2. % detection, when the primary signal is real Gaussian signal and noise is
  3. % addive white real Gaussian. Here, the threshold is available
  4. % analytically.
  5. % Code written by: Sanket Kalamkar, Indian Institute of Technology Kanpur,
  6. % India.
  7. clc
  8. close all
  9. clear all
  10. L = 1000;
  11. snr_dB = -10; % SNR in decibels
  12. snr = 10.^(snr_dB./10); % Linear Value of SNR
  13. Pf = 0.01:0.01:1; % Pf = Probability of False Alarm
  14. %% Simulation to plot Probability of Detection (Pd) vs. Probability of False Alarm (Pf)
  15. for m = 1:length(Pf)
  16.     m
  17.     i = 0;
  18. for kk=1:10000 % Number of Monte Carlo Simulations
  19.  n = randn(1,L); %AWGN noise with mean 0 and variance 1
  20.  s = sqrt(snr).*randn(1,L); % Real valued Gaussina Primary User Signal
  21.  y = s + n; % Received signal at SU
  22.  energy = abs(y).^2; % Energy of received signal over N samples
  23.  energy_fin =(1/L).*sum(energy); % Test Statistic for the energy detection
  24.  thresh(m) = (qfuncinv(Pf(m))./sqrt(L))+ 1; % Theoretical value of Threshold, refer, Sensing Throughput Tradeoff in Cognitive Radio, Y. C. Liang
  25.  if(energy_fin >= thresh(m))  % Check whether the received energy is greater than threshold, if so, increment Pd (Probability of detection) counter by 1
  26.      i = i+1;
  27.  end
  28. end
  29. Pd(m) = i/kk;
  30. end
  31. plot(Pf, Pd)
  32. hold on
  33. %% Theroretical ecpression of Probability of Detection; refer above reference.
  34. thresh = (qfuncinv(Pf)./sqrt(L))+ 1;
  35. Pd_the = qfunc(((thresh - (snr + 1)).*sqrt(L))./(sqrt(2).*(snr + 1)));
  36. plot(Pf, Pd_the, 'r')
  37. hold on
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement