Application Notes

Lock-in Amplifier (LIA) Frequency Sweep with LabVIEW — A programming tutorial with Moku:Lab & LabVIEW

In this application note, we will provide a step-by-step tutorial on how to use Moku:Lab’s LabVIEW API to build an automated test sequence. Many electronic systems perform optimally at a specific operating frequency. To maximize the signal-to-noise ratio of a lock-in measurement, it’s important to find the transfer function of the system and to use the optimal modulation frequency. In this example, we will build a LabVIEW VI that scans the frequency of the local oscillator (LO) and plots the measured amplitude as a function of LO frequency. Then, we will use this VI to measure the transfer function of a bandpass filter.

Download Printable Version

Frequency Sweep Lock-in Detection

A Lock-In Amplifier (LIA) is designed to extract extremely weak oscillating signals from a noisy background. The LIA takes the input signal and mixes it with a local oscillator (LO) of a certain frequency. Then, a narrow band lowpass filter is applied to attenuate the high frequency components. More details on the principle of the Lock-In Amplifier can be found in this video: This detection method allows us to measure signal response at any arbitrary frequency with narrow bandwidths. The center of the measured frequency is defined by the frequency of the LO. By sweeping the frequency of the LO, the transfer function of the system can be measured. We can use such a response plot to determine the resonance, optimal modulation frequency, and impedance of the system. It is an essential test to perform in order to get the maximum signal-to-noise ratio for a lock-in measurement. In this application note, we will demonstrate how to use Moku:Lab’s LabVIEW API to build an automated test sequence to sweep the LO frequency and measure the response of a bandpass filter.

Figure 1: General flow of the automated test sequence.

System Setup

The installation file and instructions for Moku:Lab LabVIEW API are located here:

The complete LabVIEW .VI file is available for download here:

To control and operate Moku:Lab with LabVIEW, we need to connect Moku:Lab and the computer to the same network. In this example, we connected Moku:Lab and the computer wirelessly to the same Wi-Fi router.

To locate Moku:Lab on the network, the IP address is required. To find the IP address, connect an iPad to the same Wi-Fi network and launch Moku:Lab’s iPad app. Then, with a long press on Moku:Lab’s icon, the IP address will be displayed. Alternatively, if you have Python and PyMoku installed on your computer, you can find Moku:Lab’s IP address with the command “moku list”.

The LO is generated from Moku:Lab’s output 2, passed through the bandpass filter device under test (DUT), and the return signal measured at Moku:Lab’s input 1.

Figure 2: Moku:Lab and the computer were connected wirelessly to the same router. The DUT was inserted between Moku output 2 and input 1.

Building the LabVIEW VI

Connect to the Moku:Lab and deploy the default settings

To start building the LabVIEW VI, we first start up LabVIEW and drag the “setup moku” palette into our program:

Step 1: Drag “setup moku” palette into the VI

This palette takes two string inputs: Moku:Lab’s IP address and the name of the instrument. We create a place holder on the user interface for the user to enter the IP address. The Lock-In Amplifier instrument is used throughout the entire program, so we set it as default instrument name. Next, we pass the http-reference, moku command feedback and error out output to the “execute cmd” palette.

Step 2: Connect the http reference and route the Moku command and error out to the “execute cmd“ palette

The “execute cmd” palette uses the http-reference as a device handle and passes JSON formatted commands to Moku:Lab. The JSON command is typically generated by another VI. The “execute cmd” palette also takes the command feedback to pass it along to the program for logging, and the error out flag to ensure that every “execute cmd” palette is successfully executed. If the flag is raised, the program will be terminated. The “set default LIA” palette generates the JSON command to initialize the Lock-In Amplifier and set every parameter to the default values. This command is used to start the Lock-In Amplifier instrument on Moku:Lab.

Figure 3: Connect and initialize the LIA instrument.

Set up parameters for the lock-in detection

After the device is initialized, we use the same “execute cmd” palette structure to modify the settings for the Lock-In Amplifier (Step 3-9).

Step 3: Configure the two Moku:Lab outputs; one for the LIA to R (amplitude, main channel) and the second to LO (aux oscillator) for the frequency sweep.

Step 4 and 5: Set the two monitor points; one at the main and one at aux outputs. The main output monitor point is later used to acquire real-time data.

Step 6: Set the time base for the monitor points and real-time data acquisition.

Step 7: Set the gain for the main channel.

Step 8: Set the range for the R-Theta conversion. Details about the R-Theta conversion can be found in Moku:Lab’s Lock-In Amplifier user manual.

Step 9: Configure the lowpass filter that is immediately after the mixer.

Figure 4: Palettes to set up the parameters for LIA.

For-loop for automated frequency sweep

A for-loop is used to iterate the frequency sweep and data acquisition. We create three customizable parameters for the loop: number of steps, frequency step, and initial frequency. At the start of each iteration, the program calculates the LO’s frequency based on i×???????????????????????????????????? ????????????????+???????????????????????????? ????????????????????????????????????. Then, this number is split into two, passed to the “set demod LIA” palette as the frequency input (step 11), as well as the x-axis location for the plot.

Figure 5: For Loop to iterate the frequency sweep and data acquisition.

To ensure that the LO is set and stable before the data acquisition, a flat sequence is used to separate the setup portion and data acquisition portion. After a 100 ms dwell period, the “get realtime data” command is sent to Moku:Lab. The “execute cmd” palette receives the raw data and passes to the “parse data” palette to convert the raw data into numeric arrays.

Figure 6: Data transfer, average, and display.

After the “parse data” palette, the data stream from the aux channel (ch2) is damped. A mean function is used to take the average of the main channel numeric array. The result is then plotted on the user interface.

Measure the Filter Transfer Function

To measure the transfer function of the DUT bandpass filter (mini-circuit BBP-21.4), we set the initial frequency at 15 MHz, and frequency step at 400 kHz with 40 steps.


Figure 7: Frequency sweep analysis with bandpass filter.

The LabVIEW VI automatically sweeps the frequency of the LO and plots the amplitude of the detected signal. The filter has its peak response at around 22 MHz.

To learn more about Moku:Lab LabVIEW API, please visit:

Questions or comments?

Please contact us at [email protected]