コード例 #1
0
def get_noise_K_samps(source_freq,
                      proj_str,
                      subfolder,
                      num_snapshots,
                      num_synth_els,
                      stride,
                      incoh,
                      rm_diag=False):
    for noise_freq in range(source_freq - 2, source_freq + 3):
        t, x = load_x(noise_freq, proj_str, subfolder)
        t, x, rt, rr, vv, r_interp = deal_with_t_x_r(t, x, source_freq)
        _, _, tmp = get_r_super_cov_seq(t,
                                        x,
                                        num_snapshots,
                                        r_interp,
                                        num_synth_els,
                                        stride,
                                        incoh=incoh)
        if rm_diag == True:
            for i in range(tmp.shape[0]):
                tmp[i, ...] -= np.diag(np.diag(tmp[i, ...]))
        if noise_freq == (source_freq - 2):
            K_samps = tmp
        elif noise_freq == source_freq:
            pass
        else:
            K_samps += tmp
    return K_samps / 5
コード例 #2
0
ファイル: snr.py プロジェクト: hunterakins/coh_mfp
def get_snr(source_freq, vv, Nfft, fact, num_snapshots, proj_str):
    subfolder = str(Nfft)
    v_counter = 0
    for v in vv:
        fc = ms.get_fc(source_freq, v)
        t, x = load_x(fc, proj_str, subfolder)
        noise_t1, noise_x1 = load_x(ms.get_fc(source_freq-1, v), proj_str, subfolder)
        noise_t2, noise_x2 = load_x(ms.get_fc(source_freq+2, v), proj_str, subfolder)

        x_pow =  np.sum(np.square(abs(x)), axis=0) / x.shape[0]
        nx1_pow = np.sum(np.square(abs(noise_x1)), axis=0) / noise_x1.shape[0]
        nx2_pow = np.sum(np.square(abs(noise_x2)), axis=0) / noise_x2.shape[0]

        num_samples = noise_t1.size
        num_covs = (num_samples - num_snapshots) // num_snapshots
        x_avg_pow = np.zeros((num_covs))
        nx1_avg_pow = np.zeros((num_covs))
        nx2_avg_pow = np.zeros((num_covs))
        cov_t = np.zeros((num_covs))

        for i in range(num_covs):
            tmp = np.mean(np.square(abs(x[:,num_snapshots*i:num_snapshots*(i+1)])))
            x_avg_pow[i] = tmp

            tmp = np.mean(np.square(abs(noise_x1[:, num_snapshots*i:num_snapshots*(i+1)])))
            nx1_avg_pow[i] = tmp

            tmp = np.mean(np.square(abs(noise_x2[:, num_snapshots*i:num_snapshots*(i+1)])))
            nx2_avg_pow[i] = tmp
            
            tmp = np.mean(t[num_snapshots*i:num_snapshots*(i+1)])
            cov_t[i] = tmp

        n_avg_pow = (nx1_avg_pow + nx2_avg_pow) / 2
        sig_avg_pow = x_avg_pow - n_avg_pow
        snr = sig_avg_pow / n_avg_pow

        if v==vv[0]:
            full_snr = np.zeros((vv.size, snr.size))
        full_snr[v_counter, :] = snr
        v_counter += 1
    best_snr = np.max(full_snr, axis=0)
    best_inds = np.argmax(full_snr, axis=0)
    best_v = vv[best_inds]
    snr_db = 10*np.log10(best_snr)
    return cov_t, snr_db, best_v
コード例 #3
0
def get_cov_time(proj_str, subfolder, num_snapshots, num_synth_els):
    source_freq = get_proj_tones(proj_str)[0]
    fc = ms.get_fc(source_freq, 0)
    t, x = load_x(fc, proj_str, subfolder)
    t, x, rt, rr, vvv, r_interp = deal_with_t_x_r(t, x, source_freq)
    stride = num_snapshots
    r_center, cov_t, K_samps = get_r_super_cov_seq(t, x, num_snapshots,
                                                   r_interp, num_synth_els,
                                                   stride)
    return cov_t
コード例 #4
0
def get_single_freq_wnc(proj_str,
                        subfolder,
                        source_freq,
                        num_synth_els,
                        best_v,
                        wn_gain,
                        num_snapshots,
                        cov_index,
                        incoh=False):
    print('wn_gain', wn_gain)
    for num_synth_els in [num_synth_els]:
        tilt_angle = -1
        vv = [best_v]
        for v in vv:
            print('-----------------------------------------')
            now = time.time()
            fc = ms.get_fc(source_freq, v)
            t, x = load_x(fc, proj_str, subfolder)
            num_rcvrs = x.shape[0]
            t, x, rt, rr, vv, r_interp = deal_with_t_x_r(t, x, source_freq)
            zs, zr = get_proj_zs(proj_str), get_proj_zr(proj_str)
            rcvr_stride = int(zr.size // num_rcvrs)
            zr = zr[::rcvr_stride]

            env = get_env(proj_str, source_freq)
            env = populate_env(env, source_freq, zs, zr, rr, fname=proj_str)

            kbar = np.mean(env.modes.k.real)
            delta_k = np.max(env.modes.k.real) - np.min(env.modes.k.real)
            #print('delta_k', delta_k)
            range_cell = (2 * np.pi / delta_k)
            range_cell /= 4  # do quarter range cells
            #print('range cell', range_cell)
            time_in_cell = range_cell / abs(v)
            #print('time in cell', time_in_cell)
            #T = time_in_cell

            delta_t = t[1] - t[0]
            print('num snapshots', num_snapshots)
            print('good num snaps per cov mat, total_num data snapshots',
                  num_snapshots, x.shape[1])
            stride = num_snapshots
            T = stride * delta_t

            print('v', v)
            r, z, reps = get_mult_el_reps(env,
                                          num_synth_els,
                                          v,
                                          T,
                                          fname=proj_str,
                                          adiabatic=False,
                                          tilt_angle=tilt_angle)

            r_center, cov_t, K_samps = get_r_super_cov_seq(t,
                                                           x,
                                                           num_snapshots,
                                                           r_interp,
                                                           num_synth_els,
                                                           stride,
                                                           incoh=incoh)
            r_center, cov_t, K_samps = r_center[cov_index], cov_t[
                cov_index], K_samps[cov_index, ...]

            #output = lookup_run_wnc(K_samps, reps, wbn_gain, noise_K_samps)
            K_samps = K_samps.reshape(1, K_samps.shape[0], K_samps.shape[1])
            output = lookup_run_wnc(K_samps, reps, wn_gain)
            out_db = 10 * np.log10(output)
            print('wnc time', time.time() - now)
            print('-----------------------------------------')
    return r, z, r_center, zs, out_db, cov_t
コード例 #5
0
def get_single_freq_bart(proj_str,
                         subfolder,
                         source_freq,
                         num_synth_els,
                         v,
                         num_snapshots,
                         cov_index,
                         incoh=False):
    rm_diag = False
    for num_synth_els in [num_synth_els]:
        tilt_angle = -1
        print('-----------------------------------------')
        now = time.time()
        fc = ms.get_fc(source_freq, v)
        t, x = load_x(fc, proj_str, subfolder)
        num_rcvrs = x.shape[0]
        t, x, rt, rr, vvv, r_interp = deal_with_t_x_r(t, x, source_freq)
        zs, zr = get_proj_zs(proj_str), get_proj_zr(proj_str)
        rcvr_stride = int(zr.size // num_rcvrs)
        zr = zr[::rcvr_stride]

        env = get_env(proj_str, source_freq)
        env = populate_env(env, source_freq, zs, zr, rr, fname=proj_str)

        kbar = np.mean(env.modes.k.real)
        delta_k = np.max(env.modes.k.real) - np.min(env.modes.k.real)
        #print('delta_k', delta_k)
        range_cell = (2 * np.pi / (delta_k / 2))
        range_cell /= 4  # do quarter range cells
        #print('range cell', range_cell)
        time_in_cell = range_cell / abs(v)

        delta_t = t[1] - t[0]
        print('source freq', source_freq)
        print(' range cell snaps', time_in_cell * 4 / delta_t)
        print(' range cell size ', range_cell * 4)
        #print('num snapshots', num_snapshots)
        #print('good num snaps per cov mat, total_num data snapshots',  num_snapshots, x.shape[1])
        #stride = num_snapshots
        stride = num_snapshots
        print('stride, num_snaps', stride, num_snapshots)
        T = stride * delta_t

        print('v', v)
        r, z, reps = get_mult_el_reps(env,
                                      num_synth_els,
                                      v,
                                      T,
                                      fname=proj_str,
                                      adiabatic=False,
                                      tilt_angle=tilt_angle)

        r_center, cov_t, K_samps = get_r_super_cov_seq(t,
                                                       x,
                                                       num_snapshots,
                                                       r_interp,
                                                       num_synth_els,
                                                       stride,
                                                       incoh=incoh)
        r_center, cov_t, K_samps = r_center[cov_index], cov_t[
            cov_index], K_samps[cov_index, ...]
        bart_db, max_val = get_amb_surf(r, z, K_samps, reps, matmul=True)
        bart_db += 10 * np.log10(max_val)
        out_db = bart_db
        #out_db = 10*np.log10(output)
        #print('bart time', time.time() - now)
    return r, z, r_center, zs, out_db, cov_t