code_snippets/epoxy_transducer/tof_data.py

41 lines
1.0 KiB
Python
Raw Permalink Normal View History

import numpy as np
import matplotlib.pyplot as plt
num_meas = 4
# speed of sound m/s
sos = 1500
# depth of the tub in mm
tub_depth = 690
# distances from the top measured at in mm
distance = [0,138,276,414]
# distance from the bottom
distance_to_bot = np.empty(num_meas)
for i in range(num_meas):
distance_to_bot[i] = tub_depth - distance[i]
# time from pulse to reflection measuredin uS
tof = [912,758,614,486]
# tot distance traveled
distance_traveled = np.empty(num_meas)
for i in range(num_meas):
distance_traveled[i] = (690*2) - (distance[i] * 2)
# ideal time from pulse to reflection measured uS
tof_expected = np.empty(num_meas)
for i in range(num_meas):
tof_expected[i] = ((distance_traveled[i] * 1e-3) / sos) * 1e6
plt.figure(1)
plt.plot(distance_to_bot, tof, label = 'tof measured in uS')
plt.plot(distance_to_bot, tof_expected, label = 'tof expected in uS')
plt.xlabel('Distance to bottom [mm]')
plt.ylabel('Time [uS]')
plt.title('Tof Data')
plt.xlim(max(distance_to_bot),min(distance_to_bot))
plt.legend()