Add "FAR vs PD"

This commit is contained in:
Ksyer
2024-05-11 15:43:25 +08:00
parent 17386d80c1
commit b48ab07dd0
21 changed files with 412 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
%% 参数设置
N = 16;
M = 4;
A = get_Psi(N, M, 0);
%% 检查每一行 / 列的二范数
col_norms = zeros(N, 1);
for i = 1: N
col_norms(i) = norm(A(i, :), 2);
end
row_norms = zeros(N * M, 1);
for i = 1: N * M
row_norms(i) = norm(A(:, i), 2);
end
figure(1);
subplot(211);
plot(1: N, col_norms);
xlabel("Col");
ylabel("L2 norm of col");
title("L2 norm of cols");
subplot(212);
plot(1: N * M, row_norms);
xlabel("Row");
ylabel("L2 norm of row");
title("L2 norm of rows");
%%
AH = conj(A).';
figure(2);
result = abs(A * AH);
subplot(211);
plot(diag(result));
subplot(212);
heatmap(result);
a = sum(result(:)) - sum(diag(result));
fprintf("%f", a);
+72
View File
@@ -0,0 +1,72 @@
function P_fa = FAR_simu(threshold)
global N M epi trail_times
% Define measurement matrix
A = get_Psi(N, M, epi);
% Define sparse vector x
[Lambda, x] = get_sparse_vector(N * M, 1);
Lambda_C = setdiff(1:N*M, Lambda);
% Try "trail_times" times
NN = N;
results = zeros(trail_times, N * M);
if exist("FAR_recovery_1_LASSO_5.mat")
load("FAR_recovery_0_debiasedLASSO_500.mat", "results");
else
for T = 1: trail_times
% y = Ax + n
n = randn(NN, 1) * 0.1;
y_noise = A * x + n;
% x_hat = CS(A, y)
x_hat = recovery(A, y_noise);
results(T, :) = x_hat;
end
end
% Distribute of H_0 and H_1
H_0_distribute = zeros(1, length(Lambda_C));
H_1_distribute = zeros(1, length(Lambda));
i1 = 1;
i2 = 1;
Ts = [];
for t = 1: trail_times
x_hat = results(t, :);
T = 0;
for i = 1: length(x)
if ismember(i, Lambda_C)
H_0_distribute(i1) = x_hat(i);
i1 = i1 + 1;
elseif ismember(i, Lambda)
T = T + abs(x_hat(i));
H_1_distribute(i2) = x_hat(i);
i2 = i2 + 1;
end
end
Ts = [Ts T];
end
% Draw
figure(1)
subplot(2, 1, 1);
title("Freq histogram of H_0");
histfit(real(H_0_distribute));
subplot(2, 1, 2);
title("Freq histogram of H_1");
histfit(real(H_1_distribute));
H_0_mean = mean(H_0_distribute);
H_0_std = std(H_0_distribute);
H_1_mean = mean(H_1_distribute);
H_1_std = std(H_1_distribute);
fprintf("H_0: mu = %f, std = %f\n", H_0_mean, H_0_std);
fprintf("H_1: mu = %f, std = %f\n", H_1_mean, H_1_std);
% P_fa = normcdf(threshold, H_0_mean, H_0_std);
end
+27
View File
@@ -0,0 +1,27 @@
clear; clc;
%% 参数设置
global N M lambda tau iter_max method trail_times epi extend_target K;
N = 64;
M = 4;
K = 10;
lambda = zeros(M * N, 1);
lambda(:) = 0.3;
tau = 1e-4;
iter_max = 500;
% method = "debiased_LASSO";
% method = "LASSO";
method = "BP";
% method = "VAMP";
trail_times = 1e2;
epi = 0;
extend_target = 1;
%% FAR
P_fa_FAR = FAR_simu(3);
% fprintf("FAR: %f\n", P_fa_FAR);
%% PD
P_fa_PD = PD_simu(1);
fprintf("PD: %f\n", P_fa_PD);
+73
View File
@@ -0,0 +1,73 @@
function P_fa = PD_simu(threshold)
global N method trail_times
% Define measurement matrix
B = dftmtx(N);
% Define sparse vector z
[Lambda, z] = get_sparse_vector(N, 1);
Lambda_C = setdiff(1:N, Lambda);
results = zeros(trail_times, N);
% Calcuate test statistics
P2 = [];
if exist("PD_recovery_0_debiasedLASSO_500.mat")
load("PD_recovery_1_debiasedLASSO_500.mat", "results");
else
for T = 1: trail_times
% y = Bz + n
n = randn(N, 1) * 0.1;
y_noise = n;
% z_hat = CS(B, y)
z_hat = recovery(B, y_noise);
% Calculate test statistic
results(T, :) = z_hat;
end
end
% Distribute of H_0 and H_1
H_0_distribute = zeros(1, length(Lambda_C));
H_1_distribute = zeros(1, length(Lambda));
i1 = 1;
i2 = 1;
Ts = [];
for t = 1: trail_times
z_hat = results(t, :);
T = 0;
for i = 1: length(z)
if ismember(i, Lambda_C)
H_0_distribute(i1) = z_hat(i);
i1 = i1 + 1;
elseif ismember(i, Lambda)
T = T + abs(z_hat(i));
H_1_distribute(i2) = z_hat(i);
i2 = i2 + 1;
end
end
Ts = [Ts T];
end
% Draw
figure(2)
subplot(2, 1, 1);
title("Freq histogram of H_0");
histfit(real(H_0_distribute));
subplot(2, 1, 2);
title("Freq histogram of H_1");
histfit(real(H_1_distribute));
H_0_mean = mean(H_0_distribute);
H_0_std = std(H_0_distribute);
H_1_mean = mean(H_1_distribute);
H_1_std = std(H_1_distribute);
fprintf("H_0: mu = %f, std = %f\n", H_0_mean, H_0_std);
fprintf("H_1: mu = %f, std = %f\n", H_1_mean, H_1_std);
% P_fa = normcdf(threshold, H_0_mean, H_0_std);
end
+16
View File
@@ -0,0 +1,16 @@
# 频率捷变雷达和单载频雷达的性能对比分析
本项目用于分析频率捷变雷达和单载频雷达的性能。
频率捷变雷达的观测矩阵满足行正交性质,利用这一性质,可以使用 cVAMPro 算法作为压缩感知恢复算法,通过观测检测出目标。
For simplicity, we denote Psi as the measurement matrix for FAR.
Code structure:
- Analyze_of_Psi.m: Verify the row orthonormal properity of Psi
- cVAMPro.m: cVAMPro recovery algorithm
- get_Psi.m: Generate Psi.
- FAR_simu.m: Simulate P_fd in FAR.
- PD_simu.m: Simulate P_fd in PD.
- Main.m: The entry of simulation.
+82
View File
@@ -0,0 +1,82 @@
% Input: y,A,lambda,tau,Kit
% Output: x_hat_wl,x_hat_d
% Main structure of cVAMP
function [x_hat_wl, x_hat_d] = cVAMPro(y, A, lambda, tau, Kit)
% Initialization
[M, N] = size(A);
gamma = M / N;
k = 0;
p = ctranspose(A) * y;
h_1 = p;
Q_1 = gamma;
tau_d = 1;
% Iteration
while ((k < Kit) && (tau_d > tau))
% Factorized Part
x_1 = ST(h_1, lambda, Q_1);
chi_1 = F1(x_1, lambda, Q_1);
% Message Passing
h_2 = x_1 / chi_1 - h_1;
Q_2 = 1 / chi_1 - Q_1;
% Gaussian Part
t1 = (p + h_2) / Q_2;
t2 = ctranspose(A) * (A * (p + h_2)) / ((Q_2 + 1) * Q_2);
x_2 = t1 - t2;
chi_2 = gamma / (Q_2 + 1) + (1 - gamma) / Q_2;
% Message Passing
h_1_next = x_2 ./ chi_2 - h_2;
Q_1_next = 1 / chi_2 - Q_2;
tau_d = norm(h_1_next - h_1, Inf) / norm(h_1_next, Inf);
k = k + 1;
% output
x_hat_wl = x_1;
x_hat_d = h_1_next / Q_1_next;
% next
h_1 = h_1_next;
Q_1 = Q_1_next;
end
end
% SoftThreshold function
function x = ST(h_1, lambda, Q_1)
[N, M] = size(h_1);
x = zeros(N, M);
for i = 1:N
sign = h_1(i) ./ abs(h_1(i));
diff = abs(h_1(i)) - lambda(i);
x(i) = sign .* (diff ./ Q_1) .* SF(diff);
end
end
% Heaviside's step function
function v = SF(a)
if a > 0
v = 1;
elseif a == 0
v = 0; % at zero points
else
v = 0;
end
end
% Calculation of chi_1
function chi_1 = F1(x_1, lambda, Q_1)
[N, M] = size(x_1);
count = 0;
for i = 1:N
temp = Q_1 * abs(x_1(i)) + lambda(i);
count = count + (2 - lambda(i) / temp) * SF(abs(x_1(i)));
% count = count + (2-lambda(i)/temp) * (abs(x_1(i)) > 1e-4);
end
chi_1 = count / (2 * N * Q_1);
end
+11
View File
@@ -0,0 +1,11 @@
{
"N": 64,
"M": 4,
"K": 10,
"method": "debiased_LASSO",
"trail_times": 5e2,
"extend_target": true,
"debiased_LASSO_params": {
}
}
+11
View File
@@ -0,0 +1,11 @@
function Psi = get_Psi(N, M, epi)
Psi = zeros(N,M*N);
for n = 0 : N-1
Cn = floor(rand()*M);
for q = 0 : N-1
for p = 0:M-1
Psi(n+1,q*M+p+1) = exp(1i*2*pi*p/M*Cn+1i*2*pi*q/N*n*(1+Cn*epi)) / sqrt(N);
end
end
end
end
+13
View File
@@ -0,0 +1,13 @@
function [indices, z] = get_sparse_vector(N, Amp)
global K extend_target;
z = zeros(N, 1);
if extend_target
target_start_idx = fix(0.4 * N);
target_size = K;
indices = target_start_idx: target_start_idx + target_size;
else
indices = randperm(N, K);
end
z(indices) = Amp;
end
+53
View File
@@ -0,0 +1,53 @@
function x_hat = recovery(A, y_noise)
global method
if method == "debiased_LASSO"
sz = size(A);
N = sz(2);
LASSO_lambda = 2;
gamma = sz(1) / sz(2);
cvx_begin quiet
variable x_LASSO(N) complex
minimize(LASSO_lambda * norm(x_LASSO, 1) + norm(y_noise - A * x_LASSO, 2))
cvx_end
rho_active = sum(abs(x_LASSO) > 1e-3)/N;
Q_hat = (gamma - rho_active)/(1 - rho_active);
Rho = sum((abs(x_LASSO) > 1e-3).* (2 - LASSO_lambda./(Q_hat*abs(x_LASSO) + LASSO_lambda))) / 2 / N;
diff = 1;
while(diff > 1e-4)
Rho_pre = Rho;
Rho = sum((abs(x_LASSO) > 1e-3).* (2 - LASSO_lambda./((gamma-Rho)/(1-Rho)*abs(x_LASSO) + LASSO_lambda))) / 2 / N;
diff = abs(Rho - Rho_pre);
end
Q_hat = (gamma-Rho)/(1-Rho);
x_d_CROD = x_LASSO + A'*(y_noise - A*x_LASSO)/Q_hat;
x_hat = x_d_CROD;
elseif method == "LASSO"
sz = size(A);
N = sz(2);
LASSO_lambda = 1;
cvx_begin quiet
variable x_LASSO(N) complex
minimize(LASSO_lambda * norm(x_LASSO, 1) + norm(y_noise - A * x_LASSO, 2))
cvx_end
x_hat = x_LASSO;
elseif method == "BP"
sz = size(A);
N = sz(2);
cvx_begin quiet
variable x_hat(N) complex
minimize(norm(x_hat, 1))
subject to
A * x_hat == y_noise
cvx_end
else
global lambda tau iter_max;
[x_hat, z_hat_d] = cVAMPro(y_noise, A, lambda, tau, iter_max);
end
end
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

+12
View File
@@ -0,0 +1,12 @@
clc;
clear;
N = 100;
F = dftmtx(N);
F_inv = inv(F);
result = zeros(N);
for i = 1: N
for j = 1: N
result(i, j) = F_inv(i,:) * conj(F_inv(j,:))';
end
end