Exemplo n.º 1
0
def plot_h_p(x, y, z):
    offset, h = af.get_impulse_response(x, y, z)
    t_h = arrayutil.get_time_sequence(len(h), SAMPLE_RATE,
                                      offset / SAMPLE_RATE)

    half_w = ELEM_WIDTH / 2

    plt.figure()
    plt.plot(C * t_h / half_w, h / C)
    plt.grid(True)
    plt.xlabel("ct/a")
    plt.ylabel("h/c")
    plt.title("h x/a={} y/a={} z/a={}".format(x / half_w, y / half_w,
                                              z / half_w))

    p = DENSITY * signal.convolve(h, dvdt)
    t_p = arrayutil.get_time_sequence(len(p), SAMPLE_RATE,
                                      offset / SAMPLE_RATE)

    plt.figure()
    plt.plot(C * t_p / half_w, p)
    plt.grid(True)
    plt.xlabel("ct/a")
    plt.ylabel("p")
    plt.title("p x/a={} y/a={} z/a={}".format(x / half_w, y / half_w,
                                              z / half_w))
Exemplo n.º 2
0
def filter_signal(signal, plot_signals):
    s2 = filter_spikes(signal)
    s_filtered = sinc_lowpass(s2, fs, cutoff_freq)
    if plot_signals:
        plt.figure()
        plt.title("Comparison of signals")
        plt.plot(get_time_sequence(len(signal), fs, 0.0),
                 signal,
                 "r-o",
                 label="raw")
        plt.plot(get_time_sequence(len(s2), fs, 0.0),
                 s2,
                 "g--",
                 label="spikes filtered")
        plt.plot(get_time_sequence(len(s_filtered), fs, 0.0),
                 s_filtered,
                 "b--",
                 label="filtered")
        plt.legend(loc='upper right')
        plt.xlabel('t (s)')
        plt.grid(True)

        plot_spectrum(signal, "Spectrum - raw signal")
        plot_spectrum(s_filtered, "Spectrum - filtered signal")
    return s_filtered
Exemplo n.º 3
0
period = 1.0 / FC

t0 = np.arange(0.0, NUM_PERIODS * period, 1.0 / FS)
s0 = np.sin(2.0 * np.pi * FC * t0)
s1 = -np.cos(2.0 * np.pi * (FC / NUM_PERIODS) * t0) + 1.0

plt.figure()
plt.plot(t0, s0)

plt.figure()
plt.plot(t0, s1)

s2 = s1 * s0
s2 = np.r_[np.zeros((MARGIN, )), s2, np.zeros((MARGIN, ))]
print('s2.shape:', s2.shape)
t2 = arrayutil.get_time_sequence(len(s2), FS, 0) * 1e6
s2_env = calc_envelope(s2, 0.0)

plt.figure(figsize=(6, 3))
plt.plot(t2, s2, '--k', label='sinal')
plt.plot(t2, s2_env, 'k', label='envelope')
plt.grid(True)
if pcfg.t3():
    plt.legend(loc='upper right', labelspacing=0.0, fontsize=12, ncol=1)
    plt.xlabel(r'$\mathrm{tempo}~(\si{\micro\second})$')
    plt.ylabel('valor')
    plt.autoscale(enable=True, axis='x', tight=True)
    plt.tight_layout(
        pad=0.2)  # padding between the x and y labels and the figure borders
    plt.savefig(pcfg.plot_dir + '/envelope_normal.pdf')
Exemplo n.º 4
0
def plot_excitation(s):
    plt.figure()
    plt.plot(arrayutil.get_time_sequence(len(s), SAMPLE_RATE), s)
    plt.grid(True)
    plt.title("Excitation waveform")
    plt.xlabel("t (s)")
Exemplo n.º 5
0
        focus_delay = np.zeros(NUM_ARRAY_ELEM_X * NUM_ARRAY_ELEM_Y)

    if USE_NUMERIC_METHOD:
        af = n_af.NumericRectangularSourceAcousticField(
            ELEM_WIDTH, ELEM_HEIGHT, SAMPLE_RATE, C, SUB_ELEM_SIZE)
        af.plot_sub_elements()
    else:
        af = a_af.AnalyticRectangularSourceAcousticField(
            ELEM_WIDTH, ELEM_HEIGHT, SAMPLE_RATE, C, MIN_ELEM_EDGE_DIVISOR)

    #v = exc.waveform1(CENTER_FREQ, SAMPLE_RATE, EXCITATION_NUM_PERIODS)
    v = exc.waveform2a(CENTER_FREQ, SAMPLE_RATE, EXCITATION_NUM_PERIODS)
    #v = exc.waveform2b(CENTER_FREQ, SAMPLE_RATE, EXCITATION_NUM_PERIODS)
    #v = exc.hdf5_waveform("data/ref_pulse-40MHz.h5", "ascan", 40.0e6, SAMPLE_RATE)
    plt.figure()
    plt.plot(arrayutil.get_time_sequence(len(v), SAMPLE_RATE), v)
    plt.grid(True)
    plt.title("Excitation waveform")
    plt.xlabel("t (s)")

    dvdt = arrayutil.central_diff(v, SAMPLE_RATE)

    grid_x, grid_z = np.meshgrid(x_list, z_list, indexing='ij')
    image = np.zeros(grid_x.shape)

    job_queue = mproc.Queue()
    result_queue = mproc.Queue()

    # Create jobs.
    num_jobs = len(x_list)
    for ix in range(num_jobs):
Exemplo n.º 6
0
UPSAMPLING_FACTOR = 16
UPSAMP_FILTER_TOLERANCE = 0.0001
UPSAMP_FILTER_TRANSITION_WIDTH = 0.2  # fraction of the original bandwidth

MAX_FREQ = 20e6
ENV_PADDING = 1024
FREQ_RESP_THRESHOLD = 0.1
FREQ_RESP_PADDING = 32 * 1024

#------------------------------------------------------------------------------

fs = FS * UPSAMPLING_FACTOR

ascan = hdf5util.read_to_ndarray(ASCAN_FILE_NAME, ASCAN_DATASET_NAME)
t = arrayutil.get_time_sequence(len(ascan), FS, 0)

plt.figure(figsize=(6, 3))
plt.plot(t, ascan / np.abs(ascan).max(), 'k')
plt.grid(True)
if pcfg.t1():
    plt.title('A-scan')
    plt.xlabel('time (s)')
    plt.tight_layout(
        pad=0.2)  # padding between the x and y labels and the figure borders
elif pcfg.t2():
    plt.xlabel(r'$\mathrm{time} (\si{\second})$')
    plt.ylabel('normalized value')
    plt.autoscale(enable=True, axis='x', tight=True)
    plt.tight_layout(
        pad=0.2)  # padding between the x and y labels and the figure borders
Exemplo n.º 7
0
from util import arrayutil, hdf5util, decimation

DECIMATION_FILTER_TOLERANCE = 0.0001
DECIMATION_FILTER_TRANSITION_WIDTH = 0.3 # fraction of the original bandwidth
FS = 400e6
DECIMATION_OFFSET = 32
#DECIMATION_OFFSET = 33



ascan = hdf5util.read_to_ndarray(file_path='ref_pulse.h5', dataset_name='ascan')
ascan = np.hstack((ascan, np.zeros(500)))
ascan = np.hstack((ascan, np.ones(100)))
ascan = np.hstack((ascan, np.zeros(500)))

t = arrayutil.get_time_sequence(len(ascan), FS)

hdf5util.write_ndarray(data=ascan, file_path='decimation_source.h5', dataset_name='v')

for decimation_factor in [2, 5, 10]:
    print('### decimation_factor: {}'.format(decimation_factor))
    decim_filter = decimation.downsampling_filter(decimation_factor=decimation_factor,
                                                  half_transition_width=DECIMATION_FILTER_TRANSITION_WIDTH,
                                                  tolerance=DECIMATION_FILTER_TOLERANCE,
                                                  plot=False)
    print('filter length: {}'.format(len(decim_filter)))

    ascan_d_offset, ascan_d, t_d = decimation.decimate(DECIMATION_OFFSET,
                                                       ascan,
                                                       decimation_factor,
                                                       decim_filter,