Skip to main content

ORIGINAL RESEARCH article

Front. Sens., 30 March 2023
Sec. Sensor Devices

OLIA: An open-source digital lock-in amplifier

  • 1Department of Chemistry, Norwegian University of Science and Technology (NTNU), Trondheim, Norway
  • 2School of Chemical and Process Engineering, University of Leeds, Leeds, United Kingdom

The Open Lock-In Amplifier (OLIA) is a microcontroller-based digital lock-in amplifier built from a small number of inexpensive and easily sourced electronic components. Despite its small credit card-sized form-factor and low build-cost of around US$35, OLIA is a capable instrument that offers many features associated with far costlier commercial devices. Key features include dual-phase lock-in detection at multiple harmonic frequencies up to 50 kHz, internal and external reference modes, adjustable levels of input gain, a choice between low-pass filtering and synchronous filtering, noise estimation, and a comprehensive programming interface for remote software control. OLIA comes with an optional optical breakout board that allows noise-tolerant optical detection down to the 40-pW level. OLIA and its breakout board are released here as open hardware, with technical diagrams, full parts-lists, and source-code for the firmware.

1 Introduction

The measurement of weak signals in the presence of strong background noise is a ubiquitous problem in analytical science. In circumstances where the target signal varies only slowly with time, lock-in detection is an effective and easily implemented solution (Meade, 1982; Stimpson et al., 2019; Kishore and Akbar, 2020; Wang et al., 2023). In the lock-in method, a known modulation frequency is imposed on the target signal (e.g., by modulating the stimulus at the same frequency), and noise and interfering signals at other frequencies are eliminated by means of analogue or digital signal processing.

At its simplest, the lock-in approach requires just three elements: a waveform generator, a mixer, and a low-pass filter: the waveform generator produces a periodic signal of frequency fr that modulates the target signal and also serves as an internal reference signal; the mixer multiplies the target signal and the reference signal; and the low-pass filter rejects non-DC components of the mixed signal, leaving a slowly-varying DC signal that is proportional to the instantaneous amplitude of the target signal. Mixing and low-pass filtering can be carried out via analogue signal processing or digital signal processing (DSP), but DSP-based methods are typically best for modulation frequencies below 1 MHz as they minimise harmonic distortion and do not suffer from signal drift, leading to better signal recovery (Probst and Collet, 1985; Barragán et al., 2001). DSP-based lock-in detection has the further benefit of being implementable on low-cost, commodity hardware, making it an excellent choice for a wide range of cost-sensitive applications.

In this paper we report a simple, yet versatile, digital lock-in amplifier (LIA) based on a microcontroller development board and a small number of inexpensive, analogue components. While there have been a few previous reports of microcontroller-based LIAs (Bengtsson, 2012; Hofmann et al., 2012; Kim, 2014; Wang et al., 2017; Harvie et al., 2021; Pollastrone et al., 2023), only a small number have been released on a fully open basis (with complete design files, build instructions and source-code), and few have sought to replicate the full range of functionality offered by high-end commercial instruments. Our goal in releasing OLIA is to provide an inexpensive, easily upgraded, intermediate performance digital lock-in amplifier that is suitable for a wide range of physical measurements. We have prioritised simplicity of design and affordability over performance, but OLIA is nonetheless a capable instrument, and we believe it will find many uses in teaching and research. Key applications include optical detection, harmonic analysis, and impedance analysis.

Core functionality offered by OLIA includes: 1) dual-phase detection at multiple harmonic frequencies up to 50 kHz; 2) the choice between internal or external referencing; 3) the ability to select different time constants and varying levels of gain/reserve; 4) noise estimation; and 5) the option to select synchronous filtering at low modulation frequencies for faster settling times.

2 Overview of lock-in detection

We begin with a brief description of the lock-in procedure as implemented in OLIA. Figure 1 shows a block diagram, summarising the analysis procedure. The digitised input signal S is assumed for simplicity to be a pure sinusoid of angular frequency ωs, phase ϕs and amplitude S0:

S=S0sinωst+ϕs.(1)

FIGURE 1
www.frontiersin.org

FIGURE 1. Block diagram summarising analysis procedure. An input signal S is multiplied by orthogonal sinusoidal reference signals Qx and Qy. The resulting intermediate output signals X0 and Y0 are passed through two stages of low-pass exponential filtering (LPF), generating output signals X2 and Y2. X2 and Y2 may be re-expressed in terms of the total amplitude R2 and the phase ϕ2.

The lock-in amplifier generates two internal reference signals Qx and Qy of angular frequency ωr, which are separated in phase by π/2 radians:

Qx=2sinωrt+ϕr(2a)

and

Qy=2cosωrt+ϕr(2b)

where ϕr is a constant phase offset and the pre-factor of two is chosen for algebraic convenience.

In the first stage of lock-in amplification, the input signal S is multiplied by the two reference signals, generating two intermediate signals, X0 and Y0, where:

X0=2S0sinωst+ϕssinωrt+ϕr=S0cosωsωrt+ϕsϕrS0cosωs+ωrt+ϕs+ϕr(3a)

and

Y0=2S0sinωst+ϕscosωrt+ϕr=S0sin[ωsωrt+ϕsϕr]+S0sinωs+ωrt+ϕs+ϕr(3b)

Hence, for the typical case ωsωr, each channel gives two sinusoidal components at the sum and difference frequencies of ωs and ωr.

In the second stage of lock-in amplification we sequentially pass the intermediate output signals X0 and Y0 through two identical low-pass filters with a common cut-off frequency ω* that is much smaller than ωsωr. The filters heavily attenuate the two sinusoidal components of X0 and Y0, generating output signals X2 and Y2 that are close to zero.

Only when the frequency of the incoming signal is closely matched to the frequency of the reference signal (ωsωr|ω*) do we obtain non-zero outputs from the low-pass filters. For the special case ωs=ωr, the outputs of the two multipliers are given by:

X0=S0cosϕsϕrS0cos2ωst+ϕs+ϕr,(4a)

and

Y0=S0sinϕsϕr+S0sin2ωst+ϕs+ϕr(4b)

where the first term in each expression is a constant that depends only on the amplitude of the incoming signal and the phase difference between the incoming signal and the reference signal. After two-stage DC filtering, we therefore obtain

X2=S0cosϕsϕr,(5a)

and

Y2=S0sinϕsϕr.(5b)

where X2 and Y2 are the “in-phase” and “quadrature” components of the input signal. If S and Qx are exactly in phase (ϕs=ϕr) or exactly out of phase ϕsϕr=±π the entire signal appears in the X-channel, while if they are ninety degrees out of phase (ϕsϕr=±π/2), the entire signal appears in the Y-channel.

From Eqs 5a, 5b, we obtain expressions for the amplitude and relative phase of the input signal S in terms of X2 and Y2:

R2=X22+Y22=S0(6)

and

ϕ2=atanY2X2=ϕsϕr(7)

It follows from the above analysis, that a lock-in amplifier set to a reference frequency ωr is “blind” to all signals that differ from ωr by substantially more than the low-pass filter cut-off frequency ω*. Hence, if ωr is set to the fundamental frequency ωs of an incoming periodic signal (which need not be purely sinusoidal), the output R2 from the lock-in amplifier will equal the amplitude S0 of the first harmonic component of that signal. Signals at frequencies away from ωr—whether due to higher harmonics of the incoming signal, noise or other interferences—will be heavily attenuated by the long-pass filtering and will not significantly affect the value of R2.

The effective bandwidth is equal to twice the cut-off frequency of the low-pass filter (since signal frequencies just above and just below ωr are transformed to near-DC intermediate signals that partially survive the filtering step). Hence, lower cut-off frequencies provide better noise rejection, albeit at the expense of longer settling times (see Figure 4 in “Selected results”). Repeating the analytical procedure with a reference signal of frequency kωs where k is an integer greater than one allows the amplitude (and phase) of higher harmonics of the incoming signal to be determined.

Note, in the above analysis we assumed that the reference signals Qx and Qy and the incoming signal S had constant (time-invariant) phases, implying a fixed phase difference between them. In practice real signals are susceptible to jitter and drift which, left uncorrected, introduce noise and error into the lock-in measurement. To avoid these problems, the reference signals and incoming signal should be synchronised so that jitter or drift in the incoming signal is replicated in the reference signals, resulting in a constant phase difference between them. This may be achieved by means of a phase-locked-loop that causes the reference signals to “follow” the incoming signal or—more simply—by using one of the two internally generated reference signals to modulate the incoming signal. Both options are available in OLIA.

3 Implementation

OLIA is housed on a credit card-sized, two-sided printed circuit board (PCB) that accommodates hardware for analogue signal conditioning and a Teensy 4.0 microcontroller development board for signal sampling, digital signal processing, and external communication (Figure 2A). A separate break-out board is provided for optical detection (Figure 2B).

FIGURE 2
www.frontiersin.org

FIGURE 2. (A) Photograph of OLIA’s fully assembled printed circuit board (PCB). Inputs and outputs are made via two 4-pin terminal blocks (blue and white boxes, respectively). A 2-pin terminal block (green box) provides power pass-through from the USB port of the Teensy 4.0 (red box), which is used to both power the device and provide a connection to an external computer for data handling. We recommend using a quick-connect magnetic USB cable and connector as shown in the photo to prevent damage to the fragile micro-USB connector from repeated connection and disconnection. A potentiometer (yellow box) is used to bring OLIA into a lock condition with an external reference signal when it is operating in external referencing mode. (B) Photograph of break-out board for optical detection. Terminal blocks are used to supply power (green box) to the integrated DC servo circuit and the OPT101 amplified photodiode, and for electrical access (white box) to the output signal that feeds into OLIA. The amplified photodiode is soldered on the opposite side of the board in the position indicated by the red box. Complete schematics for the two PCBs are provided in the Supplementary Material.

4 Analogue signal conditioning

The first stage of the analogue conditioning circuit on OLIA’s PCB is a bipolar programmable gain amplifier (PGA) that offers amplification levels of 0 (“off”), 1, 2, 4, 8, 16, 32 and 64, while the second stage is a summing amplifier (S1 in Supplementary Figure S4) that converts a bipolar input signal in the range −1.65 V to +1.65 V into a unipolar output signal in the range 0–3.3 V, allowing it to be sampled by a built-in (unipolar) analogue-to-digital converter (ADC0) on the microcontroller. The third stage is a unity-gain low-pass filter with a cut-off frequency of 94 kHz, slightly less than half the default 200-kHz digitisation rate used by ADC0. The purpose of the low-pass filter is to attenuate noise and interferences above the 100-kHz Nyquist frequency of ADC0, and so reduce sampling artefacts due to aliasing. Full details of the signal conditioning circuitry are provided in Supplementary Figure S4.

A separate signal processing board containing an OPT101 amplified silicon photodiode and a DC servo circuit is also provided for optical detection (see Figure 2B; Supplementary Figure S5), with the servo circuit dynamically compensating any DC output from the photodiode due to (slowly varying) ambient light that would otherwise saturate ADC0. The DC servo circuit allows weak optical signals at the lock-in frequency to be measured even in the presence of strong ambient light.

5 Digital signal processing

5.1 Internal referencing

OLIA can operate with either an internal or an external reference signal. In the internal referencing mode, the lock-in procedure is carried out as follows. A 3.3 V square-wave equal in frequency and phase to Qxn is generated at a digital output pin of the microcontroller and is used to drive or modulate an external stimulus, generating an incoming analogue signal of frequency fs=fr. The modulated signal (together with noise and interfering signals at other frequencies) is sampled at discrete times tn=nΔt where the sample number n is a positive integer and Δt is the time interval between successive samples. Timing errors are minimised by choosing fr to be an exact integer fraction of the digitisation rate fd, i.e., fr=fd/m=1/mΔt where m is a positive integer greater than two. The in-phase and quadrature reference signals Qx and Qy are updated at each time-step as follows:

Qxn=2sin2πn/m(8a)

and

Qyn=2cos2πn/m(8b)

The sample values Sn are obtained from the ADC as 12-bit integers and stored as 64-bit doubles. All subsequent calculations are carried out at 64-bit precision using the microcontroller’s onboard Floating-Point Unit (FPU).

5.2 External referencing

In the external referencing mode, the digitisation rate is determined by an incoming 3.3 V TTL reference signal of frequency fext, which is phase-locked to the stimulus. The TTL signal is passed to a frequency multiplier on the PCB, which generates 64 phase-locked clock cycles per single TTL cycle (see Supplementary Figure S4). The frequency range of the multiplier circuit is determined by the potentiometer P1 and the fixed capacitor C8 in Supplementary Figure S4. For the chosen component values (C8 = 820 pF and 0 < P1 < 200 k Ω), the multiplier is able to accept reference signals in the range 130 Hz to 6 kHz, depending on the setting of P1. The frequency range may be pushed to higher or lower frequencies by lowering or raising the capacitance of C8.

The approximate frequency of the TTL signal is measured via a digital input pin of the microcontroller, which connects internally to a hardware counter on the microcontroller. For fext values below 1562.5 Hz, the signal is sampled on each rising or falling edge of the clock signal, resulting in 128 samples per complete TTL cycle, i.e., 128 samples per time period of the modulated signal being measured (up to a maximum digitisation rate of 200 kHz at fext = 1562.5 Hz). For signal frequencies in the range 1562.5–3,125 Hz, the signal is sampled on the rising edge of each clock cycle, resulting in 64 samples per complete TTL cycle (up to a maximum digitisation rate of 200 kHz at fext = 3,125 Hz). For TTL frequencies above 3,125 Hz, the signal is sampled on every Nth rising edge of the clock cycle where N = 2, 4, 8, or 16, resulting in 64/N samples per complete TTL cycle. The specific value of N is chosen to ensure the digitisation rate 64 fext/N is less than (but as close as possible to) the maximum permitted ADC digitisation rate of 200 kHz. At each sample the reference signals are updated as follows:

Qxn=2sin2πn/m*(9a)

and

Qyn=2cos2πn/m*(9b)

where n is again the sample number and m* is the number of samples per TTL cycle.

5.3 Lock-in detection

The lock-in procedure is implemented entirely in the digital domain at 64-bit double precision using the microcontroller’s built-in FPU. Multiplying Qxn and Qyn by the input signal Sn at each time step yields two (unfiltered) intermediate outputs X0n and Y0n:

X0n=QxnSn(10a)

and

Y0n=QynSn(10b)

The low-pass filtering step is carried out by exponentially averaging X0n and Y0n, (Finch, 2009) which yields two intermediate outputs X1n and Y1n:

X1n=X1n1+αX0nX1n1(11a)

and

Y1n=Y1n1+αY0nY1n1,(11b)

where X1n1 nd Y1n1 are the previous values of X1 and Y1 and α is a weighting coefficient that determines the cut-off frequency fc—or equivalently the time constant τ—of the exponential filter. α is related to fc and the digitisation rate fd by the equation: α=cosγ1+cos2γ4cosγ+3, where γ=2πfc/fd (Lyons, 2011). X1 and Y1 are arbitrarily set to zero prior to the first sample.

The exponential filtering stage is repeated using the same α value to provide better attenuation of non-DC interferences and hence obtain a ‘cleaner’ solution (at the expense of a slower settling time):

X2n=X2n1+αX1nX2n1(12a)

and

Y2n=Y2n1+αY1nY2n1(12b)

Finally, we determine the amplitude R2n and the phase ϕ2n via the equations:

R2n=X2nX2n+Y2nY2n(13)

and

ϕ2n=atanY2nX2n(14)

Note, the above procedure may be repeated using higher harmonics of the reference signals to obtain the amplitude and phase of higher harmonics of the incoming signal. Since all calculations are done entirely in the digital domain using the same input signal S, analysis of higher harmonics may be carried out alongside the analysis of the first-harmonic signal.

5.4 Synchronous filtering

From Eqs 4a, 4b, it is evident that the outputs of the two multipliers contain significant components at the sum frequency 2ωs that must be suppressed by filtering to obtain a reliable measurement of the DC component. To suppress the 2ωs contributions by an overall factor of 1000, say, each stage of exponential filtering must reduce the 2ωs contribution by a factor of 1000=101.5. To achieve this level of attenuation, the cut-off frequency ω* of the filter must be approximately 101.5 times smaller than 2ωs, i.e., ω* must be less than 2ωs/101.5. Equivalently the filter time constant τ=1/ω* must be greater than 101.5/2ωs=101.5/4πfs. It follows that, to reliably measure a low frequency signal of frequency fs = 1 Hz, say, would require a time constant of approximately 2.5 s. Allowing for a settling time of approximately 10τ, this would correspond to a long measurement time of around 25 s, which may be too long for the intended application.

As an alternative to exponential low-pass filtering, the outputs X0 and Y0 of the multipliers may be averaged over exactly one time period of the reference signal S (a process called “synchronous filtering” since the filtering/averaging process is synchronised to the incoming signal). The averaging procedure eliminates all contributions at harmonics of the signal frequency (including 2ωs) since the average of a sinusoidal wave over an integer number of periods is zero. Hence, synchronous filtering allows the desired DC terms in Eqs 4a, 4b to be evaluated without interference from the 2ωs component. The synchronously filtered signal is updated once per time period, i.e., once per second for fs = 1 Hz, and so provides substantially improved time resolution compared to exponential filtering. However, in contrast to low-pass filtering, synchronous filtering only eliminates components at the harmonic frequencies, and cannot fully suppress unwanted signals at other frequencies. Hence, synchronous filtering should only be used for clean, low frequency signals where non-synchronous (exponential) filtering would be unnecessary and unacceptably slow. In practice, synchronous filtering is typically beneficial only for signal frequencies substantially below 100 Hz.

5.5 Noise estimation

A live estimation of the noise level is obtained by determining the exponentially weighted standard deviation S2n of the lock-in output R2. The exponentially weighted mean R2¯n is first determined from Eq. 15:

R2¯n=R2¯n1+αR2nR2¯n1(15)

where n is the sample number, R2n is the corresponding lock-in output, R2¯n1 is the previous value of the exponentially weighted mean, and α is the same constant used in Eqs 11, 12. S2n is then determined using Eq. 16:

S22n=1αS2n1+αR2nR2¯n12(16)

where S2n1 is the previous value of the exponentially weighted standard deviation (Finch, 2009).

6 Graphical user interface (GUI)

The lock-in calculations described above are carried out internally on the FPU of the Teensy 4.0 microcontroller. The microcontroller sends out new values for X2n, Y2n, R2n and ϕ2n, as well as an estimate of the noise level S2n over its universal serial bus (USB) interface every 0.1 s for remote analysis on a personal computer or other hardware. A simple Python-based application is provided for setting the measurement parameters and reading, plotting and saving data (see Figure 3); alternatively, it is possible to communicate with OLIA directly using the programming interface described in Supplementary Appendix S1.

FIGURE 3
www.frontiersin.org

FIGURE 3. Screenshot of Python-based graphical user interface used for controlling OLIA and visualising and saving data. The application window includes controls for connecting to OLIA’s serial interface (top), and a text window (top right) for displaying messages relating to the measurement status, e.g., out-of-range signals and connection status. Controls for setting measurement parameters such as the modulation frequency, input gain, time constant, and the lowest requested higher harmonic are also present. Two checkboxes are provided for switching between internal or external referencing and low-pass or synchronous filtering. A file-name may be specified for live data logging. The numerical values of R2,ϕ2,X2,Y2 and the noise estimate S2 are updated every 0.1 s, and the values of R2 and ϕ2 or X2 and Y2 are plotted in real-time over a specified time range.

The Python application allows the user to select between internal and external referencing. In internal referencing mode, it is possible to modify the modulation frequency from 1 Hz to 50 kHz, the analogue input gain from zero to 64, and the time constant from 0.01 to 10 s. To obtain the optimum signal-to-noise ratio (SNR), the input gain should be set as high as possible without saturating the ADC. If the input to the ADC is too high, an overload message is displayed in the text box located at the top-right corner of the GUI interface. (Note, low input gain is equivalent to high dynamic reserve so, if the signal is masked by a high level of noise, it may be necessary to use a low input gain to avoid noise-induced saturation of the ADC). For a reliable measurement, it is advisable to wait approximately ten time-constants after any change (e.g., after switching on a sensor, loading a new sample in an experimental set-up, or changing a measurement parameter) to provide sufficient time for the lock-in output to stabilise. Hence, for a typical time constant of 0.6 s, a wait time of at least 6 s is recommended. For modulation frequencies below 100 Hz that would require high exponential filter time constants and long associated wait times, it is possible to select synchronous filtering and obtain a new output every time period (at the expense of increased measurement noise).

In internal referencing mode, the digitisation rate fd is set to a fixed value of 200 kHz by default, and this value is appropriate for most applications. If required, the digitisation rate may be changed to a lower value in the source code of the firmware, but the cut-off frequency of the antialiasing filter should then be adjusted accordingly (to <fd/2) by modifying resistors R5 and R6 along with capacitors C1 and C2 in Supplementary Figure S4. (The necessary changes to the firmware are clearly commented in the source-code provided). At the default 200-kHz digitisation rate, there is sufficient computational headroom in the Teensy 4.0 microcontroller to analyse three harmonics (in addition to the fundamental frequency) within each 5-μ s time step. By default, OLIA outputs the X2 and Y2 values of harmonics 2 to 4 (in addition to the X2n, Y2n, R2n and ϕ2n values of the fundamental). Higher consecutive harmonics may be outputted by specifying the value of the lowest required higher harmonic in the labelled box of the GUI. For instance, if the lowest higher harmonic is set to three, OLIA will output the third, fourth and fifth harmonics (alongside the data for the fundamental frequency). Decreasing the digitisation rate to 100 kHz, say, would double the time-step duration and hence allow seven higher harmonics to be calculated at each time step.

A real-time plot of lock-in output at the fundamental frequency is displayed on the GUI front panel, with the option to select between (X2, Y2) or (R2, ϕ2) representation as preferred. The data may be saved to a file by selecting the ‘Record’ checkbox. An analogue output voltage proportional to the magnitude R of the measured signal is available from one digital output pin of the microcontroller, although we caution that (since the Teensy 4.0 has no DAC) the output voltage is generated using filtered pulse width modulation (PWM), and hence is only suitable for monitoring changes in signal amplitudes that occur at a rate slower than 1 Hz. (The 1 Hz limit is imposed by the 1.6-Hz cut-off frequency of the low-pass filter used to smooth the PWM signal; if it is necessary to measure more rapidly varying signals then the cut-off frequency of the filter may be increased by decreasing the values of resistor R9 or capacitor C6 from their default values of 10 kΩ and 10 µF). A scaling factor can be set on the GUI front panel to bring output signals that are too weak or too high into the 0–3.3 V operating range of the PWM output.

The external referencing mode is selected by ticking the appropriate checkbox on the GUI front panel, and offers equivalent functionality to the internal referencing mode. The button “Query freq.” should be pressed immediately after switching to external referencing mode to determine the frequency of the external reference signal and hence allow OLIA to determine the appropriate digitisation rate. The potentiometer P1 must then be manually adjusted (by rotating the tuning knob on the PCB) until the PLL circuit achieves phase locking; an error message “lock failure” is displayed on the front panel until P1 has been set to a suitable value. “Query freq.” should also be pressed whenever the frequency of the reference signal changes appreciably, so that the digitisation rate is kept at an appropriate value.

7 Selected results

In this section, we present illustrative results obtained using OLIA. For convenience, we refer to the doubly filtered lock-in outputs X2,Y2,R2,ϕ2 and S2 as X,Y,R,ϕ and S. Unless stated otherwise, all measurements were obtained using OLIA’s internal referencing mode and reported values are the direct, uncalibrated results obtained from OLIA. The amplitudes of the input signals used in Figures 4, 68 were controlled using resistive voltage dividers, and the quoted values are accurate to within ± 3%. (We use the symbol “∼” to reflect their approximate nature). The amplitudes of the input signals in Figure 5 were controlled using a high precision waveform generator, and are accurate to within ± 0.1%.

FIGURE 4
www.frontiersin.org

FIGURE 4. (A) Measured amplitude R versus signal frequency fs for ∼250 mV sinusoidal input signals in the range 970–1030 Hz; data were obtained using a fixed reference frequency fr of 1 kHz and time constants τ of 0.06, 0.6 and 6 s. (B) Measured amplitude versus time following a step change in the input signal amplitude S0 from 0 to ∼380 mV at t = 0 s; data were obtained using fixed signal and reference frequencies (fs and fr) of 1 kHz and time constants τ of 0.06, 0.6 and 6 s.

FIGURE 5
www.frontiersin.org

FIGURE 5. Measured amplitude R vs. input signal amplitude S0 for 1 kHz sinusoidal input signals, using a fixed reference frequency of 1 kHz. The blue circles, orange dots and green crosses indicate data obtained using time constants of 0.6, 3 and 6 s and nominal PGA input gains of 1, 16 and 64 respectively. The dashed horizontal line at 0.81 µV represents the noise floor, using a 6-s time constant and a gain of 64.

The most common use of a lock-in amplifier is to measure a target signal of known fixed frequency in the presence of interfering signals at other frequencies. Figure 4A shows—for a fixed internal reference frequency fr of 1000 Hz and time-constant settings of 0.06, 0.6 and 6 s—how the measured output signal R changes when the frequency fs of an applied (noise-free) sinusoidal input voltage of fixed amplitude ∼250 mV is swept from just below fr (970 Hz) to just above fr (1030 Hz). In each case the frequency response is peaked around fr (as expected), falling symmetrically towards zero on either side of fr. The measured R-values at fs=fr= 1000 Hz were 246.00 ± 0.06 mV, 245.97 ± 0.02 mV and 245.86 ± 0.002 mV for time constants τ of 0.06, 0.6 and 6 s, respectively, showing that (in the absence of noise) the measured signal amplitude is largely unaffected by the time constant. The width of the response function, by contrast, is strongly affected by the time constant, becoming progressively narrower as τ is increased. For the three selected values of τ the half-width Δf1% at one percent of the maximum value decreases from 22 Hz to 3.1 Hz to 0.15 Hz as τ is increased from 0.06 to 0.6 to 6 s. In other words, for τ = 0.06 s, OLIA is (broadly) insensitive to signals outside the range 1000 ± 22 Hz; for τ = 0.6 s, it is insensitive to signals outside the range 1000 ± 3.1 Hz; and for τ = 6 s, it is insensitive to signals outside the range 1000 ± 0.15 Hz.

The drawback of using higher τ values is an increase in the time taken for the lock-in output to stabilise, and hence a longer measurement time. Figure 4B shows for an incoming sine wave of frequency fs= 1000 Hz the time-evolution of the R-value following a step change (at t = 0 s) in the signal amplitude from 0 V to ∼380 mV, using time constants τ of 0.06, 0.6 and 6 s. In each case, a duration of approximately ten time-constants is required for the lock-in output to stabilise. With two-stage, first-order filtering of the kind used in OLIA, the expected time response is given by

Rt=R1et/τ*1+t/τ*(17)

where R is the steady-state value of the output signal and the parameter τ* equals the time constant of the filters (see Supplementary Appendix S6). Fitting the curves in Figure 4B to Eq. 17 we obtain τ* values of 0.0593 ± 0.0001 s, 0.5940 ± 0.0001 s and 5.9404 ± 0.0001 s in close agreement with the selected filter time constants of 0.06, 0.6 and 6 s.

Figure 5 shows—for a sinusoidal input of frequency 1 kHz—the effect on the measured amplitude R of varying the amplitude S0 of the input signal from 2.4 µV to 1.25 V. The input signals were generated using a precision signal generator (SDG 2042X, Siglent), with the lowest-amplitude signals obtained using a buffered and calibrated potential divider. The blue circles, orange dots and green crosses show data obtained using time constants of 0.6, 3 and 6 s and PGA input gains of 1, 16 and 64, in external referencing mode. The horizontal line at 0.81 µV shows the measured amplitude with a 6-s time constant, a gain of 64 and an input amplitude of zero, and indicates the approximate noise floor. The data show good linearity down to 7 μV, with a dynamic range of around 106. Hence, OLIA provides an effective solution to the challenge of carrying out sensitive µV-resolution detection on low-end electronics.

Figure 6A shows—for a sinusoidal input of magnitude ∼240 mV and frequency 1 kHz—the effect on the measured phase of varying the relative phase ϕ=ϕsϕr of the input signal from 0° to 90°. The measured phase is proportional to the set phase, with a constant offset of −1.8680°, attributable to a phase-lag introduced by the input-stage electronics. The phase offset can be calibrated out by measuring the apparent phase ϕ* of a “fast” signal that is known to be in phase with the reference signal and subtracting this value ϕ* from all measured phases. (ϕ* is most simply obtained by connecting OLIA’s square wave reference voltage to the input). Figure 6B shows the measured magnitude R of the signal versus phase for the same input signals. The values are distributed about a mean value of 237.82 mV with a standard deviation of 0.04 mV, indicating (as expected) that the measured amplitude is independent of phase.

FIGURE 6
www.frontiersin.org

FIGURE 6. (A) Measured phase ϕ versus the relative phase ϕsϕr between the input and reference signal. The straight line shows a linear least-squares fit with unity gradient and −1.8680° vertical offset. (B) Measured amplitude R versus the relative phase ϕsϕr.

Figure 7A shows—for a filter time constant of 6 s and sinusoidal input signals of amplitude ∼1 mV and frequency 1 kHz—the influence of varying levels of white noise on the measured R signal. Input signals of varying SNR were obtained by using a unity-gain, op-amp-based summing amplifier to combine a (noise-free) sinusoidal signal of fixed amplitude ∼1 mV with white-noise “signals” of different root-mean-squared (RMS) amplitudes in the range 0.01–1000 mV. (The two input signals were digitally synthesised on separate Teensy 3.6 microcontrollers, using the built-in 12-bit digital-to-analogue converter at a digitisation rate of 100 kHz. The pseudo-random white-noise was generated digitally, using a Galois linear feedback shift register algorithm. The noise signal was individually buffered with its own op-amp before passing to the summing amplifier. SNR values denote the ratio of the RMS signal amplitude to the RMS noise amplitude, where the two RMS values were separately determined using a digital oscilloscope.). Percentage errors in R of less than 0.5% were obtained for signal-to-noise ratios of ten and above, with the signal deviating from the correct value of 0.945 mV by less than 15% at signal-to-noise ratios down to 10−2.

FIGURE 7
www.frontiersin.org

FIGURE 7. (A) Measured amplitude R vs. signal to noise ratio γ for ∼1 mV sinusoidal input signals of frequency 1 kHz with varying (white) noise-levels; data were obtained using a 1 kHz reference frequency, a time constant of 6 s, and an input gain of 1. The “correct” (noise-free) value of the signal amplitude is represented by the horizontal line. (B) Measured amplitude R vs. harmonic number k for the first 22 harmonics of a ∼250 mV square-wave of frequency 1000 Hz; data were obtained using reference frequencies matched to the frequency of the corresponding harmonic, a fixed time constant of 0.6 s, and an input gain of 1. The curve indicates a least-squares fit of the odd harmonics k=1,3,21 to an equation of the form Rk=R1/k.

A common application of a lock-in amplifier is to carry out a Fourier decomposition of an incoming signal by carrying out lock-in detection at harmonics of the fundamental signal frequency. Figure 7B shows the measured amplitude R versus harmonic number n for an incoming square-wave voltage of amplitude ∼250 mV and frequency 100 Hz. As expected for a square wave, the amplitudes of the even harmonics are approximately zero (1.0 ± 0.6 mV), while the amplitudes of the odd harmonics lie on a curve of the form Rkn=R1/k where R1= 267 mV.

Figure 8 shows the normalised signal amplitude versus signal frequency fs for noise-free sinusoidal input signals of fixed amplitude ∼250 mV and phase zero, determined using internal referencing (solid line) and external referencing (dotted line). Using an internal reference, OLIA performed reliably up to frequencies of ∼25 kHz, giving consistent amplitude values to within ±0.1%. There was a progressive fall in the measured amplitude at higher frequencies (with the output dropping by 12% at 50 kHz) due to frequency roll-off of the anti-aliasing filter, but it is possible to correct for this drop in sensitivity using a calibration file. Hence, in internal referencing mode, OLIA is usable at frequencies of up to at least 50 kHz.

FIGURE 8
www.frontiersin.org

FIGURE 8. Normalised measured amplitude vs. modulation frequency for input signals of fixed amplitude ∼200 mV and zero phase; data were obtained using a time constant of 0.6 s, an input gain of 1, and reference frequencies matched to the frequency of the incoming signal. The measured amplitude has been normalised to the value recorded at 1 kHz. The solid and dotted lines denote data acquired using internal and external referencing, respectively.

Using an external square-wave reference derived from an external waveform generator, reliable measurements were obtained over a narrower frequency range from 130 Hz to 6 kHz, with the frequency multiplier circuit exhibiting unreliable locking outside of this range. Within the working range, the results obtained by external referencing closely matched those obtained by internal referencing. If required the working range of the PLL could be modified by changing the value of capacitor C1 in the PLL, with higher capacitances pushing the working range to lower frequencies and vice versa.

Figure 9 shows optical measurements obtained using OLIA and its companion optical breakout board, which houses an OPT101 amplified photodiode and a DC servo circuit to zero-out DC offsets caused by ambient light or non-ideality of the photodiode’s built-in amplifier (see Supplementary Figure S5). To carry out the measurements, a 635-nm LED driven at 1 kHz by OLIA’s square wave reference voltage was focused directly onto the OPT101 photodiode, while a beam-splitter directed a fixed fraction of the light onto a (non-amplified) silicon photodiode connected to an electrometer (6517A, Keithley) operating as a sensitive current meter. The electrometer’s integration time was set to the longest possible value of 200 ms (equal to 200 periods of the modulating signal), and the entire optical setup was sealed in a light-proof enclosure, so that the average current recorded by the electrometer was directly proportional to the average photon flux falling on the OPT101 photodetector. Plotting the amplitude recorded by OLIA versus the average photon flux falling on the OPT101 photodetector (in arbitrary units) revealed a linear response, spanning more than five orders of magnitude. The measured amplitude at the lower end of the linearity range was 0.016 mV, which for an amplified photodiode sensitivity of approximately 0.43 V/μW, implies a detection limit of around 40 pW (0.016 mV ÷ 0.43 V/μW). Hence, in combination with its breakout box, OLIA permits sensitive measurements of photon flux with good linearity and high dynamic range.

FIGURE 9
www.frontiersin.org

FIGURE 9. (A) Optical setup used to test the performance of OLIA and its optical breakout board. Modulated light from an LED is attenuated using a series of neutral density filters (ND) before striking a glass microscope slide that serves as a beam-splitter. The transmitted light strikes the amplified silicon photodiode on the optical breakout board, and the output signal from the breakout board is connected to the input terminals of OLIA. The reflected light strikes a separate photodiode, and the resulting photocurrent is measured using an electrometer. The photocurrent measured by the electrometer is proportional to the intensity of light incident on OLIA’s photodiode. (B) Plot of amplitude R recorded by OLIA vs. intensity of light incident on OLIA’s sensor (in arbitrary units). The upper x-axis shows the photocurrent measured by the electrometer.

8 Potential modifications

There are many ways in which OLIA could be further improved, without substantially increasing the cost or complexity of design, and we mention the most obvious enhancements here. Firstly, digitisation of the input signal is currently carried out using the built-in ADC on the Teensy 4.0 microcontroller, which has a low effective bit-depth of 12 and high input noise; switching to a high performance 16- or 18-bit bipolar ADC would improve dynamic range and lower measurement noise (while also removing the need for the summing amplifier S1), bringing the performance closer to high-end instruments.

The antialiasing filter has a slow second-order roll-off at 94 kHz, providing only weak attenuation of signals above the 100 kHz Nyquist frequency; a better choice would be a separate, specialised low-pass anti-aliasing filter such as the eighth-order LTC1564 (Analog devices), which could be doubly cascaded if necessary. We further note that the antialiasing filter in the current design has a fixed cut-off frequency. Using a dynamically tuneable anti-aliasing filter (such as the LTC1564) would allow run-time adjustment of the digitisation rate, which in turn would allow more harmonics to be simultaneously measured (at lower digitisation rates).

The frequency multiplier used in the external reference mode requires manual tuning (via a mechanical potentiometer) and is restricted to a frequency range of 130 Hz to 5 kHz. Modifications to the design of the frequency multiplier would eliminate the need for manual tuning and widen the operating range.

The Teensy 4.0 microcontroller development board has no internal DAC; switching to a different DAC-equipped microcontroller or adding an external DAC chip would allow for the generation of sinusoidal analogue reference signals and/or a faster analogue output of the X, Y and R signals.

Finally, it would be useful to develop a range of breakout boards offering, e.g., overload protection or tuneable current or voltage pre-amplification. There is also much scope for providing additional functionality at a software level, e.g., by using chirped reference signals to investigate frequency effects (Sonnaillon and Bonetto, 2007).

Most of these changes would be simple to incorporate into the current design, providing better performance and/or enhanced functionality without adding substantially to OLIA’s current US$35 build cost. Hence the current implementation of OLIA, as described here, offers a promising springboard for developing enhanced future versions that can further narrow the performance and functionality gap with (far costlier) high-end commercial systems.

9 Conclusion

In conclusion OLIA is an inexpensive microcontroller-based digital lock-in amplifier that offers much of the functionality associated with high-end instruments. Key features include dual-phase detection at multiple harmonic frequencies up to 50 kHz, internal and external reference modes, adjustable levels of input gain from 1 to 64, a choice between low-pass filtering and synchronous filtering, noise estimation, and a comprehensive programming interface for remote control. With a build cost of just US$35, OLIA’s design prioritises affordability over performance. Nonetheless, it is a capable instrument that permits the measurement of signals over six orders of magnitude, with excellent linearity and good noise rejection. OLIA also comes with an optional optical breakout board that integrates an amplified silicon photodiode with a DC servo circuit, permitting sensitive measurements down to the 40-pW level even in the presence of strong ambient illumination. We are hopeful OLIA will find uses in a wide variety of cost-sensitive applications that require noise-tolerant signal recovery over a wide dynamic range. Finally we note that, although OLIA is intended to be a research-grade instrument, its low cost and fully open design should also make it an attractive option for laboratory-based teaching.

Data availability statement

The datasets presented in this study can be found in online repositories. The names of the repository/repositories and accession number(s) can be found below: Zenodo, at DOI: https://doi.org/10.5281/zenodo.7334355.

Author contributions

AH designed and built hardware, wrote software and performed experiments. Both AH and JdM contributed to conceptualisation, algorithm design, data analysis and preparing the manuscript.

Funding

This work was supported through a grant from the Research Council of Norway (Grant No. 262152) and the NTNU Nano Impact Fund.

Conflict of interest

The authors declare that the research was conducted in the absence of any commercial or financial relationships that could be construed as a potential conflict of interest.

Publisher’s note

All claims expressed in this article are solely those of the authors and do not necessarily represent those of their affiliated organizations, or those of the publisher, the editors and the reviewers. Any product that may be evaluated in this article, or claim that may be made by its manufacturer, is not guaranteed or endorsed by the publisher.

Supplementary material

The Supplementary Material for this article can be found online at: https://www.frontiersin.org/articles/10.3389/fsens.2023.1102176/full#supplementary-material

References

Barragán, L. A., Artigas, J. I., Alonso, R., and Villuendas, F. (2001). A modular, low-cost, digital signal processor-based lock-in card for measuring optical attenuation. Rev. Sci. Instrum. 72, 247–251. doi:10.1063/1.1333046

CrossRef Full Text | Google Scholar

Bengtsson, L. E. (2012). A microcontroller-based lock-in amplifier for sub-milliohm resistance measurements. Rev. Sci. Instrum. 83, 075103. doi:10.1063/1.4731683

PubMed Abstract | CrossRef Full Text | Google Scholar

Finch, T. (2009). Incremental calculation of weighted mean and variance. Cambridge, United Kingdom: University of Cambridge

Google Scholar

Harvie, A. J., Yadav, S. K., and de Mello, J. C. (2021). A sensitive and compact optical detector based on digital lock-in amplification. HardwareX 10, e00228. doi:10.1016/j.ohx.2021.e00228

PubMed Abstract | CrossRef Full Text | Google Scholar

Hofmann, M., Bierl, R., and Rueck, T. (2012). “Implementation of a dual-phase lock-in amplifier on a TMS320C5515 digital signal processor,” in 2012 5th European DSP Education and Research Conference (EDERC) (IEEE), 20–24. doi:10.1109/EDERC.2012.6532217

CrossRef Full Text | Google Scholar

Kim, C.-W. (2014). A microcontroller-based lock-in amplifier for capacitive sensors. J. Sens. Sci. Technol. 23, 24–28. doi:10.5369/JSST.2014.23.1.24

CrossRef Full Text | Google Scholar

Kishore, K., and Akbar, S. A. (2020). Evolution of lock-in amplifier as portable sensor interface platform: A review. IEEE Sens. J. 20, 10345–10354. doi:10.1109/JSEN.2020.2993309

CrossRef Full Text | Google Scholar

Lyons, R. G. (2011). Understanding digital signal processing. 3rd ed. Prentice Hall Publishing.

Google Scholar

Meade, M. L. (1982). Advances in lock-in amplifiers. J. Phys. E 15, 395–403. doi:10.1088/0022-3735/15/4/001

CrossRef Full Text | Google Scholar

Pollastrone, F., Piccinini, M., Pizzoferrato, R., Palucci, A., and Montereali, R. M. (2023). Fully-digital low-frequency lock-in amplifier for photoluminescence measurements. Analog. Integr. Circuits Signal Process. doi:10.1007/s10470-022-02125-9

CrossRef Full Text | Google Scholar

Probst, P. A., and Collet, B. (1985). Low-frequency digital lock-in amplifier. Rev. Sci. Instrum. 56, 466–470. doi:10.1063/1.1138324

CrossRef Full Text | Google Scholar

Sonnaillon, M. O., and Bonetto, F. J. (2007). Lock-in amplifier error prediction and correction in frequency sweep measurements. Rev. Sci. Instrum. 78, 014701. doi:10.1063/1.2428269

PubMed Abstract | CrossRef Full Text | Google Scholar

Stimpson, G. A., Skilbeck, M. S., Patel, R. L., Green, B. L., and Morley, G. W. (2019). An open-source high-frequency lock-in amplifier. Rev. Sci. Instrum. 90, 094701. doi:10.1063/1.5083797

PubMed Abstract | CrossRef Full Text | Google Scholar

Wang, J., Wang, Z., Ji, X., Liu, J., and Liu, G. (2017). A simplified digital lock-in amplifier for the scanning grating spectrometer. Rev. Sci. Instrum. 88, 023101. doi:10.1063/1.4974755

PubMed Abstract | CrossRef Full Text | Google Scholar

Wang, Z., Shi, X., Wang, W., and Cai, W. (2023). High-performance digital lock-in amplifier module based on an open-source red pitaya platform: Implementation and applications. IEEE Trans. Instrum. Meas. 72, 1–14. doi:10.1109/TIM.2022.3221746

CrossRef Full Text | Google Scholar

Keywords: open hardware, lock-in amplification, signal detection, optical sensing, digital signal processing (DSP), electronics

Citation: Harvie AJ and de Mello JC (2023) OLIA: An open-source digital lock-in amplifier. Front. Sens. 4:1102176. doi: 10.3389/fsens.2023.1102176

Received: 18 November 2022; Accepted: 16 March 2023;
Published: 30 March 2023.

Edited by:

Massood Atashbar, Western Michigan University, United States

Reviewed by:

Damon Miller, Western Michigan University, United States
Yang Deng, University of Pennsylvania, United States

Copyright © 2023 Harvie and de Mello. This is an open-access article distributed under the terms of the Creative Commons Attribution License (CC BY). The use, distribution or reproduction in other forums is permitted, provided the original author(s) and the copyright owner(s) are credited and that the original publication in this journal is cited, in accordance with accepted academic practice. No use, distribution or reproduction is permitted which does not comply with these terms.

*Correspondence: Andrew J. Harvie, a.j.harvie@leeds.ac.uk; John C. de Mello, john.demello@ntnu.no

Disclaimer: All claims expressed in this article are solely those of the authors and do not necessarily represent those of their affiliated organizations, or those of the publisher, the editors and the reviewers. Any product that may be evaluated in this article or claim that may be made by its manufacturer is not guaranteed or endorsed by the publisher.