diff --git a/main.py b/main.py index 5cdd6af..966e326 100644 --- a/main.py +++ b/main.py @@ -12,9 +12,11 @@ from scipy.integrate import cumulative_trapezoid import matplotlib.pyplot as plt + +# R =3.4 ohm SINE_FREQ = 100e3 -CYCLE_COUNT = 100 +CYCLE_COUNT = 10 DIV_COUNT = 10 @@ -23,16 +25,18 @@ OSC_CHANNEL_A = 1 # GEN signal OSC_CHANNEL_B = 2 # OUT GEN_CHANNEL = siglent.ChannelID.CH1 -UPPER_BOUND_DIV = 8 +UPPER_BOUND_DIV = 7 LOWER_BOUND_DIV = 3 TARGET_DIV = (UPPER_BOUND_DIV + LOWER_BOUND_DIV) / 2 PATH = "/home/zychlix/Desktop/pomiary/out" +PATH_BH = "/home/zychlix/Desktop/pomiary/out_BH" +PATH_BH_RAW = "/home/zychlix/Desktop/pomiary/out_BH_raw" -R0 = 99.4 +R0 = 99.5 -AMPLITUDE = 3 -COUNT = 200 +AMPLITUDE = 10 +COUNT = 50 class ImpedanceAnalyzer: @@ -52,6 +56,7 @@ class ImpedanceAnalyzer: self.dc = 0 self.scales = [10] * (CHANNEL_COUNT + 1) + return def getImpedance(self, freq: float): @@ -77,7 +82,9 @@ class ImpedanceAnalyzer: print(f"{freq} V_a {v_a} V_o {v_o}") - z = R0 * (v_a - v_o) / v_o + # z = R0 * (v_o) / v_o #resistor to gnd + + z = R0 * (v_o) / (v_a - v_o) # resistor to input # z = v_a / (v_o / R0) self.debug_voltages.append([np.abs(v_a), np.abs(v_o)]) @@ -87,8 +94,10 @@ class ImpedanceAnalyzer: def getScaledWaveform(self, ch): data = self.osc.getChannel(ch).getWaveform() vpp = self.calculateVRMS(data) * 2 * np.sqrt(2) + print(f"VPP measured from rms: {vpp} on channel {ch}: SCALE {self.scales[ch]}") + if not (LOWER_BOUND_DIV < vpp / self.scales[ch] < UPPER_BOUND_DIV): - # self.autoscale(ch) + self.autoscale(ch) time.sleep(2) # change back to 1 self.osc.single() data = self.osc.getChannel(ch).getWaveform() @@ -116,7 +125,8 @@ class ImpedanceAnalyzer: data = self.osc.getChannel(channel).getWaveform() time.sleep(1) - rms = self.calculateVRMS(data) + # rms = self.calculateVRMS(data) + min = numpy.dat vpp = rms * 2 * np.sqrt(2) if LOWER_BOUND_DIV < vpp / self.scales[channel] < UPPER_BOUND_DIV: @@ -132,6 +142,7 @@ class ImpedanceAnalyzer: self.scales[channel] = self.osc.getChannel(channel).clampVscale( vpp / TARGET_DIV ) + self.osc.getChannel(channel).setVScale(self.scales[channel]) print( f"Autoscaled channel: {channel}, RMS: {rms}, Vpp:{vpp}, Scale:{self.scales[channel]}" @@ -140,13 +151,13 @@ class ImpedanceAnalyzer: return def PlotBH(self, freq, amplitude): - setWindowSize(self.osc, 1, freq) + setWindowSize(self.osc, 2, freq) self.gen.channels[GEN_CHANNEL].apply_sine(freq, amplitude, self.dc) self.gen.channels[GEN_CHANNEL].set_output(True) self.osc.run() - time.sleep(5) + time.sleep(2) self.osc.single() @@ -166,9 +177,11 @@ class ImpedanceAnalyzer: B = ( cumulative_trapezoid(v_l, time_array, initial=0) / 1 ) # Correct to proper values - H = current_data / R0 # As well as in here + H = current_data # As well as in here plt.plot(H, B) + self.exportZtoCSV(np.array([B, H]).T, PATH_BH_RAW) + self.exportZtoCSV(np.array([B, H]).T, PATH_BH) plt.show() @@ -205,7 +218,7 @@ def main(): # imp = ImpedanceAnalyzer("TCPIP::10.112.1.2::INSTR", "TCPIP::10.112.1.3::INSTR") - imp = ImpedanceAnalyzer("TCPIP::192.168.1.4::INSTR", "TCPIP::192.168.1.5::INSTR") + imp = ImpedanceAnalyzer("TCPIP::192.168.1.2::INSTR", "TCPIP::192.168.1.3::INSTR") imp.gen.channels[GEN_CHANNEL.CH1].set_output(True) @@ -213,9 +226,9 @@ def main(): # imp.autoscale(2) - imp.PlotBH(3e3, AMPLITUDE) + # imp.PlotBH(10e3, AMPLITUDE) - return 0 + # return 0 z, f = imp.getSweep(2, 7, COUNT) z_real = np.real(z) @@ -241,6 +254,7 @@ def main(): ax[1].legend() imp.exportZtoCSV(np.array([f, z]).T, PATH) + plt.savefig(PATH + ".png") plt.show()