Files
FAR_CS/0 - example/wzk - 目标检测/node_detect.m
T
2024-11-11 16:32:53 +08:00

87 lines
1.5 KiB
Matlab

clc
clear
close all;
SNR = 10;
sigma_n = 0.1;
P_fa = [1e-5, 5e-5, 1e-4, 5e-4, 1e-3, 5e-3, 1e-2, 5e-2, 1e-1, 5e-1, 1];
len_P_fa = length(P_fa);
h0_rep_time = 99 * 1e4;
h1_rep_time = 1e5;
% h0_rep_time = 1000;
% h1_rep_time = 1000;
a = sqrt(10^(SNR/10) * sigma_n^2);
P_fa_node_cnt = zeros(len_P_fa, h0_rep_time);
parfor rep = 1: h0_rep_time
% for rep = 1: h0_rep_time
%% 噪声处理
noise = random('Normal', 0, sigma_n/sqrt(2), 1, 1) + 1j * random('Normal', 0, sigma_n/sqrt(2), 1, 1);
y = noise;
stat = abs(y)^2;
kd = sigma_n^2 * chi2inv(1 - P_fa, 2) / 2;
for cnt_h_th = 1: len_P_fa
P_fa_node_cnt(cnt_h_th, rep) = stat > kd(cnt_h_th);
end
fprintf('Pfa-%d\n', rep);
end
P_fa_node = mean(P_fa_node_cnt, 2);
figure(1)
loglog(P_fa,P_fa_node)
title('Pfa')
P_d_node_cnt = zeros(len_P_fa, h1_rep_time);
parfor rep = 1: h1_rep_time
% for rep = 1: h1_rep_time
%% 噪声处理
noise = random('Normal', 0, sigma_n/sqrt(2), 1, 1) + 1j * random('Normal', 0, sigma_n/sqrt(2), 1, 1);
y = a + noise;
stat = abs(y)^2;
kd = sigma_n^2 * chi2inv(1 - P_fa, 2) / 2;
for cnt_h_th = 1: len_P_fa
P_d_node_cnt(cnt_h_th, rep) = stat > kd(cnt_h_th);
end
fprintf('Pd-%d\n', rep);
end
P_d_node = mean(P_d_node_cnt, 2);
figure(2)
loglog(P_fa,P_d_node)
title('Pd')
figure(3)
loglog(P_fa_node,P_d_node)
title('ROC')
save node_detect.mat ...
SNR...
P_fa...
P_fa_node...
P_d_node...
sigma_n...
h0_rep_time...
h1_rep_time...
a;