如何改变Moku锁相放大器中解调信号的相位
了解如何调整Moku锁相放大器中解调信号的相位,以优化信号处理并实现更精确的测量。
Moku锁相放大器使用双相解调来确定信号的 X 和 Y 分量。通过调整解调信号属性,可以在 Python 中移动解调信号的相位。
此示例演示了如何调整解调信号相位。
#
# Moku example: Phase change in Moku Lock-In Amplifier
#
# This example demonstrates how you can shift the phase of the demodulation signal
# in the Lock-In Amplifier instrument
#
# (c) 2024 Liquid Pty. Ltd.
#
# This is configured for Moku:Lab and is compatible with Moku:Go and Moku:Pro
#
# Setup : loopback Moku output 2 to input 1 with a BNC cable.
#
# The phase of the demodulation signal is then swept
# a full 360 degrees and the resulting LIA output DC signal
# reflects the phase offset between the PLL and input 1.
#
from moku.instruments import LockInAmp
import statistics
import matplotlib.pyplot as plt
# Launch Lock In Amplifier and connect to your device via IP
i = LockInAmp('192.168.2.74', force_connect=True)
try:
# Configure analog input port 1 as 50 Ohm and 0 dB attenuation
i.set_frontend(1, coupling='DC', impedance='50Ohm', attenuation='0dB')
# Output a 1MHz sine wave and demodulate at same
i.set_demodulation(mode='Internal', frequency=1e6)
i.set_filter(corner_frequency=1e1, slope="Slope6dB")
# Output the 'X' (I) signal and the local-oscillator sine wave on the two
# DAC channels.
i.set_aux_output(frequency=1e6, amplitude=1)
i.set_outputs(main='X', aux='Aux', main_offset=0, aux_offset=0)
i.use_pid("Off")
i.set_gain(main=0, aux=0)
# Monitor the I and Q signals from the mixer, before filtering
i.set_monitor(1, 'Input1')
i.set_monitor(2, 'MainOutput')
# Trigger on Monitor 'B' ('I' signal), rising edge, 0V with 0.1V hysteresis
i.set_trigger(source='ProbeB', edge='Rising', hysteresis=0.1)
# View +- 0.1 second, ie trigger in the centre
i.set_timebase(-2e-6, 2e-6)
# Set up the plotting parameters
plt.figure(num="Moku Lock-in Amplifier")
plt.ylabel("Voltage (V)")
plt.xlabel("Time [s]")
line1, = plt.plot([], label='Input 1')
line2, = plt.plot([], label='LIA X out')
# Configure labels for axes
ax = plt.gca()
plt.pause(1)
# This loops through a phase range of 0 to 350 degrees with a step size of 10
for a in range(0, 351, 10):
# Set a demodulation phase
i.set_demodulation(mode='Internal', phase=a)
data = i.get_data(wait_complete=True, wait_reacquire=True)
dc2 = data['ch2']
# Print out the demodulation phase and mean value of the output
print(f'New Phase: {a}')
print(f'Mean: {statistics.mean(dc2)}')
# Update the Plotting
line1.set_ydata(data['ch1'])
line1.set_xdata(data['time'])
line2.set_ydata(data['ch2'])
line2.set_xdata(data['time'])
plt.pause(0.1)
plt.legend(loc='upper left')
# Ensure frequency axis is a tight fit
ax.relim()
ax.autoscale_view()
finally:
# Close the connection to the Moku device
# This ensures network resources and released correctly
i.relinquish_ownership()