Multifrequency Lockin Basics

lockin measurement

The lockin technique is generally defined by its use of a reference oscillation for making a narrow-band measurement of some physical process [Dicke-1946]. The physical system is excited or modulated with a sinusoidal signal of frequency \omega, while a phase-locked reference oscillation at the same frequency \omega is used to demodulate, or determine the systems response to the excitation.

Let us denote the response signal as V(t). The lockin multiplies this signal with two unity-amplitude reference oscillations and integrates over time, to give two quadrature components.

I = \frac{1}{T_m}\int_0^{T_m} V(t)\cos(\omega t)dt

Q = \frac{1}{T_m}\int_0^{T_m} V(t)\sin(\omega t)dt

If the response signal is an oscillation at the frequency \omega with amplitude A and phase \phi,

V(t) = A \cos(\omega t + \phi) .

and we perform the integrations over a measurement time window, T_m = M (2 \pi / \omega), corresponding to an integer number M times the oscillation period T=2\pi/\omega, we find

I = \tfrac{1}{2} A \cos(\phi)

Q = \tfrac{1}{2} A \sin(\phi).

The quadratures I and Q are the Fourier coefficients of the response, at the reference frequency. Note that at DC, or \omega=0, the integration gives I=A and Q=0. At any non-zero frequency we find the following relation between the quadratures I and Q and the response signal amplitude A.

A = 2 \sqrt{I^2 + Q^2}

The response phase is

\phi = \tan^{-1}( Q/I ).

This response phase is with respect to the phase of the reference oscillation, which has zero phase by definition. It is very useful to represent the response signal as complex number,

\hat{V} = I + i Q

We call the absolute value of this complex number the quadrature amplitude

A_\mathrm{quad} = \sqrt{I^2 + Q^2} = A/2

Note that at DC, or \omega=0, the last equivalence does not hold, and we find A_\mathrm{quad}=A.

In the time domain the response signal can then be written,

V(t) = \hat{V} e^{i \omega t} + \hat{V}^* e^{-i \omega t}

where \hat{V}^* = I -iQ is the complex conjugate of \hat{V}. Equivalently

V(t) = 2 \mathbf{Re} \left[  \hat{V} e^{i \omega t} \right] = 2I \cos(\omega t) + 2Q \sin(\omega t)

demodulating multiple frequencies

Lockin measurement at one frequency is straight forward, but what happens when there are two frequencies in the excitation waveform and we want to measure the Fourier coefficients of the response at these two frequencies, and perhaps other frequencies. One could use each excitation frequency as a separate reference, but it is far better to define one global reference for all frequencies. The global reference is possible if you carefully choose the excitation frequencies in a process that we call tuning, in direct analogy to the tuning of musical instruments. Below we explain why one should tune a multi-frequency lockin measurement, and how tuning is done with the MLA™.

The MLA™ will excite a physical system with a waveform consisting of many different frequency components, and simultaneously measure both quadratures of the response (i.e. demodulate) at many frequencies. We refer to the components of the excitation signal and response signal as tones, each having a frequency, amplitude and phase (or alternatively frequency, and two quadrature amplitudes). The MLA™ is special in that all tones can be locked to one reference, which is also locked to the measurement bandwidth \delta f, or inverse of the measurement time window \delta T_m = 1 / \delta f. Unlike other multifrequency lockins which are simply many independent lockins in one box (the MLA™ can also run in this mode), the MLA™ uses special digital algorithms to achieve many synchronous lockins, all working off the same reference. This synchronous mode of operation is achieved by tuning the frequencies of all tones to ensure that they are integer multiples of \delta f.

The number of tones N in your MLA™ may depend on the particular firmware that you are running, but typically N \leq 40. The amplitude and phase of each drive tone in the multifrequency excitation is set by the user, and each tone can be directed to either or both of the MLA™ output ports. If you do not wish to drive but only ‘listen’ (measure) a particular frequency, simply set both bits of the output-mask to zero at this tone, or set the output amplitude to zero. The MLA™ measures (demodulates) the quadrature amplitudes of the response at its input ports, at the frequency of each of the N tones. Any tone can be demodulated at one of the 4 input ports.

The demodulation of the response is done by multiplying each digital sample of the input signal with an appropriate demodulating tone and summing over the measurement time window T_m, as described above. Thus, T_m plays the role of the time-constant of a traditional lockin. We need a word that refers to the data contained in this time window and we chose the word pixel, because the MLA™ was first used in multifrequency AFM [Platz-2008], where each measurement time window corresponds to one image pixel.

Fourier leakage

When a physical system is driven with a number of pure tones, these tones may affect each other in various ways. If the physical system is perfectly linear the principle of superposition applies: The total response is simply a sum, or linear combination of the individual responses at the frequencies of each drive tone. However, Fourier leakage may affect your ability to demodulate and independently measure the various response tones. Fourier leakage occurs when a tone is not perfectly periodic in the measurement time window. A strong tone will ‘leak’ over in to neighboring frequencies in the spectrum and destroy the measurement of other weaker tones.

A digital lockin samples the signal at discrete times and the quadrature amplitudes are calculated with discrete sums. These sums will be corrupted by Fourier leakage when any of the lockin frequencies and sampling frequency are not commensurate (i.e. do not have a common divisor). Thus, the sampling frequency becomes an ideal reference for all tones in a multifrequency digital lockin. Figure 1 demonstrates the connection between sampling and Fourier leakage.

_images/fourier_leakage.png

Figure 1: A multifrequency signal with three tones is sampled and Fourier amplitudes are calculated by discrete Fourier sums. The red samples are incommensurate with the frequencies of the tones and the Fourier amplitudes are corrupted with Fourier leakage. The blue samples are commensurate and the spectrum has no leakage, showing amplitude only at the three frequencies contained in the signal. We avoid Fourier leakage by tuning the frequencies of all tones so that they are integer multiples of \delta f = 1 / T_m, shown by the black grid on the frequency axis.

Fourier leakage can be reduced by so-called windowing, or equivalently, low pass filtering of the demodulated signal, but these methods are imperfect and they can not completely prevent leakage. To completely avoid Fourier leakage, the MLA™ is designed to work only with frequencies that perform an integer number of oscillations in the measurement time window. The process of choosing the best frequencies for measurement is called tuning, in analogy to the tuning of musical instruments. The easiest way to tune the MLA™ is to start with a desired measurement bandwidth \delta f = 1/T_m and then choose all frequencies to be an integer multiples of \delta f.

(1)f_i  = n_i \delta f

where n_i are a set of integers.

tuning and nonlinearity

Fourier leakage is an issue for the measurement of linear systems, but more fascinating is an effect that occurs in nonlinear systems. A nonlinear system will generate new tones in the response waveform that are not in the drive waveform. Harmonics are generated at exact integer multiples of the drive frequencies and they will occur in nonlinear systems driven with only one tone. Intermodulation products, or mixing products occur when two or more tones are present in the drive, and these occur at frequencies that are integer linear combinations of the drive frequencies. One of the primary design goals of the MLA™ is the accurate measurement of many intermodulation products [Tholen-2011].

When many drive tones are present: f_0, f_1, f_2 ..., nonlinear response is generated at very many new frequencies,

(2)f_{\textsc{\tiny IMP}} = k_0 f_0 + k_1 f_1 + k_2 f_2 + ...

were k_0, k_1, k_2 ... are any integer.

Equation (2) tells us that all frequencies in the nonlinear response will be at integer multiples of a base tone \Delta f, if we choose the frequencies such that they all have a greatest common divisor \Delta f. This property of a tonal system in music is referred to as ‘just intonation’ or ‘just temperament’.

The inverse of the base tone T= 1 / \Delta f defines the period of the multifrequency waveform. A positive effect of the constraint (1) is that all harmonics and intermodulation products generated by nonlinearity, will also be at frequencies f_{\textsc{\tiny IMP}} = n \delta f, where n is an integer. Thus, tuning the measurement also means that the nonlinear response will not be affected by Fourier leakage.

Note that the base tone \Delta f and the measurement bandwidth \delta f are not necessarily the same, but they must have an integer relationship,

(3)\Delta f  = m \delta f

where m \geq 1 is a positive integer. You can improve the signal-to-noise ratio by reducing the measurement bandwidth while keeping the same base tone (i.e. make m>1). Choosing the base tone to be 2, 3, 4,… times the measurement bandwidth allows you to check for period-doubling, period-tripling, period-quadrupeling,etc., bifurcations in nonlinear response.

setup and tuning functions

When as many as 40 frequencies are involved, setting up the measurement can be a complicated procedure. The MLA™ does have a Graphical User Interface (MLA GUI) with fields for adjusting the drive and reading the response amplitude and phase of each individual tone. But setup and measurement in this manner is often not practical. The MLA™ also has a powerful Application Programming Interface (MLA API) which allows for full setup and control using commands in a Python script. It is simple to edit these scripts and run them directly in the GUI, making for a very flexible environment to set up and test complex multifrequency measurements.

Within the API there are several convenience functions available to facilitate tuning. Tuning functions take a set of target frequencies and a target measurement bandwidth as input arguments. They return a tuned set of frequencies and tuned measurement bandwidth. The set of frequencies can be an entire array of values, or a single ‘carrier frequency’, around which you might build a frequency comb.

The tuning functions behave according to the following rules:

  • f, df = mla.lockin.tune0(f, df) performs only the minimum about of tuning necessary to make the requested numbers fit the corresponding digital registers in the MLA™ hardware. No attempts are made to avoid Fourier leakage. This function should be used together with a user-defined tuning algorithm, or in rare cases where Fourier leakage is known not to be an issue, for example when measuring strong tones well separated in frequency. If you are using this function, you will probably want to also use mla.lockin.reset_awgen_on_new_pixel(False) to avoid jumps in the signal at the end of each measurement time window (see finite accuracy and perfect tuning). See full function documentation in the MLA API, subsection mla.lockin, lockin.Lockin.tune0().

  • f, df = mla.lockin.tune1(f, df, priority='f') gives the standard level of tuning, adequate for most measurements. The returned array of frequencies and bandwidth are selected so that they fulfill the condition (1) which avoids Fourier leakage. The key-word argument priority='f' puts the highest priority on getting the frequencies as close as possible to the requested frequencies. With priority priority='df' the highest priority is put on getting the measurement bandwidth as close as possible to the requested measurement bandwidth. See full function documentation in the MLA API, subsection mla.lockin, lockin.Lockin.tune1().

  • f, df = mla.lockin.tune2(f, df, priority='f') results in the most rigid tuning which forces the number of samples in the measurement time window to be a power of 2 (see finite accuracy and perfect tuning). In this case the command mla.lockin.reset_awgen_on_new_pixel(False) has no effect because there is no phase correction. This tuning is normally not used because it significantly restricts the available frequencies. See full function documentation in the MLA API, subsection mla.lockin, lockin.Lockin.tune2().

The MLA™ is not configured by simply calling a tuning function. The separate functions mla.lockin.set_frequencies(f) and mla.lockin.set_measurement_bandwidth(df) transfer the tuned values to the MLA™, configuring it for measurement. If these functions are used without tuning, the measurement will suffer from Fourier leakage and phase drift. It is therefore up to the user ensure that the condition (1) is fulfilled, either with the above tuning functions, or with their own tuning algorithm.

For further discussion of tuning algorithms, see finite accuracy and perfect tuning.

tuning frequency combs

The three tuning functions described above do not represent the only possible ways to tune the measurement. As with tuning systems in music, there many ways to choose the tones and the best way may depend on the particular measurement that you would like to perform. You can experiment with your own tuning methods, but to avoid phase drift and Fourier leakage, one should conform to the constraints (1) and (3) above. In this case the frequencies of all tones will be defined by set of integers n_i and a measurement bandwidth \delta f.

We call waveforms of this type a frequency comb, because all tones exist on a equally spaced grid of frequencies, like teeth of the comb for your hair. You can choose to place your N measurement and excitation frequencies where ever you want on this grid. Once you have constructed the set of integers n_i, use the following function to configure the MLA™:

  • ns, df, f = set_frequencies_by_n_and_df(n, df, tune=False, wait_for_effect=True) takes and array of integers n_i and a bandwidth \delta f and sets the lockin frequencies to be f_i = n_i \delta f. The function returns the number of samples per pixel n_s, the tuned bandwidth \delta f and an array with the set frequencies f_i. See full function documentation in the MLA API, subsection mla.lockin, lockin.Lockin.set_frequencies_by_n_and_df().

The array of integers n_i is often calculated relative to some tuned ‘carrier’ frequency. It is best to call this function using a tuned bandwidth \delta f and carrier frequency, both of which are first determined using one of tuning functions described above. We demonstrate this in the following example script:

# Example for setting a comb of 5 pairs of tones equally spaced around a single carrier frequency
# Choose the carrier frequency and measurement bandwidth
_fc = 100e3  # Target carrier frequency
_df = 1e3  # Target measurement bandwidth
nr_freq = 11  # Number of frequencies in the comb

# Tune fc and df
fc, df = mla.lockin.tune2(_fc, _df)  # perfect tuning, priority on carrier frequency

# Build the frequency comb
n_c = int(np.round(fp/df)) #integer corresponding to the tuned carrier frequency
n_low = n_c - np.arange(nr_freq/2, 0, -1)
n_high = n_c + np.arange(1, nr_freq/2+1, 1)
n_comb = np.concatenate(([n_c], n_low, n_high))

# Configure lockin with the comb of frequencies
mla.lockin.set_frequencies_by_n_and_df(n_comb, df)

For further discussion of tuning algorithms, see finite accuracy and perfect tuning.

advanced lockin topics

The general introduction above is augmented by several advanced sections with a more detailed explanation of the particular features and concepts behind the MLA™. If you feel that an important explanation is missing from this manual, please contact Intermodulation Products <info@intermodulation-products.com> with questions and suggestions. We appreciate the feedback!