%for Energy detection
%probabilty of false alarm Energy Detection
N=5000;
L=1000;
pfc=0.01:0.01:1;
pfe=1-sqrt(1-pfc);
pfm=(pfc-pfe)./(1-pfe);
%-----SNR in decibels-----%
snr_dB = -20;
snr_dB1 = -14;
snr_dB2 = -12;
snr_dB3 = -10;
snr_dB4=-8;
%-----Linear Value of SNR-----%
snr = 10.^(snr_dB./10);
snr1 = 10.^(snr_dB1./10);
snr2 = 10.^(snr_dB2./10);
snr3 = 10.^(snr_dB3./10);
snr4 = 10.^(snr_dB4./10);
%-----Probability of False Alarm-----%
% Pf = 0.01:0.01:1;
%% Simulation to plot Probability of Detection (Pd) vs. Probability of False Alarm (Pf) %
for m = 1:length(pfe)
Detect = 0;
for kk=1:1000 % Number of Monte Carlo Simulations
%-----AWGN noise with mean 0 and variance 1-----%
Noise = randn(1,L);
%-----Real valued Gaussian Primary User Signal------%
Signal = sqrt(snr).*randn(1,L);
Recv_Sig = Signal + Noise; % Received signal at SU
Energy = abs(Recv_Sig).^2; % Energy of received signal over N samples
%-----Computation of Test statistic for energy detection-----%
Test_Statistic =(1/L).*sum(Energy);
%-----Theoretical value of Threshold-----%
Threshold(m) = (qfuncinv(pfe(m))./sqrt(L))+ 1;
if(Test_Statistic >= Threshold(m)) % Check whether the received energy is greater than threshold, if so, increment Pd (Probability of detection) counter by 1
Detect = Detect+1;
end
end
% Pd(m) = Detect/kk;
end
% plot(pfe, Pd)
% hold on
%% Theroretical expression of Probability of Detection
Threshold =qfuncinv(pfe)./sqrt(L)+ 1;
Pd_the = qfunc(((Threshold - (snr + 1)).*sqrt(L))./2*(sqrt(2).*(snr + 1)));
Pd_the1 = qfunc(((Threshold - (snr1 + 1)).*sqrt(L))./2*(sqrt(2).*(snr1 + 1)));
Pd_the2 = qfunc(((Threshold - (snr2 + 1)).*sqrt(L))./2*(sqrt(2).*(snr2 + 1)));
Pd_the3 = qfunc(((Threshold - (snr3 + 1)).*sqrt(L))./2*(sqrt(2).*(snr3 + 1)));
Pd_the4 = qfunc(((Threshold - (snr4 + 1)).*sqrt(L))./2*(sqrt(2).*(snr4+ 1)));
% Pd_the5 = qfunc(((Threshold - (snr5 + 1)).*sqrt(L))./2*(sqrt(2).*(snr5+ 1)));
figure(1)
semilogx(pfe, Pd_the,'r','LineWidth',2)
hold on
semilogx(pfe, Pd_the1,'g','LineWidth',2)
hold on
semilogx(pfe, Pd_the2,'b','LineWidth',2)
hold on
semilogx(pfe, Pd_the3,'c','LineWidth',2)
hold on
semilogx(pfe, Pd_the4,'k','LineWidth',2)
axis([0 1 0 1.1])
grid on
title('ED ROC curves for Probability of False Alarm vs Probability of Detection N=5000 sample');
xlabel('Probability Of False Alarm');
ylabel('Probability Of Detection');
legend('SNR= -20dB','SNR= -14dB','SNR= -12dB','SNR= -10dB','SNR= -8dB');
%% Simulation to plot Probability of Detection (Pd) vs. Probability of False Alarm (Pf) %
L=1000;
pfc=0.01:0.01:1;
pfe=1-sqrt(1-pfc);
pfm=(pfc-pfe)./(1-pfe);
i_pfa=1:length(pfm);
for m = 1:length(pfm)
Detect = 0;
for kk=1:1000 % Number of Monte Carlo Simulations
%-----AWGN noise with mean 0 and variance 1-----%
Noise = randn(1,L);
%-----Real valued Gaussian Primary User Signal------%
Signal = sqrt(snr).*randn(1,L);
Recv_Sig = Signal + Noise; % Received signal at SU
Energy = abs(Recv_Sig).^2; % Energy of received signal over N samples
%-----Computation of Test statistic for energy detection-----%
Test_Statistic =(1/L).*sum(Energy);
%-----Theoretical value of Threshold-----%
% Threshold(m) = (qfuncinv(Pf(m))./sqrt(L))+ 1;
Threshold(i_pfa)=(sqrt(N)+sqrt(L))^2/(sqrt(N)-sqrt(L))^2*(1+(sqrt(N)+sqrt(L))^(-2/3)/(N*L)^(1/6)*finv(1-pfm,1,1));
if(Test_Statistic >= Threshold(i_pfa)) % Check whether the received energy is greater than threshold, if so, increment Pd (Probability of detection) counter by 1
Detect = Detect+1;
end
end
% Pd(m) = Detect/kk;
end
% plot(Pf, Pd)
% hold on
%% Theroretical expression of Probability of Detection
Threshold = (qfuncinv(pfm)./sqrt(L))+ 1;
Pd_them = qfunc(((Threshold - (snr + 1)).*sqrt(L))./2*(sqrt(2).*(snr + 1)));
Pd_the1m = qfunc(((Threshold - (snr1 + 1)).*sqrt(L))./2*(sqrt(2).*(snr1 + 1)));
Pd_the2m = qfunc(((Threshold - (snr2 + 1)).*sqrt(L))./2*(sqrt(2).*(snr2 + 1)));
Pd_the3m = qfunc(((Threshold - (snr3 + 1)).*sqrt(L))./2*(sqrt(2).*(snr3 + 1)));
Pd_the4m = qfunc(((Threshold - (snr4 + 1)).*sqrt(L))./2*(sqrt(2).*(snr4+ 1)));
figure(2)
semilogx(pfm, Pd_them,'r','LineWidth',2)
hold on
semilogx(pfm, Pd_the1m,'g','LineWidth',2)
hold on
semilogx(pfm, Pd_the2m,'b','LineWidth',2)
hold on
semilogx(pfm, Pd_the3m,'c','LineWidth',2)
hold on
semilogx(pfm, Pd_the4m,'k','LineWidth',2)
axis([0 1 0 1.1])
grid on
title('MME detector ROC curves for Probability of False Alarm vs Probability of Detection N=5000 sample');
xlabel('Probability Of False Alarm');
ylabel('Probability Of Detection');
legend('SNR= -20dB','SNR= -14dB','SNR= -12dB','SNR= -10dB','SNR= -8dB');
%for 2EMC
%probabilty of false alarm Energy Detection
Pdc=Pd_the+(1-Pd_the).*Pd_them;
Pdc1=Pd_the1+(1-Pd_the1).*Pd_the1m;
Pdc2=Pd_the2+(1-Pd_the2).*Pd_the2m;
Pdc3=Pd_the3+(1-Pd_the3).*Pd_the3m;
Pdc4=Pd_the4+(1-Pd_the4).*Pd_the4m;
figure(3)
semilogx(pfc,Pdc,'r','LineWidth',2)
hold on
semilogx(pfc, Pdc1,'g','LineWidth',2)
hold on
semilogx(pfc, Pdc2,'b','LineWidth',2)
hold on
semilogx(pfc, Pdc3,'c','LineWidth',2)
hold on
semilogx(pfc, Pdc4,'k','LineWidth',2)
axis([0 1 0 1.1])
grid on
title('2EMC ROC curves for Probability of False Alarm vs Probability of Detection N=5000 sample');
xlabel('Probability Of False Alarm');
ylabel('Probability Of Detection');
legend('SNR= -20dB','SNR= -14dB','SNR= -12dB','SNR= -10dB','SNR= -8dB');
%Compare Roc when SNR=-12dB
figure(4)
semilogx(pfe, Pd_the2,'b','LineWidth',2)
hold on
semilogx(pfm, Pd_the2m,'r','LineWidth',2)
hold on
semilogx(pfc, Pdc2,'g','LineWidth',2)
grid on
axis([0 1 0 1.1])
title('compare graph SNR=-12dB');
xlabel('Probability Of False Alarm');
ylabel('Probability Of Detection');
legend('ED','MME','2EMC');
New folder (2).zip_cognitive code_cognitive radio_matlab
版权申诉
111 浏览量
2022-09-22
14:37:57
上传
评论
收藏 42KB ZIP 举报
weixin_42651887
- 粉丝: 77
- 资源: 1万+
最新资源
- 基于C# winform+mysql人事工资管理系统源码+sql文件+运行说明.zip
- 基于Java web搭建的一个简易博客网站源码.rar
- 基于Java web搭建的一个简易博客网站源码.zip
- 基于C#+MySql实现的药品销售库存信息管理系统源码+数据库+项目说明.zip
- mysql 5.7.15 安装配置方法图文教程.zip
- 基于springboot websocket 定制,主要完成的功能是WebSocket的状态管理,具备单机和集群能力.zip
- SpringBoot框架示例:整合SpringMVC、MyBatis、安全框架Shiro、页面布局框架Sitemesh.zip
- SpringBoot集成thumbnailator图片压缩.zip
- SpringBoot发送邮件神器,只需简单配置即可,支持自定义模板.zip
- SpringBoot的定时调用的加强工具,实现定时任务动态管理,后续加入可视化管理、调度日志、集群任务统一管理.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈