def mcm_mvdr_comp(env, rmin, rmax, grid_dr, r0, v_grid, T, num_synth_els, K_true, folder, fname, rs, zs, f_err=0): """ Compare MCM and MVDR processor, using assumed source velocity as constraint points Input env """ K_true = K_true.reshape(1, K_true.shape[0], K_true.shape[1]) wn_gain = -3 fig, axis = plt.subplots(1, 1) plt.suptitle('Compare MCM and WNC output at the correct source depth') axis.set_xlabel('Range (m)') axis.set_ylabel('WNC output (dB)') for i, v in enumerate(v_grid): r, z, synth_replicas = form_replicas(env, rmin, rmax, grid_dr, v, T, num_synth_els, folder, fname) print('synth dr in func ', v * T) if i == 0: r_arr = np.zeros( (len(v_grid), num_synth_els * env.zr.size, z.size, r.size), dtype=np.complex128) synth_replicas = add_f_err(synth_replicas, num_synth_els, T, env.freq, env.freq + f_err) r_arr[i, ...] = synth_replicas[...] z_ind = np.argmin(np.array([abs(zs - x) for x in z])) #output = get_amb_surf(r, z, K_true, synth_replicas) #plot_amb_surf(-5, r, z, output, 'bartlett, v = ' + str(v), rs, zs) mvdr = run_wnc(K_true, synth_replicas, wn_gain) mvdr = mvdr[0, ...] mvdr = 10 * np.log10(abs(mvdr) / np.max(mvdr)) #plot_amb_surf(-10, r, z, mvdr, 'g, v = ' + str(v), rs, zs) axis.plot(r, mvdr[z_ind, :]) num_constraints = len(v_grid) look_ind = int(num_constraints // 2) print('look ind', look_ind) leg = [str(x)[:4] + ' m /s assumed speed' for x in v_grid] if num_synth_els > 1: mcm = run_wnc_mcm(K_true, r_arr, wn_gain, look_ind=look_ind) mcm = mcm[0, ...] mcm = 10 * np.log10(abs(mcm) / np.max(mcm)) axis.plot(r, mcm[z_ind, :]) plot_amb_surf(-10, r, z, mcm, 'mcm', rs, zs) leg += ['MCM'] axis.legend(leg) plt.show()
def mcm_plot(K_true, r_arr, db_down, look_ind, r, z, rs, zs): output = run_wnc_mcm(K_true.reshape(1, K_true.shape[0], K_true.shape[1]), r_arr, db_down, look_ind=look_ind) output = 10 * np.log10(abs(output) / np.max(output)) output = output[0, :, :] plot_amb_surf(-5, r, z, output, 'mcm wnc ' + str(db_down), rs, zs, show=True)
def gen_incoh_avg_plots(outputs, r, z, r_center, zs, db_lev, freqs, proj_str, title_str): for i in range(len(outputs)): out = outputs[i] out /= len(freqs) fig = plot_amb_surf(-10, r, z, out, title_str + str(i), r_center[i], zs) plt.savefig('pics/' + proj_str + '/' + str(i).zfill(3) + '.png') plt.close(fig) return
def make_amb_mov(self): """ Make an ambiguity surface mov """ zs = get_proj_zs(self.proj_str) folder = 'pics/' + self.proj_str + '/' + self.subfolder + '/' if self.proj_str not in os.listdir('pics'): os.mkdir('pics/' + self.proj_str) if self.subfolder not in os.listdir('pics/' + self.proj_str): os.mkdir(folder) for num_snaps in self.num_snap_list: for num_freqs in self.num_freq_list: for num_synth_els in self.num_synth_el_list: dr_list = [] for tilt_angle in self.tilt_angles: if num_synth_els == 1: v = -2.3 dr = DataRun(self.proj_str, num_snaps, v, self.subfolder, num_freqs, num_synth_els, tilt_angle, self.incoh, self.wnc) dr = load_dr(dr) best_outs = dr.outputs r_center = dr.r_center dr_list.append(dr) else: for v in self.vv: dr = DataRun(self.proj_str, num_snaps, v, self.subfolder, num_freqs, num_synth_els, tilt_angle, self.incoh, self.wnc) dr = load_dr(dr) dr_list.append(dr) r_center = dr.r_center best_outs = form_best_output_mat(dr_list) for i in range(len(r_center)): db_max = np.max(best_outs[i, :, :]) db_min = db_max - 20 fig = plot_amb_surf([db_min, db_max], dr.r, dr.z, best_outs[i, :, :], 'bart ' + str(num_synth_els), r_center[i], zs) plt.savefig(folder + str(i).zfill(3) + '.png') plt.close(fig) os.system( 'ffmpeg -loglevel quiet -r 3 -f image2 -s 1920x1080 -i ' + folder + '/%03d.png -vcodec libx264 -crf 25 -pix_fmt yuv420p ' + folder + str(num_snaps) + '_' + str(num_synth_els) + '_' + str(num_freqs) + '_' + str(self.incoh) + '.mp4') os.system('rm ' + folder + '*png')
p_true = synth_p_true[:zr.size] p_true /= np.linalg.norm(p_true) K_true = np.outer(p_true, p_true.conj()) synth_replica, rep_pos = get_v_replicas(ship_v, T, env, folder, fname, num_synth_els, dz, zmax, rmax) rep_r_ind = np.argmin( (np.array([abs(x * 1e3 - r0) for x in rep_pos.r.range]))) rep_z_ind = np.argmin((np.array([abs(zs - x) for x in rep_pos.r.depth]))) rep_true = synth_replica[:, rep_z_ind, rep_r_ind] output = get_amb_surf(rep_pos.r.range, rep_pos.r.depth, K_true, synth_replica) print(rep_true.conj().T @ p_true) print(rep_pos.r.range) plot_amb_surf(-20, rep_pos.r.range * 1e3, rep_pos.r.depth, output, 'Correct velocity', r0, zs) plt.show() modes = env.modes kr = modes.k rough_k, rough_phase = get_rough_phase(kr, true_r, synth_data) """ Generate a set of replicas for the true initial position but with a velocity error """ v_grid = np.linspace(1, 10, 200) modeled_shape = get_mainlobe_sinc_approx(v_grid, T, rough_k, num_synth_els, ship_dr) modeled_shape = np.square(abs(modeled_shape)) bartlett_grid = get_bartlett_fn_of_v(v_grid, T, r0, num_synth_els, folder, fname, synth_p_true, synth_replica)