使用Moku:Go测量阻抗(第 1 部分)
使用Moku :go 和 Python 测量电阻
这两个 Python 脚本附带应用说明“ 使用Moku:Go测量阻抗,第 1 部分,电阻”。
单端口方法
# moku example: Single-Port Impedance Test
#
# This example demonstrates how you can take an impedance of a device under
# test using the single-port method
#
# Initializing the Instrument and Functions
from moku.instruments import FrequencyResponseAnalyzer
import numpy as np
import math
# Connect to your Moku by its ip address using FrequencyResponseAnalyzer('192.168.###.###')
# or by its serial number using FrequencyResponseAnalyzer(serial=123)
i = FrequencyResponseAnalyzer('192.168.73.1', force_connect=True)
try:
# Configure Input Parameters
i.set_output(1, 1)
i.measurement_mode('In')
# For Moku:Go
i.set_frontend(1, "50Ohm", "DC", "10Vpp")
# For Moku:Lab and Moku:Pro
#i.set_frontend(1, "50Ohm", "DC", "4Vpp")
# Configure output sweep parameters
i.set_sweep(start_frequency=6e4, stop_frequency=100, num_points=256,
averaging_time=1e-6, settling_time=1e-6, averaging_cycles=1, settling_cycles=1)
# Check the parameters of the FRA
print(i.summary())
# Start the sweep
i.start_sweep(single=True)
# Get a single sweep frame. This will block until the sweep is complete,
# beware if you include low frequencies there will be a longer
# measurement time for the frame
frame = i.get_data()
# Known
# Input Impedance for the Moku:Lab and Moku:Pro
# For Moku:Go, this is the parallel resistance with a 50 ohm
# terminator resistor in parallel with the input
Z_in = 50 #ohms
# Amplitude of the Output Voltage from the FRA
V_out = 1 #Vpp
# Output Impedance of the Moku
# Make sure the correct one is put into your equation below
Z_out_Go = 200 #ohms
Z_out_Pro_Lab = 50 #ohms
#Taking needed Power Measurement
frequency = frame['ch1']['frequency']
magnitude = frame['ch1']['magnitude']
# Check Outputs
#print(frame['ch1']['magnitude'])
#print(frame['ch1']['frequency'])
# Pull the Power Measurement at the Frequency of 300 Hz
index_300hz = np.argmin(np.abs(np.array(frequency) - 300))
dBm = magnitude[index_300hz]
# Assuming Moku is expressing the dBm
V_in = math.sqrt(8 * Z_in * ((10 ** (dBm / 10)) / 1000))
print(f"The magnitude at 300 Hz is {dBm:.2f} dBm, which corresponds to {V_in:.4f} V.")
# Calculate Z_DUT
# Make sure the correct Z_out is being used
Z_dut = ((V_out * Z_in) / V_in) - (Z_in + Z_out_Go)
print(f"The impedance of the device under test is: {Z_dut:.2f} Ohms")
except Exception as e:
print(f'Exception occurred: {e}')
finally:
# Close the connection to the Moku device
# This ensures network resources and released correctly
i.relinquish_ownership()
双端口方法
# moku example: Two-Port Impedance Test
#
# This example demonstrates how you can take an impedance of a device under
# test using the two-port method
#
#
from moku.instruments import FrequencyResponseAnalyzer
import numpy as np
import math
# Connect to your Moku by its ip address using FrequencyResponseAnalyzer('192.168.###.###')
# or by its serial number using FrequencyResponseAnalyzer(serial=123)
i = FrequencyResponseAnalyzer('192.168.73.1', force_connect=True)
try:
# Configure output sweep amplitudes
# Channel 1 - 1Vpp
i.set_output(1, 1)
# Configure output sweep parameters
i.measurement_mode('In')
i.set_sweep(start_frequency=10e4, stop_frequency=100, num_points=256,
averaging_time=1e-6, averaging_cycles=1, settling_cycles=1,
settling_time=1e-6)
# For Moku:Go
i.set_frontend(1, "50Ohm", "DC", "10Vpp")
# For Moku:Lab and Moku:Pro
#i.set_frontend(1, "50Ohm", "DC", "4Vpp")
# Start the single sweep
i.start_sweep(single=True)
# Get a single sweep frame. This will block until the sweep is complete,
# beware if your range includes low frequencies!
frame = i.get_data()
# Known
# Note that Z_in will vary for Moku:Go based on the parallel resistance
Z_in= 50 #ohms
V_out = 1 #Vpp
# Check the parameters of the FRA
print(i.summary())
# Taking Power Measurement at 300 Hz from Input 1 and Input 2
frequency_1 = frame['ch1']['frequency']
magnitude_1 = frame['ch1']['magnitude']
index_1_300hz = np.argmin(np.abs(np.array(frequency_1) - 300))
magnitude_300hz_ch1 = magnitude_1[index_1_300hz]
frequency_2 = frame['ch2']['frequency']
magnitude_2 = frame['ch2']['magnitude']
index_2_300hz = np.argmin(np.abs(np.array(frequency_2) - 300))
magnitude_300hz_ch2 = magnitude_2[index_2_300hz]
# Print the corresponding magnitude values at the desired frequency
print(f"The magnitude of channel 1 at 300 Hz is: {magnitude_300hz_ch1:.4f} dBm")
print (f"The magnitude of channel 2 at 300 Hz is: {magnitude_300hz_ch2:.4f} dBm")
# Convert magnitudes from dBm to linear scale
linear_magnitude_1 = 10 ** (magnitude_300hz_ch1 / 10)
linear_magnitude_2 = 10 ** (magnitude_300hz_ch2/ 10)
# Take the ratio of Channel 2 to Channel 1
linear_result = linear_magnitude_2 / linear_magnitude_1
# Convert linear result back to dBm
result_dB = 10 * np.log10(linear_result)
# Print result (Ch2/Ch1)
print(f"Channel 2 divided by Channel 1 results in: {result_dB:.4f} dBm")
# Use the power ratio to calculate the impedance of your device under test
x = 10**(result_dB/10)
power_ratio= np.sqrt(x)
Z_dut = (power_ratio*Z_in)-Z_in
print(f"The impedance of the device under test is: {Z_dut:.2f} Ohms")
except Exception as e:
print(f'Exception occurred: {e}')
finally:
# Close the connection to the Moku device
# This ensures network resources and released correctly
i.relinquish_ownership()