|
|
|
@@ -1414,16 +1414,13 @@ class EISZeroOneDataDecoder(RecDataDecoder):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _decode_cali_coeff(cali_coeff: bytes) -> Optional[List[Tuple[int, int]]]:
|
|
|
|
|
if cali_coeff != b'':
|
|
|
|
|
cis_data_len = 20
|
|
|
|
|
cali_table = []
|
|
|
|
|
hsrtia_a = []
|
|
|
|
|
hsrtia_b = []
|
|
|
|
|
hsrtia_c = []
|
|
|
|
|
hsrtia_d = []
|
|
|
|
|
rolloff = []
|
|
|
|
|
phase_coeff = []
|
|
|
|
|
phase_offset = []
|
|
|
|
|
|
|
|
|
|
# phase_coeff = [[0]*4 for i in range(4)]
|
|
|
|
|
# phase_offset = [[0]*4 for i in range(4)]
|
|
|
|
|
|
|
|
|
|
phase_coeff = numpy.zeros([4, 4], dtype = int)
|
|
|
|
|
phase_offset = numpy.zeros([4, 4], dtype = int)
|
|
|
|
@@ -1437,104 +1434,107 @@ class EISZeroOneDataDecoder(RecDataDecoder):
|
|
|
|
|
# ]
|
|
|
|
|
#######################################
|
|
|
|
|
|
|
|
|
|
# print('cali_coeff', cali_coeff)
|
|
|
|
|
cutoff_freq = struct.unpack('>I', cali_coeff[1:5])[0] * 100 #4
|
|
|
|
|
# temp = struct.unpack('>B', cali_coeff[5:6])[0] #1
|
|
|
|
|
# hsrtia_200r = struct.unpack('>B', cali_coeff[6:7])[0] #1
|
|
|
|
|
# hsrtia_5k = struct.unpack('>H', cali_coeff[7:9])[0] #2
|
|
|
|
|
# hsrtia_20k = struct.unpack('>H', cali_coeff[6:8])[0] #2
|
|
|
|
|
# hsrtia_160k = struct.unpack('>I', cali_coeff[8:12])[0] #4
|
|
|
|
|
#Lv[0] 160k
|
|
|
|
|
cis_cali_packet = 1
|
|
|
|
|
index = (cis_cali_packet - 1) * cis_data_len
|
|
|
|
|
hsrtia_a.append(struct.unpack('>i', cali_coeff[index+1:index+5])[0])
|
|
|
|
|
hsrtia_b.append(struct.unpack('>q', cali_coeff[index+5:index+13])[0])
|
|
|
|
|
rolloff.append(struct.unpack('>i', cali_coeff[index+13:index+17])[0])
|
|
|
|
|
|
|
|
|
|
index = 20
|
|
|
|
|
cis_cali_packet = 2
|
|
|
|
|
index = (cis_cali_packet - 1) * cis_data_len
|
|
|
|
|
g = 0
|
|
|
|
|
phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
|
|
|
|
|
phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
|
|
|
|
|
phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
|
|
|
|
|
phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
|
|
|
|
|
|
|
|
|
|
index = 40
|
|
|
|
|
cis_cali_packet = 3
|
|
|
|
|
index = (cis_cali_packet - 1) * cis_data_len
|
|
|
|
|
g = 0
|
|
|
|
|
phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
|
|
|
|
|
phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
|
|
|
|
|
phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
|
|
|
|
|
phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
|
|
|
|
|
|
|
|
|
|
#Lv[0] 160k
|
|
|
|
|
index = 60
|
|
|
|
|
hsrtia_a.append(int.from_bytes(cali_coeff[index+1:index+6], signed=True, byteorder='big'))
|
|
|
|
|
hsrtia_b.append(int.from_bytes(cali_coeff[index+6:index+11], signed=True, byteorder='big'))
|
|
|
|
|
hsrtia_c.append(int.from_bytes(cali_coeff[index+11:index+16], signed=True, byteorder='big'))
|
|
|
|
|
|
|
|
|
|
#Lv[1] 20k
|
|
|
|
|
index = 80
|
|
|
|
|
hsrtia_a.append(int.from_bytes(cali_coeff[index+1:index+6], signed=True, byteorder='big'))
|
|
|
|
|
hsrtia_b.append(int.from_bytes(cali_coeff[index+6:index+11], signed=True, byteorder='big'))
|
|
|
|
|
hsrtia_c.append(int.from_bytes(cali_coeff[index+11:index+16], signed=True, byteorder='big'))
|
|
|
|
|
cis_cali_packet = 4
|
|
|
|
|
index = (cis_cali_packet - 1) * cis_data_len
|
|
|
|
|
hsrtia_a.append(struct.unpack('>i', cali_coeff[index+1:index+5])[0])
|
|
|
|
|
hsrtia_b.append(struct.unpack('>q', cali_coeff[index+5:index+13])[0])
|
|
|
|
|
rolloff.append(struct.unpack('>i', cali_coeff[index+13:index+17])[0])
|
|
|
|
|
|
|
|
|
|
cis_cali_packet = 5
|
|
|
|
|
index = (cis_cali_packet - 1) * cis_data_len
|
|
|
|
|
g = 1
|
|
|
|
|
phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
|
|
|
|
|
phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
|
|
|
|
|
phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
|
|
|
|
|
phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
|
|
|
|
|
|
|
|
|
|
cis_cali_packet = 6
|
|
|
|
|
index = (cis_cali_packet - 1) * cis_data_len
|
|
|
|
|
g = 1
|
|
|
|
|
phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
|
|
|
|
|
phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
|
|
|
|
|
phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
|
|
|
|
|
phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
|
|
|
|
|
|
|
|
|
|
#Lv[2] 5k
|
|
|
|
|
index = 100
|
|
|
|
|
hsrtia_a.append(int.from_bytes(cali_coeff[index+1:index+6], signed=True, byteorder='big'))
|
|
|
|
|
hsrtia_b.append(int.from_bytes(cali_coeff[index+6:index+11], signed=True, byteorder='big'))
|
|
|
|
|
hsrtia_c.append(int.from_bytes(cali_coeff[index+11:index+16], signed=True, byteorder='big'))
|
|
|
|
|
cis_cali_packet = 7
|
|
|
|
|
index = (cis_cali_packet - 1) * cis_data_len
|
|
|
|
|
hsrtia_a.append(struct.unpack('>i', cali_coeff[index+1:index+5])[0])
|
|
|
|
|
hsrtia_b.append(struct.unpack('>q', cali_coeff[index+5:index+13])[0])
|
|
|
|
|
rolloff.append(struct.unpack('>i', cali_coeff[index+13:index+17])[0])
|
|
|
|
|
|
|
|
|
|
cis_cali_packet = 8
|
|
|
|
|
index = (cis_cali_packet - 1) * cis_data_len
|
|
|
|
|
g = 2
|
|
|
|
|
phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
|
|
|
|
|
phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
|
|
|
|
|
phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
|
|
|
|
|
phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
|
|
|
|
|
|
|
|
|
|
cis_cali_packet = 9
|
|
|
|
|
index = (cis_cali_packet - 1) * cis_data_len
|
|
|
|
|
g = 2
|
|
|
|
|
phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
|
|
|
|
|
phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
|
|
|
|
|
phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
|
|
|
|
|
phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
|
|
|
|
|
|
|
|
|
|
#Lv[3] 200R
|
|
|
|
|
index = 120
|
|
|
|
|
hsrtia_a.append(int.from_bytes(cali_coeff[index+1:index+6], signed=True, byteorder='big'))
|
|
|
|
|
hsrtia_b.append(int.from_bytes(cali_coeff[index+6:index+11], signed=True, byteorder='big'))
|
|
|
|
|
hsrtia_c.append(int.from_bytes(cali_coeff[index+11:index+16], signed=True, byteorder='big'))
|
|
|
|
|
cis_cali_packet = 10
|
|
|
|
|
index = (cis_cali_packet - 1) * cis_data_len
|
|
|
|
|
hsrtia_a.append(struct.unpack('>i', cali_coeff[index+1:index+5])[0])
|
|
|
|
|
hsrtia_b.append(struct.unpack('>q', cali_coeff[index+5:index+13])[0])
|
|
|
|
|
rolloff.append(struct.unpack('>i', cali_coeff[index+13:index+17])[0])
|
|
|
|
|
|
|
|
|
|
index = 140
|
|
|
|
|
g = 1
|
|
|
|
|
phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
|
|
|
|
|
phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
|
|
|
|
|
phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
|
|
|
|
|
phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
|
|
|
|
|
|
|
|
|
|
index = 160
|
|
|
|
|
g = 1
|
|
|
|
|
phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
|
|
|
|
|
phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
|
|
|
|
|
phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
|
|
|
|
|
phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
|
|
|
|
|
|
|
|
|
|
index = 180
|
|
|
|
|
g = 2
|
|
|
|
|
phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
|
|
|
|
|
phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
|
|
|
|
|
phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
|
|
|
|
|
phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
|
|
|
|
|
|
|
|
|
|
index = 200
|
|
|
|
|
g = 2
|
|
|
|
|
phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
|
|
|
|
|
phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
|
|
|
|
|
phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
|
|
|
|
|
phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
|
|
|
|
|
|
|
|
|
|
index = 220
|
|
|
|
|
cis_cali_packet = 11
|
|
|
|
|
index = (cis_cali_packet - 1) * cis_data_len
|
|
|
|
|
g = 3
|
|
|
|
|
phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
|
|
|
|
|
phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
|
|
|
|
|
phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
|
|
|
|
|
phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
|
|
|
|
|
|
|
|
|
|
index = 240
|
|
|
|
|
cis_cali_packet = 12
|
|
|
|
|
index = (cis_cali_packet - 1) * cis_data_len
|
|
|
|
|
g = 3
|
|
|
|
|
phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
|
|
|
|
|
phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
|
|
|
|
|
phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
|
|
|
|
|
phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
|
|
|
|
|
|
|
|
|
|
print('cutoff_freq', cutoff_freq)
|
|
|
|
|
print('hsrtia_a', hsrtia_a)
|
|
|
|
|
print('hsrtia_b', hsrtia_b)
|
|
|
|
|
print('hsrtia_c', hsrtia_c)
|
|
|
|
|
print('rolloff', rolloff)
|
|
|
|
|
print('phase_coeff')
|
|
|
|
|
print(phase_coeff)
|
|
|
|
|
print('phase_offset')
|
|
|
|
|
print(phase_offset)
|
|
|
|
|
|
|
|
|
|
cali_table.append((cutoff_freq, phase_coeff, phase_offset, hsrtia_a, hsrtia_b, hsrtia_c, hsrtia_d))
|
|
|
|
|
cali_table.append((phase_coeff, phase_offset, hsrtia_a, hsrtia_b, rolloff))
|
|
|
|
|
|
|
|
|
|
return cali_table
|
|
|
|
|
else:
|
|
|
|
@@ -1591,9 +1591,8 @@ class EISZeroOneDataDecoder(RecDataDecoder):
|
|
|
|
|
if self.cali_coeff is not None and (self._mode == 0 or self._mode == 5):
|
|
|
|
|
hsrtia_a = []
|
|
|
|
|
hsrtia_b = []
|
|
|
|
|
hsrtia_c = []
|
|
|
|
|
hsrtia_d = []
|
|
|
|
|
cutoff_freq, phase_coeff, phase_offset, hsrtia_a, hsrtia_b, hsrtia_c, hsrtia_d = self.cali_coeff[0]
|
|
|
|
|
rolloff = []
|
|
|
|
|
phase_coeff, phase_offset, hsrtia_a, hsrtia_b, rolloff = self.cali_coeff[0]
|
|
|
|
|
|
|
|
|
|
if (self._mode == 0 or self._mode == 5):
|
|
|
|
|
img = ch1
|
|
|
|
@@ -1601,19 +1600,11 @@ class EISZeroOneDataDecoder(RecDataDecoder):
|
|
|
|
|
freq = ch3
|
|
|
|
|
fre_idx = 0
|
|
|
|
|
voltage_amp = round(ch4 / 1000) # Amp[mV]
|
|
|
|
|
rolloff_cali = rolloff[gain]
|
|
|
|
|
|
|
|
|
|
# rolloff_cali = cutoff_freq/1e5
|
|
|
|
|
rolloff_cali = hsrtia_c[gain]
|
|
|
|
|
voltage_mag = math.sqrt(img ** 2 + real ** 2) * (1 + freq ** 2 / rolloff_cali ** 2 / 1e4)
|
|
|
|
|
|
|
|
|
|
# if (gain == 3):
|
|
|
|
|
# current = hsrtia_a[gain] * math.exp(hsrtia_b[gain] * voltage_mag) + hsrtia_c[gain] * math.exp(hsrtia_d[gain] * voltage_mag)
|
|
|
|
|
# else:
|
|
|
|
|
|
|
|
|
|
current = (voltage_mag ** 2 * hsrtia_a[gain] + voltage_mag * hsrtia_b[gain]) / 1e8 #[nA]
|
|
|
|
|
# current = voltage_mag ** 2 * hsrtia_a[gain] + voltage_mag * hsrtia_b[gain] + hsrtia_c[gain]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (current != 0):
|
|
|
|
|
# impedance[mOhm] = voltage_amp[mv] * 1000000 / 1.414213 / current[nA] #RMS=amp*SQRT(2), SQRT(2)=1.414213
|
|
|
|
|
impedance = voltage_amp * 707106.78 / current
|
|
|
|
@@ -1635,20 +1626,8 @@ class EISZeroOneDataDecoder(RecDataDecoder):
|
|
|
|
|
phase = raw_phase - ideal_raw_phase
|
|
|
|
|
phase = phase % 180 if phase % 180<=90 else phase % 180-180
|
|
|
|
|
|
|
|
|
|
# last_phase_to90 = self._last_phase % 180 if self._last_phase % 180<=90 else self._last_phase % 180-180
|
|
|
|
|
# diff = phase - last_phase_to90
|
|
|
|
|
|
|
|
|
|
# if (self._first_phase_flag):
|
|
|
|
|
# # self._last_phase = phase
|
|
|
|
|
# self._first_phase_flag = 0
|
|
|
|
|
# elif (abs(diff) >= 90):
|
|
|
|
|
# phase = self._last_phase + diff + (180 if diff<0 else-180)
|
|
|
|
|
# else:
|
|
|
|
|
# phase = self._last_phase + diff
|
|
|
|
|
# self._last_phase = phase
|
|
|
|
|
|
|
|
|
|
imag_after_cal = impedance * math.sin(phase * math.pi / 180)
|
|
|
|
|
real_after_cal = impedance * math.cos(phase * math.pi / 180)
|
|
|
|
|
imag_after_cal = round(impedance * math.sin(phase * math.pi / 180))
|
|
|
|
|
real_after_cal = round(impedance * math.cos(phase * math.pi / 180))
|
|
|
|
|
|
|
|
|
|
if self._show_data:
|
|
|
|
|
if (self._mode == 0 or self._mode == 5):
|
|
|
|
@@ -1694,13 +1673,13 @@ class EISZeroOneDataDecoder(RecDataDecoder):
|
|
|
|
|
self._mode_stop = 0
|
|
|
|
|
|
|
|
|
|
ret = RecordingData(self.device, int(time_stamp * 1000 / 2), 0)
|
|
|
|
|
if self._mode == 0 or self._mode == 5: #EIS Mode
|
|
|
|
|
if self._mode == 0 or self._mode == 5:
|
|
|
|
|
ret.append_data(0, ch1) #raw_img
|
|
|
|
|
ret.append_data(1, ch2) #raw_real
|
|
|
|
|
ret.append_data(2, ch3 * 10) #Frequency [mHz]
|
|
|
|
|
ret.append_data(3, cycle_number) #cycle
|
|
|
|
|
ret.append_data(4, round(imag_after_cal)) #Z_imag [Ohm]
|
|
|
|
|
ret.append_data(5, round(real_after_cal)) #Z_real [Ohm]
|
|
|
|
|
ret.append_data(4, imag_after_cal) #Z_imag [Ohm]
|
|
|
|
|
ret.append_data(5, real_after_cal) #Z_real [Ohm]
|
|
|
|
|
ret.append_data(6, round(impedance)) #Impedance [Ohm]
|
|
|
|
|
ret.append_data(7, round(phase*1000)) #Phase [millidegree]
|
|
|
|
|
ret.append_data(8, round(current)) #Current [nA]
|
|
|
|
@@ -1712,8 +1691,6 @@ class EISZeroOneDataDecoder(RecDataDecoder):
|
|
|
|
|
ret.append_data(12, notify_three)
|
|
|
|
|
ret.append_data(13, voltage_amp) #amp[mV]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else: #CV Mode
|
|
|
|
|
ret.append_data(0, ch1) #Iin [nA]
|
|
|
|
|
ret.append_data(1, ch2) #Vset [nV]
|
|
|
|
|