diff --git a/basic/cVAMPro.m b/basic/cVAMPro.m index 4afe60e..adfe6cd 100755 --- a/basic/cVAMPro.m +++ b/basic/cVAMPro.m @@ -46,7 +46,11 @@ function x = ST(h_1, lambda, Q_1) x = zeros(N, M); for i = 1:N - sign = h_1(i) ./ abs(h_1(i)); + if h_1(i) == 0 + sign = 1; + else + sign = h_1(i) ./ abs(h_1(i)); + end diff = abs(h_1(i)) - lambda; x(i) = sign .* (diff ./ Q_1) .* SF(diff); end diff --git a/basic/get_Psi.m b/basic/get_Psi.m index 714e344..91421c4 100755 --- a/basic/get_Psi.m +++ b/basic/get_Psi.m @@ -1,15 +1,31 @@ -function Psi = get_Psi(N, M, epi) +function [C_n, Psi] = get_Psi(N, M, epi) + if nargin == 2 + epi = 0; + end + k = 1 / sqrt(M * N); + C_n = zeros(M, 1); + + % Determined code 1 + % C_n = repelem(0:M-1, N/M); + + % Determined code 2 + % C_n = repmat(0:M-1, 1, N/M); + + % Determined code 3 + C_n = repmat(0:M-1, 1, N/M); + C_n = C_n(randperm(length(C_n))); + Psi = zeros(N,M*N); for n = 0 : N-1 col = zeros(1, M*N); - Cn = floor(rand()*M); + % C_n(n+1) = floor(rand()*M); for q = 0 : N-1 for p = 0:M-1 - f1 = p/M*Cn; - f2 = q/N*n*(1+Cn*epi); + f1 = p/M*C_n(n+1); + f2 = q/N*n*(1+C_n(n+1)*epi); col(q*M+p+1) = exp(1j*2*pi*(f1 + f2)); end end - Psi(n+1, :) = col; + Psi(n+1, :) = col * k; end end diff --git a/basic/get_Psi_sample.m b/basic/get_Psi_sample.m new file mode 100755 index 0000000..fdb497e --- /dev/null +++ b/basic/get_Psi_sample.m @@ -0,0 +1,89 @@ +function [s_T, A, freqs] = FAR_signal_model_sample(FAR_N, FAR_M) + global c f_c N N_wide B ranges_wide betas_wide FIGURE numP f_s N_high T_r T_p TEST method; + + pulse_number = FAR_N; + single_pulse_length = N; + all_pulse_length = single_pulse_length * pulse_number; + pulse_width = N_high; + + delta_f = B / FAR_M; + delta_r = c / (2 * B); + delta_v = c / (2 * f_c * FAR_N * T_r); + + ranges = (0: FAR_M - 1) * delta_r; + velos = (0: FAR_N - 1) * delta_v; + delays = 2 * ranges / c; + + t_single = (0: 1/f_s: T_p-1/f_s)'; + t = (0: 1/f_s: FAR_N * T_r-1/f_s)'; + s_T = zeros(length(t), 1); + T_p_N = floor(T_p * f_s); + T_r_N = floor(T_r * f_s); + + freqs = zeros(FAR_N, 1); + for i = 1: FAR_N + C_n = floor(rand() * FAR_M); + freqs(i) = f_c + C_n * delta_f; + % freqs(i) = f_c + i * delta_f; + end + + for i = 1: FAR_N + N_l = (i - 1) * T_r_N + 1; + N_r = (i - 1) * T_r_N + T_p_N; + s_T(N_l:N_r) = exp(1j * 2 * pi * freqs(i) * t_single); + end + + % echo + s_R = zeros(length(s_T), FAR_M, FAR_N); + s_D = zeros(length(s_T), FAR_M, FAR_N); + for range_idx = 1: FAR_M % R + r = ranges(range_idx); + for doppler_idx = 1: FAR_N % D + v = velos(doppler_idx); + f_n = freqs(doppler_idx); + for pulse_idx = 1: FAR_N % N + nT_r = (pulse_idx - 1) * T_r; + rr = r + v * nT_r; + delay = 2 * rr / c; + t_l = delay + nT_r; + N_l = max(1, round(t_l * f_s) + 1); + N_r = N_l + T_p_N - 1; + + s_D(N_l: N_r, range_idx, doppler_idx) = exp(-1j * 2 * pi * f_n * (2 / c) * (r + v * (nT_r + t_single))); + end + end + end + + % Sampling + A = zeros(FAR_N, FAR_N * FAR_M); + for range_idx = 1: FAR_M % R + for doppler_idx = 1: FAR_N % D + index = (doppler_idx - 1) * FAR_M + range_idx; + for pulse_idx = 1: FAR_N % N + t_sample = delays(range_idx) + T_p + (pulse_idx - 1) * T_r; + A(pulse_idx, index) = s_D(round(t_sample * f_s), range_idx, doppler_idx); + end + end + end + A = get_Psi(FAR_N, FAR_M, 0); + AAH = A * A'; + A = A ./ sqrt(AAH(1, 1)); + + if 1 == 0 + Lambda = 1:10; + x_wide = zeros(N_wide, 1); + x_wide(Lambda) = 1; + n_wide = randn(length(s_T_FAR), 1) * 0.01; + y = A_wide * x_wide; + y_noise = y + n_wide; + x_hat = recovery(A_wide, y_noise, method); + + figure(1); + subplot(211); plot(abs(x_wide)); + subplot(212); plot(abs(x_hat)); + + figure(2); + subplot(311); plot(real(A_wide * x_wide)); + subplot(312); plot(real(A_wide * x_hat)); + subplot(313); plot(real(A_wide * (x_wide - x_hat))); + end diff --git a/basic/narrow_signal_model_sample.m b/basic/narrow_signal_model_sample.m new file mode 100755 index 0000000..c958c20 --- /dev/null +++ b/basic/narrow_signal_model_sample.m @@ -0,0 +1,87 @@ +function [s_T, A] = narrow_signal_model_sample(FAR_N) + FAR_M = 1; + global c f_c N N_wide B ranges_wide betas_wide FIGURE numP f_s N_high T_r T_p TEST method; + + pulse_number = FAR_N; + single_pulse_length = N; + all_pulse_length = single_pulse_length * pulse_number; + pulse_width = N_high; + + delta_f = 0; + delta_r = T_p * c / 2; + delta_v = c / (2 * f_c * FAR_N * T_r); + + ranges = (0: FAR_M - 1) * delta_r; + velos = (0: FAR_N - 1) * delta_v; + delays = 2 * ranges / c; + + t_single = (0: 1/f_s: T_p-1/f_s)'; + t = (0: 1/f_s: FAR_N * T_r-1/f_s)'; + s_T = zeros(length(t), 1); + T_p_N = floor(T_p * f_s); + T_r_N = floor(T_r * f_s); + + freqs = zeros(FAR_N, 1); + for i = 1: FAR_N + C_n = floor(rand() * FAR_M); + freqs(i) = f_c + C_n * delta_f; + % freqs(i) = f_c + i * delta_f; + end + + for i = 1: FAR_N + N_l = (i - 1) * T_r_N + 1; + N_r = (i - 1) * T_r_N + T_p_N; + s_T(N_l:N_r) = exp(1j * 2 * pi * freqs(i) * t_single); + end + + % echo + s_R = zeros(length(s_T), FAR_M, FAR_N); + s_D = zeros(length(s_T), FAR_M, FAR_N); + for range_idx = 1: FAR_M % R + r = ranges(range_idx); + for doppler_idx = 1: FAR_N % D + v = velos(doppler_idx); + f_n = freqs(doppler_idx); + for pulse_idx = 1: FAR_N % N + nT_r = (pulse_idx - 1) * T_r; + rr = r + v * nT_r; + delay = 2 * rr / c; + t_l = delay + nT_r; + N_l = max(1, round(t_l * f_s) + 1); + N_r = N_l + T_p_N - 1; + + s_D(N_l: N_r, range_idx, doppler_idx) = exp(-1j * 2 * pi * f_n * (2 / c) * (r + v * (nT_r + t_single))); + end + end + end + + % Sampling + A = zeros(FAR_N, FAR_N * FAR_M); + for range_idx = 1: FAR_M % R + for doppler_idx = 1: FAR_N % D + index = (doppler_idx - 1) * FAR_M + range_idx; + for pulse_idx = 1: FAR_N % N + t_sample = delays(range_idx) + T_p + (pulse_idx - 1) * T_r; + A(pulse_idx, index) = s_D(round(t_sample * f_s), range_idx, doppler_idx); + end + end + end + + if 1 == 0 + Lambda = 1:10; + x_wide = zeros(N_wide, 1); + x_wide(Lambda) = 1; + n_wide = randn(length(s_T_FAR), 1) * 0.01; + y = A_wide * x_wide; + y_noise = y + n_wide; + x_hat = recovery(A_wide, y_noise, method); + + figure(1); + subplot(211); plot(abs(x_wide)); + subplot(212); plot(abs(x_hat)); + + figure(2); + subplot(311); plot(real(A_wide * x_wide)); + subplot(312); plot(real(A_wide * x_hat)); + subplot(313); plot(real(A_wide * (x_wide - x_hat))); + end