Lock-in Amplifier Instrument

The Lock-in Amplifier instrument can be used to retrieve small signals of known frequency from within the noise floor. The Moku:Lab Lock-in supports internal or external demodulation (reference) frequency, multiple possible output signals and an optional PID controller to be used in a closed-loop system to drive the recovered signal towards a set point.

The Lock-in can have monitor points set up, providing a “virtual Oscillscope” view of input, output and internal signals. Once configured, these can be displayed and logged using the same API as the Oscilloscope object.

Example Usage

The following example code and a wide range of other pymoku demo scripts can be found at the pymoku Github repository.

lockinamp_basic.py
#
# pymoku example: Basic Lock-in Amplifier
#
# This example demonstrates how you can configure the lock-in amplifier
# instrument
#
# (c) 2019 Liquid Instruments Pty. Ltd.
#
from pymoku import Moku
from pymoku.instruments import LockInAmp

# Use Moku.get_by_serial() or get_by_name() if you don't know the IP
m = Moku.get_by_name('Moku')

try:
    i = m.deploy_or_connect(LockInAmp)

    # Configure the two DAC outputs to provide the R (magnitude) and
    # demodulation (local-oscillator in this case, see below) outputs.
    # Give the main ('R') channel 100x gain.
    i.set_outputs('R', 'demod')
    i.set_gain('main', 100)

    # Demodulate at 1MHz (internally-generated) with a 100Hz, 2nd-order
    # (6dB / octave) LPF.
    i.set_demodulation('internal', 1e6)
    i.set_filter(100, 2)
finally:
    m.close()

The LockInAmp Class

class pymoku.instruments.LockInAmp
commit()

Apply all modified settings.

Note

If the autocommit feature has been turned off, this function can be used to manually apply any instrument settings to the Moku device. These instrument settings are those configured by calling all set_ and gen_ type functions. Manually calling this function allows you to atomically apply many instrument settings at once.

enable_input(*args, **kwargs)

Enable or disable the PID channel input(s).

If ch is None (the default), both channels will be acted upon, otherwise just the one specified by the argument.

Parameters:
  • ch (int; {1,2} or None) – Output channel, or both.
  • en (bool) – Enable the specified input channel(s).
Raises:

InvalidParameterException – Invalid parameters

enable_output(*args, **kwargs)

Enable or disable the PID channel output(s).

If ch is None (the default), both channels will be acted upon, otherwise just the one specified by the argument.

Parameters:
  • ch (int; {1,2} or None) – Output channel, or both.
  • en (bool) – Enable the specified output channel(s).
Raises:

InvalidParameterException – Invalid parameters

get_data(timeout=None, wait=True)

Get full-resolution data from the instrument.

This will pause the instrument and download the entire contents of the instrument’s internal memory. This may include slightly more data than the instrument is set up to record due to rounding of some parameters in the instrument.

All settings must be committed before you call this function. If pymoku.autocommit=True (the default) then this will always be true, otherwise you will need to have called commit first.

The download process may take a second or so to complete. If you require high rate data, e.g. for rendering a plot, see get_realtime_data.

If the wait parameter is true (the default), this function will wait for any new settings to be applied before returning. That is, if you have set a new timebase (for example), calling this with wait=True will guarantee that the data returned has this new timebase.

Note that if instrument configuration is changed, a trigger event must occur before data captured with that configuration set can become available. This can take an arbitrary amount of time. For this reason the timeout should be set appropriately.

Parameters:
  • timeout (float) – Maximum time to wait for new data, or None for indefinite.
  • wait (bool) – If true (default), waits for a new waveform to be captured with the most recently-applied settings, otherwise just return the most recently captured valid data.
Returns:

InstrumentData subclass, specific to the instrument.

get_frontend(channel)

Get the analog frontend configuration.

Parameters:channel (int; {1,2}) – Channel for which the relay settings are being retrieved
Returns:Array of bool with the front end configuration of channels - [0] 50 Ohm - [1] 10xAttenuation - [2] AC Coupling
get_realtime_data(timeout=None, wait=True)

Get downsampled data from the instrument with low latency.

Returns a new InstrumentData subclass (instrument-specific), containing a version of the data that may have been downsampled from the original in order to be transferred quickly.

This function always returns a new object at framerate (10Hz by default), whether or not there is new data in that object. This can be verified by checking the return object’s waveformid parameter, which increments each time a new waveform is captured internally.

The downsampled, low-latency nature of this data makes it particularly suitable for plotting in real time. If you require high-accuracy, high-resolution data for analysis, see get_data.

If the wait parameter is true (the default), this function will wait for any new settings to be applied before returning. That is, if you have set a new timebase (for example), calling this with wait=True will guarantee that the data returned has this new timebase.

Note that if instrument configuration is changed, a trigger event must occur before data captured with that configuration set can become available. This can take an arbitrary amount of time. For this reason the timeout should be set appropriately.

Parameters:
  • timeout (float) – Maximum time to wait for new data, or None for indefinite.
  • wait (bool) – If true (default), waits for a new waveform to be captured with the most recently-applied settings, otherwise just return the most recently captured valid data.
Returns:

InstrumentData subclass, specific to the instrument.

get_samplerate()
Returns:The current instrument sample rate (Hz)
set_by_frequency(*args, **kwargs)

Configure the selected PID controller using crossover frequencies.

Parameters:
  • ch (int; [1,2]) – Channel of PID controller to configure
  • kp (float; [-1e3,1e3]) – Proportional gain factor
  • i_xover (float; [1e-3,1e6] Hz) – Integrator crossover frequency
  • d_xover (float; [1,10e6] Hz) – Differentiator crossover frequency
  • ii_xover (float; [1, 1e6] Hz) – Second integrator crossover frequency
  • si (float; float; [-1e3,1e3]) – Integrator gain saturation
  • sd (float; [-1e3,1e3]) – Differentiator gain saturation
  • in_offset (float; [-1.0,1.0] V) – Input signal offset
Raises:

InvalidConfigurationException – if the configuration of PID gains is not possible.

set_by_gain(*args, **kwargs)

Configure the selected PID controller using gain coefficients.

Parameters:
  • ch (int; [1,2]) – Channel of the PID controller to be configured.
  • g (float; [0,2^16 - 1]) – Gain
  • kp (float; [-1e3,1e3]) – Proportional gain factor
  • ki (float;) – Integrator gain factor
  • kd (float;) – Differentiator gain factor
  • kii (float;) – Second integrator gain factor
  • si (float; float; [-1e3,1e3]) – Integrator gain saturation
  • sd (float; [-1e3,1e3]) – Differentiator gain saturation
  • in_offset (float; [-1.0,1.0] V) – Input signal offset
Raises:

InvalidConfigurationException – if the configuration of PID gains is not possible.

set_control_matrix(**kwargs)

Warning

Method Deprecation: Deprecated.

set_defaults(*args, **kwargs)

Reset the lockinamp to sane defaults.

set_demodulation(*args, **kwargs)

Configure the demodulation stage.

The mode is one of:
  • internal : for an internally set local oscillator
  • external : to directly use an external signal for demodulation (Note: Q is not selectable in this mode)
  • external_pll : to use an external signal for demodulation after running it through an internal PLL.

Note

When ‘external’ is used (that is, without a PLL), the Lock-in Amplifier doesn’t know the frequency and therefore can’t form the quadrature for full I/Q demodulation. This in turn means it can’t distinguish I from Q, X from Y, or form R/Theta. This limits the choices for signals that can be output on the Main and AUX channels to ones not formed from the quadrature signal.

An exception will be raised if you attempt to set the demodulation to ‘external’ while viewing one of these signals.

Parameters:
  • mode (string; {'internal', 'external', 'external_pll'}) – Demodulation mode
  • frequency (float; [0, 200e6] Hz) – Internal demodulation signal frequency (ignored for all ‘external’ modes)
  • phase (float; [0, 360] deg) – Internal demodulation signal phase (ignored in ‘external’ mode)
  • output_amplitude (float; [0.0, 2.0] Vpp) – Output amplitude of the demodulation

signal when auxiliary channel set to output demod.

set_filter(*args, **kwargs)

Set the low-pass filter parameters.

Parameters:
  • f_corner (float; [300.0e-3, 5.0e6]) – Corner frequency of the low-pass filter (Hz)
  • order (int; [1, 2, 3, 4]) – filter order; 0 (bypass), first- or second-order.
set_framerate(*args, **kwargs)

Set framerate

set_frontend(channel, fiftyr=True, atten=False, ac=False)

Configures gain, coupling and termination for each channel.

Parameters:
  • channel (int; {1,2}) – Channel to which the settings should be applied
  • fiftyr (bool) – 50Ohm termination; default is 1MOhm.
  • atten (bool) – Turn on 10x attenuation. Changes the dynamic range between 1Vpp and 10Vpp.
  • ac (bool) – AC-couple; default DC.
set_gain(*args, **kwargs)

Sets the gain stage to be on the specified lock-in channel, and configures its gain.

This sets the PID stage to be on the opposite channel.

Parameters:
  • lia_ch (string; {'main','aux'}) – Channel name
  • g (float; [0, 2^16 - 1]) – Gain
set_input_range_r_theta(*args, **kwargs)

Sets the Rect-to-polar conversion range for r theta mode.

Three scaling ranges are available: 2 Vpp, 7.5 mVpp and 25 uVpp

Parameters:i_range (integer, [0, 1, 2]) – range selection, 0 = 2 Vpp, 1 = 7.5 mVpp, 2 = 25 uVpp
set_lo_output(*args, **kwargs)

Configure local oscillator output.

This output is available on Channel 2 of the Moku:Lab.

Parameters:
  • amplitude (float; [0.0, 2.0] Vpp) – Amplitude
  • frequency (float; [0, 200e6] Hz) – Frequency
  • phase (float; [0, 360] deg) – Phase
set_monitor(*args, **kwargs)

Select the point inside the lockin amplifier to monitor.

There are two monitoring channels available, ‘A’ and ‘B’; you can mux any of the internal monitoring points to either of these channels.

The source is one of:
  • none: Disable monitor channel
  • in1, in2: Input Channel 1/2
  • main: Lock-in output (Output Channel 1)
  • aux: auxiliary output (Output Channel 2)
  • demod: Demodulation signal input to mixer
  • i, q: Mixer I and Q channels respectively.
Parameters:
  • monitor_ch (string; {'A','B'}) – Monitor channel
  • source (string; {'none','in1','in2','main','aux','demod','i','q'}) – Signal to monitor
  • high_sensitivity_en (bool) – Enable high-sensitivity mode (for signals smaller than 25 mVpp)
set_outputs(*args, **kwargs)

Configures the main (Channel 1) and auxiliary (Channel 2) output signals of the Lock-In.

Note

When ‘external’ demodulation is used (that is, without a PLL), the Lock-in Amplifier doesn’t know the frequency and therefore can’t form the quadrature for full I/Q demodulation. This in turn means it can’t distinguish I from Q, X from Y, or form R/Theta. This limits the choices for signals that can be output on the AUX channel to ones not from the Lock-in logic (e.g. demodulation source, auxiliary sine wave etc).

An exception will be raised if you attempt to set the auxiliary channel to view aa signal from the Lock-in logic while external demodulation is enabled.

Parameters:
  • main (string; {'x', 'y', 'r', 'theta', 'offset', 'none'}) – Main output signal
  • aux (string; {'x', 'y', 'r', theta', 'sine', 'demod', 'offset', 'none'}) – auxiliary output signal
  • main_offset (float; [-1.0, 1.0] V) – Main output offset
  • aux_offset (float; [-1.0, 1.0] V) – auxiliary output offset
set_pid_by_frequency(*args, **kwargs)

Set which lock-in channel the PID is on and configure it using frequency domain parameters.

This sets the gain stage to be on the opposite channel.

Parameters:
  • lia_ch (string; {'main','aux'}) – Lock-in channel name to put PID on.
  • kp (float; [-1e3,1e3]) – Proportional gain factor
  • i_xover (float; [1e-3,1e6] Hz) – Integrator crossover frequency
  • d_xover (float; [1,10e6] Hz) – Differentiator crossover frequency
  • si (float; float; [-1e3,1e3]) – Integrator gain saturation
  • sd (float; [-1e3,1e3]) – Differentiator gain saturation
  • in_offset (float; [-1.0,1.0] V) – Input signal offset
  • out_offset (float; [-1.0, 1.0] V) – Output signal offset
Raises:

InvalidConfigurationException – if the configuration of PID gains is not possible.

set_pid_by_gain(*args, **kwargs)

Set which lock-in channel the PID is on and configure it using gain parameters.

This sets the gain stage to be on the opposite channel.

Parameters:
  • lia_ch (string; {'main','aux'}) – Lock-in channel name to put PID on
  • g (float; [0,2^16 - 1]) – Gain
  • kp (float; [-1e3,1e3]) – Proportional gain factor
  • ki (float;) – Integrator gain factor
  • kd (float;) – Differentiator gain factor
  • si (float; float; [-1e3,1e3]) – Integrator gain saturation
  • sd (float; [-1e3,1e3]) – Differentiator gain saturation
  • in_offset (float; [-1.0,1.0] V) – Input signal offset
  • out_offset (float; [-1.0, 1.0] V) – Output signal offset
Raises:

InvalidConfigurationException – if the configuration of PID gains is not possible.

set_precision_mode(*args, **kwargs)

Change aquisition mode between downsampling and decimation. Precision mode, a.k.a Decimation, samples at full rate and applies a low-pass filter to the data. This improves precision. Normal mode works by direct downsampling, throwing away points it doesn’t need.

Parameters:state (bool) – Select Precision Mode
set_samplerate(*args, **kwargs)

Manually set the sample rate of the instrument.

The sample rate is automatically calculated and set in set_timebase.

This interface allows you to specify the rate at which data is sampled, and set a trigger offset in number of samples. This interface is useful for datalogging and capturing of data frames.

Parameters:
  • samplerate (float; 0 < samplerate <= MAX_SAMPLERATE smp/s) – Target samples per second. Will get rounded to the nearest allowable unit.
  • trigger_offset (int; -2^16 < trigger_offset < 2^31) – Number of samples before (-) or after (+) the trigger point to start capturing.
Raises:

ValueOutOfRangeException – if either parameter is out of range.

set_timebase(*args, **kwargs)

Set the left- and right-hand span for the time axis. Units are seconds relative to the trigger point.

Parameters:
  • t1 (float) – Time, in seconds, from the trigger point to the left of screen. This may be negative (trigger on-screen) or positive (trigger off the left of screen).
  • t2 (float) – As t1 but to the right of screen.
Raises:

InvalidConfigurationException – if the timebase is backwards or zero.

set_trigger(*args, **kwargs)

Set the trigger source for the monitor channel signals. This can be either of the input or monitor signals, or the external input.

Parameters:
  • source (string, {'in1','in2','A','B','ext'}) – Trigger Source. May be either an input or monitor channel (as set by set_monitor()), or external. External refers to the back-panel connector of the same name, allowing triggering from an externally-generated digital [LV]TTL or CMOS signal.
  • edge (string, {'rising','falling','both'}) – Which edge to trigger on. In Pulse Width modes this specifies whether the pulse is positive (rising) or negative (falling), with the ‘both’ option being invalid.
  • level (float, [-10.0, 10.0] volts) – Trigger level
  • minwidth (float, seconds) – Minimum Pulse Width. 0 <= minwidth < (2^32/samplerate). Can’t be used with maxwidth.
  • maxwidth (float, seconds) – Maximum Pulse Width. 0 <= maxwidth < (2^32/samplerate). Can’t be used with minwidth.
  • hysteresis (float, [100e-6, 1.0] volts) – Hysteresis around trigger point.
  • hf_reject (bool) – Enable high-frequency noise rejection
  • mode (string, {'auto', 'normal'}) – Trigger mode.
set_xmode(*args, **kwargs)

Set rendering mode for the horizontal axis.

Parameters:xmode (string, {'roll','sweep','fullframe'}) – Respectively; Roll Mode (scrolling), Sweep Mode (normal oscilloscope trace sweeping across the screen) or Full Frame (like sweep, but waits for the frame to be completed).