.. |MLA (TM)| unicode:: MLA U+2122 .. index:: multifrequency lockin measurement, .. _multifrequency-basics-label: Multifrequency Lockin Basics ============================ .. _lockin-measurement-label: 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 :math:`\omega`, while a phase-locked reference oscillation at the same frequency :math:`\omega` is used to demodulate, or determine the systems response to the excitation. Let us denote the response signal as :math:`V(t)`. The lockin multiplies this signal with two unity-amplitude reference oscillations and integrates over time, to give two **quadrature components**. :math:`I = \frac{1}{T_m}\int_0^{T_m} V(t)\cos(\omega t)dt` :math:`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 :math:`\omega` with amplitude :math:`A` and phase :math:`\phi`, :math:`V(t) = A \cos(\omega t + \phi)` . and we perform the integrations over a :ref:`measurement_time_window`, :math:`T_m = M (2 \pi / \omega)`, corresponding to an integer number :math:`M` times the oscillation period :math:`T=2\pi/\omega`, we find :math:`I = \tfrac{1}{2} A \cos(\phi)` :math:`Q = \tfrac{1}{2} A \sin(\phi)`. The quadratures :math:`I` and :math:`Q` are the Fourier coefficients of the response, at the reference frequency. Note that at DC, or :math:`\omega=0`, the integration gives :math:`I=A` and :math:`Q=0`. At any non-zero frequency we find the following relation between the quadratures :math:`I` and :math:`Q` and the response signal amplitude :math:`A`. :math:`A = 2 \sqrt{I^2 + Q^2}` The response phase is :math:`\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, :math:`\hat{V} = I + i Q` We call the absolute value of this complex number the **quadrature amplitude** :math:`A_\mathrm{quad} = \sqrt{I^2 + Q^2} = A/2` Note that at DC, or :math:`\omega=0`, the last equivalence does not hold, and we find :math:`A_\mathrm{quad}=A`. In the time domain the response signal can then be written, :math:`V(t) = \hat{V} e^{i \omega t} + \hat{V}^* e^{-i \omega t}` where :math:`\hat{V}^* = I -iQ` is the complex conjugate of :math:`\hat{V}`. Equivalently :math:`V(t) = 2 \mathbf{Re} \left[ \hat{V} e^{i \omega t} \right] = 2I \cos(\omega t) + 2Q \sin(\omega t)` .. index:: time window, tone, tones, base tone, tuning 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 :ref:`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 (TM)|. The |MLA (TM)| 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 :ref:`tones`, each having a frequency, :ref:`amplitude` and phase (or alternatively frequency, and two quadrature amplitudes). The |MLA (TM)| is special in that all tones can be locked to one reference, which is also locked to the :ref:`measurement_bandwidth` :math:`\delta f`, or inverse of the :ref:`measurement_time_window` :math:`\delta T_m = 1 / \delta f`. Unlike other multifrequency lockins which are simply many independent lockins in one box (the |MLA (TM)| can also run in this mode), the |MLA (TM)| uses special digital algorithms to achieve many synchronous lockins, all working off the same reference. This synchronous mode of operation is achieved by :ref:`tuning` the frequencies of all tones to ensure that they are integer multiples of :math:`\delta f`. The number of tones :math:`N` in your |MLA (TM)| may depend on the particular firmware that you are running, but typically :math:`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 (TM)| 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 (TM)| measures (demodulates) the quadrature amplitudes of the response at its input ports, at the frequency of each of the :math:`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 :ref:`measurement_time_window` :math:`T_m`, as described above. Thus, :math:`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 :ref:`pixel`, because the |MLA (TM)| was first used in multifrequency AFM [Platz-2008]_, where each measurement time window corresponds to one image pixel. .. index:: Fourier leakage, harmonics, intermodulation products .. _leakage-label: Fourier leakage +++++++++++++++ When a physical system is driven with a number of pure :ref:`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. .. figure:: figures/fourier_leakage.png :figclass: align-center **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 :math:`\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 (TM)| 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 :ref:`tuning`, in analogy to the tuning of musical instruments. The easiest way to tune the |MLA (TM)| is to start with a desired measurement bandwidth :math:`\delta f = 1/T_m` and then choose all frequencies to be an integer multiples of :math:`\delta f`. .. math:: f_i = n_i \delta f :label: nidf where :math:`n_i` are a set of integers. .. index:: harmonics, intermodulation products .. _nonlinearity-label: 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 (TM)| is the accurate measurement of many intermodulation products [Tholen-2011]_. When many drive tones are present: :math:`f_0, f_1, f_2 ...`, nonlinear response is generated at very many new frequencies, .. math:: f_{\textsc{\tiny IMP}} = k_0 f_0 + k_1 f_1 + k_2 f_2 + ... :label: fimp were :math:`k_0, k_1, k_2 ...` are any integer. Equation :eq:`fimp` tells us that all frequencies in the nonlinear response will be at integer multiples of a :ref:`base_tone` :math:`\Delta f`, if we choose the frequencies such that they all have a **greatest common divisor** :math:`\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 :math:`T= 1 / \Delta f` defines the period of the multifrequency waveform. A positive effect of the constraint :eq:`nidf` is that all harmonics and intermodulation products generated by nonlinearity, will also be at frequencies :math:`f_{\textsc{\tiny IMP}} = n \delta f`, where :math:`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 :math:`\Delta f` and the measurement bandwidth :math:`\delta f` are not necessarily the same, but they must have an integer relationship, .. math:: \Delta f = m \delta f :label: dfDf where :math:`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 :math:`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. .. index: Continuous lockin measurements, buffers, reading data, data transfer .. _continous_lockin_measurements-label: .. index:: tuning, setting up a multifrequency lockin measurement, .. _setup-and-tuning-label: setup and tuning functions ++++++++++++++++++++++++++ When as many as 40 frequencies are involved, setting up the measurement can be a complicated procedure. The |MLA (TM)| does have a Graphical User Interface (:ref:`mla-gui-label`) 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 (TM)| also has a powerful Application Programming Interface (:ref:`mla-api-label`) 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 :ref:`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 :ref:`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 (TM)| 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 :ref:`finite-accuracy-label`). See full function documentation in the :ref:`mla-api-label`, subsection :ref:`lockin-label`, :func:`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 :eq:`nidf` 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 :ref:`mla-api-label`, subsection :ref:`lockin-label`, :func:`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 :ref:`finite-accuracy-label`). 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 :ref:`mla-api-label`, subsection :ref:`lockin-label`, :func:`lockin.Lockin.tune2`. The |MLA (TM)| 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 (TM)|, 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 :eq:`nidf` is fulfilled, either with the above tuning functions, or with their own tuning algorithm. For further discussion of tuning algorithms, see :ref:`finite-accuracy-label`. .. index:: frequency combs, tuning .. _tuning-frequency-combs-label: 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 :eq:`nidf` and :eq:`dfDf` above. In this case the frequencies of all tones will be defined by set of integers :math:`n_i` and a measurement bandwidth :math:`\delta f`. We call waveforms of this type a :ref:`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 :math:`N` measurement and excitation frequencies where ever you want on this grid. Once you have constructed the set of integers :math:`n_i`, use the following function to configure the |MLA (TM)|: * ``ns, df, f = set_frequencies_by_n_and_df(n, df, tune=False, wait_for_effect=True)`` takes and array of integers :math:`n_i` and a bandwidth :math:`\delta f` and sets the lockin frequencies to be :math:`f_i = n_i \delta f`. The function returns the number of samples per :ref:`pixel` :math:`n_s`, the tuned bandwidth :math:`\delta f` and an array with the set frequencies :math:`f_i`. See full function documentation in the :ref:`mla-api-label`, subsection :ref:`lockin-label`, :func:`lockin.Lockin.set_frequencies_by_n_and_df`. The array of integers :math:`n_i` is often calculated relative to some tuned 'carrier' frequency. It is best to call this function using a tuned bandwidth :math:`\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: .. code :: # 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 :ref:`finite-accuracy-label`. .. index:: Advanced lockin topics .. _advanced_lockin-label: 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 (TM)|. If you feel that an important explanation is missing from this manual, please contact **Intermodulation Products** with questions and suggestions. We appreciate the feedback! .. toctree:: :maxdepth: 1 advanced_lockin