2024-03-21 19:24:50 +01:00
|
|
|
from matplotlib import pyplot as plt
|
2024-03-22 13:55:14 +01:00
|
|
|
from scipy import signal
|
|
|
|
import numpy as np
|
2024-03-21 19:24:50 +01:00
|
|
|
import reader
|
2024-03-22 13:55:14 +01:00
|
|
|
import helper
|
2024-03-21 19:24:50 +01:00
|
|
|
|
2024-03-22 13:55:14 +01:00
|
|
|
# load data
|
2024-03-21 19:24:50 +01:00
|
|
|
data_reader = reader.Reader()
|
2024-03-22 13:55:14 +01:00
|
|
|
data = data_reader.read_file(r".\data\T0004CH1.csv")
|
2024-03-21 19:24:50 +01:00
|
|
|
|
2024-03-22 13:55:14 +01:00
|
|
|
# slice empty space, start and end time is in seconds
|
|
|
|
data = helper.cut_time(data, -1e-7, 5e-7)
|
2024-03-21 19:24:50 +01:00
|
|
|
|
2024-03-22 13:55:14 +01:00
|
|
|
# find peaks, use max to find the highest, or a threshold
|
|
|
|
# adjust width to find the middle of a peak (width is in indices)
|
|
|
|
# peaks, _ = signal.find_peaks(data['CH1'], max(data['CH1']))
|
|
|
|
peaks, _ = signal.find_peaks(data['CH1'], 2, width=10)
|
2024-03-21 19:24:50 +01:00
|
|
|
|
2024-03-22 13:55:14 +01:00
|
|
|
# find throughs, comment away it finds too many throughs
|
|
|
|
# invert = [-x for x in data['CH1']]
|
|
|
|
# throughs, _ = signal.find_peaks(invert, max(invert))
|
|
|
|
# peaks = np.concatenate([peaks, throughs])
|
|
|
|
|
|
|
|
# store time step
|
|
|
|
step = data['TIME'][1] - data['TIME'][0]
|
|
|
|
|
|
|
|
# do some calcs
|
|
|
|
idx_diff = peaks[-1] - peaks[0]
|
|
|
|
tim_diff = idx_diff*step
|
|
|
|
print(f"Time between peaks: {tim_diff*1e9:.1f} ns")
|
|
|
|
c = 299792458
|
|
|
|
k = 0.66
|
|
|
|
c_coax = c * k
|
|
|
|
print(f"Measured distance: {(tim_diff/2)*c_coax:.2f} m")
|
|
|
|
|
|
|
|
# Plot data
|
2024-03-21 19:24:50 +01:00
|
|
|
plt.plot(data['TIME'], data['CH1'])
|
2024-03-22 13:55:14 +01:00
|
|
|
if len(peaks) > 0:
|
|
|
|
for peak in peaks:
|
|
|
|
plt.vlines(
|
|
|
|
peak*step+data['TIME'][0],
|
|
|
|
min(data['CH1']),
|
|
|
|
max(data['CH1']), 'red', 'dashed')
|
|
|
|
plt.grid()
|
|
|
|
plt.show()
|