From 02512129e24c9d510283efe9e1cf701fc1330c0b Mon Sep 17 00:00:00 2001 From: xavi Date: Thu, 21 Mar 2024 10:53:11 -0700 Subject: [PATCH] Added time of flight data analysis script Used to compare expected time of flight to measured when using epoxyed desoldered hc-sr04 ultrasonic transducers. --- epoxy_transducer/tof_data.py | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 epoxy_transducer/tof_data.py diff --git a/epoxy_transducer/tof_data.py b/epoxy_transducer/tof_data.py new file mode 100644 index 0000000..4152fa6 --- /dev/null +++ b/epoxy_transducer/tof_data.py @@ -0,0 +1,40 @@ +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()