Add Example

This commit is contained in:
Ksyer
2024-11-11 16:32:53 +08:00
parent a2cb6d1825
commit 29ae9585f9
56 changed files with 4029 additions and 0 deletions
@@ -0,0 +1,71 @@
% PRF: pulse repetition frequency
% B: bandwidth
% fs: sampling rate
% D: duty ratio
% gamma: compression ratio
% A: chirp matrix
% signal_t: transmitting beam
function [ A, signal_t ] = generate_chirp_mtx(PRF, B, fs, D, gamma, sign_mid)
% parameters
if nargin < 5
gamma = 0.5;
end
if nargin < 6
sign_mid = 0;
end
Tr = 1 / PRF;
Tp = Tr * D;
K = B / Tp;
% generate_signal
N = Tr * fs;
N_high = Tp * fs;
N_mtx = round(N / gamma);
signal_t = zeros(1, N);
for i = 1: N_high
tp = i * (1 / fs) - sign_mid * N_high / fs / 2;
signal_t(1, i) = exp(1j * 2 * pi * 0.5 * K * tp .^ 2);
end
signal_t_2fs = zeros(1, N_mtx);
for i = 1: round(N_high / gamma)
tp = (i+1) * (1 / fs / 2) - sign_mid * N_high / fs / 2;
signal_t_2fs(1, i) = exp(1j * pi * K * tp .^ 2);
end
% generate chirp matrix
A = generate_matrix_by_signal2fs(transpose(signal_t_2fs));
end
function [ mtx ] = generate_matrix_by_signal2fs(signal)
mtx = [];
l = round(length(signal) / 2);
temp1 = signal(1:2:end);
temp2 = circshift(signal(2:2:end), 1);
if length(temp2) ~= length(temp1)
temp2 = [temp2; 0];
end
for i = 1:l
t1 = circshift(temp1, i-1);
t2 = circshift(temp2, i-1);
if i - 1 > 0
t1(1:i - 1,1) = 0;
end
if i - 1 > 0
t2(1:i - 1,1) = 0;
end
mtx = [mtx,t1,t2];
end
end
@@ -0,0 +1,87 @@
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;
@@ -0,0 +1,87 @@
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;
@@ -0,0 +1,42 @@
clear;
close all;
clc;
load node_detect.mat;
Fontsize = 18;
plot_width = 850;
plot_height = 600;
Linewidth = 2;
Markersize = 8;
%% plot
figure(1);
loglog(P_fa, P_fa_node, '-o', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
grid on;
legend('SNR = 10dB');
xlabel('P_{fa} Set');
ylabel('Actual P_{fa}');
ylim([1e-5,1]);
set(gca, 'FontSize', Fontsize);
title('P_{fa}')
set(gcf, 'position', [200, 300, plot_width, plot_height]);
set(gca,'fontsize',20,'fontname','Times');
figure(3);
semilogx(P_fa_node, P_d_node, '-o', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
grid on;
legend('SNR = 10dB');
xlabel('Actual P_{fa}');
ylabel('P_{d}');
xlim([9.99e-6,1]);
set(gca, 'FontSize', Fontsize);
title('ROC')
set(gcf, 'position', [200, 300, plot_width, plot_height]);
set(gca,'fontsize',20,'fontname','Times');