Update Expr3

This commit is contained in:
Ksyer
2023-12-20 10:24:50 +08:00
parent f7ceea0be7
commit 0ce20fbca2
4 changed files with 25 additions and 168 deletions
@@ -1,72 +0,0 @@
% Expr2.m to draw Fig 3(a)
clc;
clear;
M = 4;
N = 128;
rate = 0.02; % \Delta f / f_c = 0.02
beta = 1;
max_n = 125;
max_k = 25;
trials_time = 50;
prob = zeros(max_n, max_k);
rng(1)
Phi_far = zeros(N, N * M);
C = randi([1, M], 1, N);
xi = 1 + 0.02 * C;
% for i = 1:N
%
% Phi_x = zeros(N, M);
%
% for p = 1:M
%
% for q = 1:N
% range = ((p - 1) * C(i)) / M; % p start from 0 or 1?
% doppler = ((q - 1) * (i - 1) * xi(i)) / N; % q start from 0 or 1?
% Phi_x(q, p) = exp(1j * 2 * pi * (range + doppler)) / sqrt(N);
% end
%
% end
%
% % t == ctranspose(Phi_x(:,1)) * Phi_x(:,1) == 1
% Phi_far(:, (i - 1) * M + 1:i * M) = Phi_x;
%
% end
for i = 1:n
for j = 1:m
n = 60;
k = 5;
s = beta * k * M;
x = 0;
for t = 1:trials_time
x = x + Expr3_can_recovery(Phi_far, N, M, n, s, eps);
end
disp(x);
for n = 1:max_n
parfor k = 1:max_k
s = beta * k * M;
x = 0;
for t = 1:trials_time
x = x + Expr3_can_recovery(Phi_far, N, M, n, s, eps);
end
prob(n, k) = x / trials_time;
end
end
save("Expr3.mat", "prob");
+9 -23
View File
@@ -4,12 +4,12 @@ clear;
M = 4; M = 4;
N = 128; N = 128;
rate = 0.02; % \Delta f / f_c = 0.02 epi = 0.02; % \Delta f / f_c = 0.02
beta = 1; beta = 1;
max_n = 125; max_n = 125;
max_k = 25; max_k = 25;
trials_time = 10; trials_time = 5;
eps = 1e-5; eps = 1e-5;
prob = zeros(max_n, max_k); prob = zeros(max_n, max_k);
@@ -18,32 +18,18 @@ rng(1)
Phi_far = zeros(N, N * M); Phi_far = zeros(N, N * M);
C = randi([0, M-1], 1, N); for n = 0:N - 1
vecn = 0:N-1; Cn = floor(rand() * M);
xi = 1 + rate .* C;
for i = 1:N for q = 0:N - 1
for j = 1:M
t = (i-1)*M+j; for p = 0:M - 1
temp = 1/sqrt(N) .* exp(1j * 2 * pi + (j-1) / M .* C + 1j * 2 * pi * (i-1)/N .* vecn .* xi); Phi_far(n + 1, q * M + p + 1) = exp(1i * 2 * pi * p / M * Cn + 1i * 2 * pi * q / N * n * (1 + Cn * epi));
Phi_far(:, t) = temp;
end
disp(ctranspose(Phi_far(:,1)) * Phi_far(:,1))
end end
% n = 60; 0
n = 70;
k = 7;
s = beta * k * M;
x = 0;
for t = 1:trials_time
x = x + Expr3_can_recovery(Phi_far, N, M, n, s, eps);
end end
disp(x);
end
for n = 1:max_n for n = 1:max_n
@@ -1,43 +0,0 @@
function flg = Expr3_can_recovery(Phi_far, N, M, n, s, eps)
Phi = zeros(n, N * M);
indices = randperm(N, n);
for i = 1:n
Phi(i, :) = Phi_far(indices(i), :);
end
d = M*N;
x = zeros(d, 1);
random_indices = randperm(d, s);
x(random_indices) = randn(s, 1);
x = sign(x);
for i = 1:M * N
if x(i) ~= 0
t = rand(1) * 2 * pi;
x(i) = cos(t) + 1j * sin(t);
end
end
y = Phi * x;
cvx_begin quiet
variable s1(d) complex
minimize(norm(s1, 1))
subject to
norm(y - Phi * s1) <= eps
cvx_end
x = sign(real(x));
s1 = real(s1);
p = norm(x - s1, 2);
disp(p);
if p < eps
flg = 1;
else
flg = 0;
end
end
@@ -1,39 +1,25 @@
function flg = Expr3_can_recovery(Phi_far, N, M, n, s, eps) function flg = Expr3_can_recovery(Phi_far, N, M, n, s, eps)
Phi = zeros(n, N * M);
indices = randperm(N, n);
for i = 1:n % select random n cols
Phi(i, :) = Phi_far(indices(i), :); col_choose = randperm(N, n);
end Phi = Phi_far(col_choose, :);
d = M*N;
x = zeros(d, 1);
random_indices = randperm(d, s);
x(random_indices) = randn(s, 1);
x = sign(x);
for i = 1:M * N % generate sparse signal
sparse_signal = zeros(M, N);
block = randperm(N, s);
sparse_signal(:, block) = exp(1i * 2 * pi * rand(M, s));
if x(i) ~= 0 % generate y
t = rand(1) * 2 * pi; y = Phi * sparse_signal(:);
x(i) = cos(t) + 1j * sin(t);
end
end
y = Phi * x;
cvx_begin quiet cvx_begin quiet
variable s1(d) complex variable x(M * N) complex
minimize(norm(s1, 1)) minimize(norm(x, 1))
subject to subject to
norm(y - Phi * s1) <= eps Phi * x == y
cvx_end cvx_end
x = sign(real(x)); p = norm(x - sparse_signal(:), 2);
s1 = real(s1);
p = norm(x - s1, 2);
disp(p);
if p < eps if p < eps
flg = 1; flg = 1;