diff --git a/measurement.py b/measurement.py index ca7162a..054dbab 100644 --- a/measurement.py +++ b/measurement.py @@ -86,6 +86,7 @@ def __init__(self, out_filename, port): super().__init__(out_filename) self._serial = serial.Serial(port, 115200, timeout=1) + self._serial.readline() self._cols = 4 print("Seiral port connected on ", port) @@ -123,7 +124,7 @@ # Wait for stop print("measurement start.") - recode_dulation = 3 # sec + recode_dulation = 15 # sec for i in range(recode_dulation): time.sleep(1) print(i + 1, "/", recode_dulation, "sec") @@ -139,23 +140,29 @@ gd_t = np.linspace( gd_data[0, 0], gd_data[-1, 0], len(gd_data[:, 0]) ) # Equalize time interval - valid = serial_worker._data[:, 0] >= gd_data[0, 0] - ser_data = serial_worker._data[valid, :] + # valid = serial_worker._data[:, 0] >= gd_data[0, 0] + # ser_data = serial_worker._data[valid, :] + ser_data = serial_worker._data # print(godirect_worker._data) # print(serial_worker._data) - func = interp1d(gd_t, gd_data[:, 1], kind="cubic") + func = interp1d( + gd_t, gd_data[:, 1], kind="linear", bounds_error=False, fill_value="extrapolate" + ) new_gd_data = func(ser_data[:, 0]) combind = np.hstack((ser_data, new_gd_data.reshape(new_gd_data.size, 1))) + combind = combind[-(recode_dulation * 100 + 1) :, :] + combind[:, 1] = (combind[:, 1] - combind[0, 1]) / 1000.0 filename = datetime.datetime.now().strftime("Rec_%Y%m%d_%H%M%S.csv") np.savetxt( filename, - combind, + combind[:, 1:], delimiter=",", fmt="%.3f", - header="time(s),device time(ms),IF-I,IF-Q,RespBelt", + header="time(s),IF-I,IF-Q,RespBelt", + comments="", ) print("Recoding data was saved to ", filename) # print(combind)