print(r'Noise level: {0:.2e}'.format(noise_level)) print(r'Minimum approximation error |a - Gb|_2: {0:.2e}'.format(min_error)) # reconstruct Diracs' locations tk z = np.roots(c_opt) z = z / np.abs(z) tk_recon = np.real(tau * 1j / (2 * np.pi) * np.log(z)) tk_recon = np.sort(tk_recon - np.floor(tk_recon / tau) * tau) # reconstruct amplitudes ak Phi_recon = periodicSinc( np.pi * B * (np.reshape(t_samp, (-1, 1), order='F') - np.reshape(tk_recon, (1, -1), order='F')), B * tau) ak_recon = np.real(linalg.lstsq(Phi_recon, y_ell)[0]) # location estimation error t_error = distance(tk_recon, tk)[0] # plot reconstruction plt.close() fig = plt.figure(num=1, figsize=(5.5, 2.5), dpi=90) # sub-figure 1 ax1 = plt.axes([0.125, 0.59, 0.85, 0.31]) markerline211_1, stemlines211_1, baseline211_1 = \ ax1.stem(tk, ak, label='Original Diracs') plt.setp(stemlines211_1, linewidth=1.5, color=[0, 0.447, 0.741]) plt.setp(markerline211_1, marker='^', linewidth=1.5, markersize=8, markerfacecolor=[0, 0.447, 0.741], mec=[0, 0.447, 0.741]) plt.setp(baseline211_1, linewidth=0)
Ihat_omega_ell_noisy, K_est, tau1, tau2, sympy.Rational(15, 12), sympy.Rational(15, 12), omega_ell, M_N[0], M_N[1], noise_level, max_ini, stop_cri, num_rotation=12) # calculate reconstruction error r_est_error, index = distance(xk + 1j * yk, xk_recon + 1j * yk_recon) xk = xk[index[:, 0]] yk = yk[index[:, 0]] alpha_k = alpha_k[index[:, 0]] xk_recon = xk_recon[index[:, 1]] yk_recon = yk_recon[index[:, 1]] alpha_k_recon = np.real(alpha_k_recon[index[:, 1]]) # order the results for the ease of comparison ind_order = np.argsort(xk) fri_recon_all[realisations, :] = np.hstack( (np.reshape(xk_recon[ind_order], (1, K), order='F'), np.reshape(yk_recon[ind_order], (1, K), order='F'), np.reshape(alpha_k_recon[ind_order], (1, K), order='F'), np.reshape(r_est_error, (1, 1), order='F'))) print('Position estimation error: {0:.2e}\n').format(r_est_error)
P = 5 noise = np.random.randn(L) + 1j * np.random.randn(L) noise = noise / linalg.norm(noise) * linalg.norm(Xomega_ell) * 10**(-P / 20.) Xomega_ell_noisy = Xomega_ell + noise # noise energy, in the noiseless case 1e-14 is considered as 0 noise_level = np.max([1e-14, linalg.norm(noise)]) max_ini = 50 # maximum number of random initialisations tk_ref, ak_recon, Xomega_Uniform_ref = \ dirac_recon_irreg_fourier(Xomega_ell_noisy, K, tau, omega_ell, M, noise_level, max_ini, stop_cri, interp_kernel) # location estimation error t_error = distance(tk_ref, tk)[0] # plot reconstruction plt.close() fig = plt.figure(num=1, figsize=(5, 4), dpi=90) subplt_height = 0.2 subplt_width = 0.87 subplt_left_corner = 0.115 # sub-figure 1 ax1 = plt.axes([subplt_left_corner, 0.71, subplt_width, subplt_height]) markerline311_1, stemlines311_1, baseline311_1 = ax1.stem( tk, ak, label='Original Diracs') plt.setp(stemlines311_1, linewidth=1.5, color=[0, 0.447, 0.741]) plt.setp(markerline311_1, marker='^',
noise_level = np.max([1e-10, linalg.norm(noise)]) taus = np.array([tau1, tau2]) omega_ell = np.column_stack((omega_ell_x, omega_ell_y)) tic = time.time() num_rotation = 12 xk_recon, yk_recon, alpha_k_recon = \ recon_2d_dirac(Ihat_omega_ell_noisy, K_est, tau1, tau2, sympy.Rational(15, 12), sympy.Rational(15, 12), omega_ell, M, N, noise_level, max_ini, stop_cri, num_rotation) toc = time.time() print('Average time: {0:.2f}[sec]'.format((toc - tic) / num_rotation)) # calculate reconstruction error r_est_error = distance(xk + 1j * yk, xk_recon + 1j * yk_recon)[0] print('Position estimation error: {0:.2e}\n'.format(r_est_error)) # plot results file_name_loc = (r'./result/TSP_eg4_K_{0}_L_{1}_' + r'noise_{2}dB_locations.' + fig_format).format(repr(K), repr(L), repr(P)) plot_2d_dirac_loc(xk_recon, yk_recon, alpha_k_recon, xk, yk, alpha_k, K, L, P, tau1, tau2, save_figure=True, fig_format=fig_format, file_name=file_name_loc) file_name_spec = (r'./result/TSP_eg4_K_{0}_L_{1}_' + r'noise_{2}dB_spectrum').format(repr(K), repr(L), repr(P)) plot_2d_dirac_spec(xk_recon, yk_recon, alpha_k_recon, Ihat_omega_ell_noisy, Ihat_omega_ell, omega_ell_x, omega_ell_y, M, N, P, L, save_figure=True, fig_format=fig_format, file_name=file_name_spec, show_dirty_img=True, dirty_img=dirty_img)