Example #1
0
    n_samples_fri = 2 * M + 1  # also number of FS coefficients

    # subsampling
    skip = n_samples // n_samples_fri
    sub_idx = np.arange(0, n_samples, skip).astype(np.int)
    n_samples_fri = len(sub_idx)
    M = (n_samples_fri - 1) // 2
    oversample_fact = M / K
    print("Oversample factor : %f" % oversample_fact)
    t_samp_sub = t_samp[sub_idx]

    # fourier coefficients - ideal low pass by only using this coefficients
    fs_ind_base = np.arange(-M, M + 1)
    fs_ind = fs_ind_base + fs_ind_center  # around center frequency
    """ Pulse estimate """
    H_tot = total_freq_response(fs_ind / period, center_freq, bw_pulse,
                                n_cycles)

    # "TGC" of sorts
    atten = 2 * np.pi * time2distance(t_samp_sub + t0, speed_sound)
    """ Sweep though all channels """
    rx_echoes = np.zeros((n_elem_tx, n_points))
    amplitudes = np.zeros((n_elem_tx, n_points))
    resynth_score = np.zeros(n_elem_tx)
    start_time = time.time()
    print()
    for chan_idx in range(n_elem_tx):

        print("CHANNEL %d/%d" % (chan_idx + 1, n_elem_tx))

        y_samp = ndt_rawdata[min_samp:max_samp, chan_idx]
Example #2
0
samp_bw = n_samples / period
Ts = 1 / samp_bw

y_samp, t_samp = sample_iq(ck, tk, period, samp_bw, center_freq, bw, n_cycles,
                           bwr)
"""
Estimate FS coefficients of sum of diracs
"""
freqs_fft = np.fft.fftfreq(n_samples, Ts)
increasing_order = np.argsort(freqs_fft)
freqs_fft = freqs_fft[increasing_order]
Y = (np.fft.fft(y_samp))[increasing_order] / n_samples

# equalize
freqs = freqs_fft + center_freq
H_tot = total_freq_response(freqs, center_freq, bw, n_cycles, bwr)
fs_coeff_hat = Y / H_tot
"""
FRI recovery
"""
ann_filt = compute_ann_filt(fs_coeff_hat, n_diracs)
tk_hat = estimate_time_param(ann_filt, period)
ck_hat = estimate_amplitudes(fs_coeff_hat, freqs, tk_hat, period)
"""
Evaluate
"""
evaluate_recovered_param(ck, tk, ck_hat, tk_hat)
"""
Plot measured data, alongside typical RF data
"""
y_rf, t_rf = sample_rf(ck, tk, period, samp_freq, center_freq, bw, n_cycles,
Example #3
0
def process_fig2p10(n_diracs,
                    period,
                    snr_db,
                    center_freq,
                    bw,
                    n_cycles,
                    bwr,
                    samp_freq,
                    cadzow_iter,
                    oversample_fact,
                    viz=False,
                    seed=0):
    """
    Fig. 2.8-2.9
    """

    # create FRI parameters
    ck, tk = create_pulse_param(n_diracs, period=period, seed=seed)

    # set oversampling
    M = oversample_fact * n_diracs
    n_samples = 2 * M + 1
    samp_bw = n_samples / period
    Ts = 1 / samp_bw

    # oversample
    y_samp, t_samp = sample_iq(ck, tk, period, samp_bw, center_freq, bw,
                               n_cycles, bwr)
    y_noisy = add_noise(y_samp, snr_db, seed=seed)

    # estimate fourier coefficients
    freqs_fft = np.fft.fftfreq(n_samples, Ts)
    increasing_order = np.argsort(freqs_fft)
    freqs_fft = freqs_fft[increasing_order]
    freqs = freqs_fft + center_freq
    H_tot = total_freq_response(freqs, center_freq, bw, n_cycles, bwr)
    fs_coeff_hat = estimate_fourier_coeff(y_noisy, t_samp, H=H_tot)

    # denoising + recovery
    fs_coeff_clean = cadzow_denoising(fs_coeff_hat,
                                      n_diracs,
                                      n_iter=cadzow_iter)
    ann_filt = compute_ann_filt(fs_coeff_clean, n_diracs)
    tk_hat = estimate_time_param(ann_filt, period)
    ck_hat = estimate_amplitudes(fs_coeff_clean, freqs, tk_hat, period)

    # compute errors
    tk_err = compute_srr_db_points(tk, tk_hat)

    y_rf, t_rf = sample_rf(ck, tk, period, samp_freq, center_freq, bw,
                           n_cycles, bwr)
    y_rf_resynth, t_rf = sample_rf(ck_hat, tk_hat, period, samp_freq,
                                   center_freq, bw, n_cycles, bwr)
    sig_err = compute_srr_db(y_rf, y_rf_resynth)

    print()
    print("%d Diracs, %.02fx oversampling:" % (n_diracs, oversample_fact))
    print("Locations SRR : %.02f dB" % tk_err)
    print("Resynthesized error : %.02fdB" % sig_err)
    """visualize"""
    if viz:

        import matplotlib.pyplot as plt
        time_scal = 1e5

        plt.figure()

        baseline = plt.stem(time_scal * tk,
                            ck,
                            'g',
                            markerfmt='go',
                            label="True")[2]
        plt.setp(baseline, color='g')
        baseline.set_xdata([0, time_scal * period])

        baseline = plt.stem(time_scal * tk_hat,
                            ck_hat,
                            'r',
                            markerfmt='r^',
                            label="Estimate")[2]
        plt.setp(baseline, color='r')
        baseline.set_xdata(([0, time_scal * period]))
        plt.xlabel("Time [%s seconds]" % str(1 / time_scal))
        plt.xlim([0, time_scal * period])
        plt.legend(loc='lower right')
        plt.grid()
        plt.tight_layout()
        ax = plt.gca()
        ax.axes.yaxis.set_ticklabels([])

        # resynthesized signal
        plt.figure()
        plt.plot(time_scal * t_rf, y_rf, label="True", alpha=0.65)
        plt.plot(time_scal * t_rf, y_rf_resynth, label="Estimate", alpha=0.65)
        plt.xlim([0, time_scal * period])
        plt.grid()
        plt.xlabel("Time [%s seconds]" % str(1 / time_scal))
        plt.tight_layout()
        plt.legend(loc='lower right')
        ax = plt.gca()
        ax.axes.yaxis.set_ticklabels([])