Matlab中的能量检测器和绘图ROC

时间:2017-04-04 03:47:49

标签: matlab

我对ROC情节有疑问。我不确定哪一部分是错的。我感谢您的帮助。 我正在尝试使用MATLAB创建能量检测器模拟。我使用了正弦曲线作为AWGN损坏的输入。

clc
close all
clear all

%1. Generate a sinusoid
fs=30;
t=0:1/fs:10;
A=1;
f=10;
x=A*sin(2*pi*f*t);
figure;
plot(t,x)

%2. Generate a vector of noise samples with the required power.
N=1000;
snr_dB = -10; % SNR in decibels
snr = 10.^(snr_dB./10); % Linear Value of SNR
Pf = 0.01:0.01:1; % Pf = Probability of False Alarm

%3. Add signal and noise
Y = awgn(x,snr); 

figure;
plot(t,Y)

%4. Simulation to plot Probability of Detection (Pd) vs. Probability of False Alarm (Pf) 

for m = 1:length(Pf)

   i = 0;

   for kk=1:10000 % Number of Monte Carlo Simulations

   energy = abs(Y).^2; % Energy of received signal
   energy_fin =(1/N).*sum(energy); % Test Statistic for the energy detection
   thresh(m) = (qfuncinv(Pf(m))./sqrt(N))+ 1; % Theoretical value of Threshold, refer, Sensing Throughput Tradeoff in Cognitive Radio, Y. C. Liang

    if(energy_fin >= thresh(m))  % Check whether the received energy is greater than threshold, if so, increment Pd (Probability of detection) counter by 1
        i = i+1;
    end
end

Pd(m) = i/kk;

end
figure;

plot(Pf, Pd)
xlabel('Pf') % x-axis label
ylabel('Pd') % y-axis label
hold on


thresh = (qfuncinv(Pf)./sqrt(N))+ 1;
Pd_the = qfunc(((thresh - (snr + 1)).*sqrt(N))./(sqrt(2.*snr + 1)));
figure
plot(Pf, Pd_the, 'r')
xlabel('Pf') % x-axis label
ylabel('Pd threshold') % y-axis label
hold on

0 个答案:

没有答案