In the article on mixing I obtained a DC component by multiplying two sine waves at the same frequency. But the multiplier also produces other components. If the signal I want to measure is one hundred times smaller than an interfering tone close in frequency, can I still obtain its amplitude? And how much does the result change if I observe the product for a different length of time?

For now I consider deterministic signals, with no random noise, saturation or offset. I want to separate what depends on the multiplier from what depends on the duration of the observation and on the output filter.

1. From the product to an amplitude measurement

Suppose I have an input x(t)=A sin(2πf0t+φ) and a reference r(t)=B sin(2πf0t). In an analog circuit with both inputs in volts, I call K the multiplier coefficient, expressed in V−1. The output z(t)=Kx(t)r(t) is then a voltage:

\[ z(t) = \frac{KAB}{2}\left[\cos\varphi – \cos(4\pi f_0 t+\varphi)\right]. \]

The in-phase reading is A cos φ

An ideal low-pass filter that keeps DC and rejects the double-frequency term would give X=KAB cos φ/2. I can define a normalized reading AX=2X/(KB)=A cos φ: it is the peak amplitude of the in-phase projection, not necessarily the amplitude A of the signal. When φ=0, AX=A; at 90° the reading is zero even though the input is not.

In the first mathematical tests I use a numerical reference of unit, dimensionless amplitude, r(t)=sin(2πf0t). In this case z=xr is expressed in the same unit as the input and the normalized reading is twice the mean of the product. The factor K of the analog circuit remains distinct from this convention.

2. Why the duration matters

An ideal filter cannot be realized with a finite number of samples. I can, however, build a first measurement by averaging the product over N samples, with step Δt=1/fs and nominal duration T=N/fs:

\[ X_N = \frac{1}{N}\sum_{n=0}^{N-1} z[n], \qquad A_{X,N} = 2X_N. \]

To understand what is removed, I consider a cosine term of frequency f. In continuous time the mean between 0 and T is

\[ \frac{1}{T}\int_0^T \cos(2\pi f t+\theta)\,dt = \operatorname{sinc}(fT)\cos(\pi f T+\theta), \qquad \operatorname{sinc}(u)=\frac{\sin(\pi u)}{\pi u}. \]

For f=0 the limit is cos θ. If fT is a non-zero integer, the mean is zero; otherwise a contribution may remain that depends on frequency, duration and phase. For a discrete sum the exact response is different. Summing the geometric progression of the phasors gives, when sin(πf/fs) is not zero:

\[ \frac{1}{N}\sum_{n=0}^{N-1}\cos\left(\frac{2\pi f n}{f_s}+\theta\right) = \frac{\sin(\pi N f/f_s)}{N\sin(\pi f/f_s)}\cos\left(\theta+\frac{\pi(N-1)f}{f_s}\right). \]

At the singular points I use the limit of the original sum. For frequencies well below fs the ratio is close to the continuous sinc, but for an exact numerical comparison I will use the discrete formula. The rectangular mean has response zeros at frequencies coherent with the record; it does not automatically reject every frequency other than that of the reference.

3. I add a much larger interfering tone

I choose a useful input with a peak amplitude of 10 mV and a frequency of 200 Hz, on which I superimpose an interfering tone with an amplitude of 1 V at 180 Hz. Both initial phases are zero, the unit reference is at 200 Hz. These are parameters chosen for the mathematical test, not bench measurements.

\[ x(t) = 0.010\,\sin(2\pi\cdot 200\,t) + 1\,\sin(2\pi\cdot 180\,t)\quad[\mathrm{V}]. \]

When multiplied by the reference, the useful signal gives the DC component and the 400 Hz term. The interfering tone instead produces terms at 20 and 380 Hz. Theoretically I expect a DC component of 5 mV. It is not enough, however, to read the mean value of any record: a residue of the interfering tone may be larger than the DC component I am looking for.

Planned testSamplesNominal durationReason for the choice
Coherent record200100 ms20, 380 and 400 Hz complete an integer number of periods.
Record not coherent for the interfering tone13065 msThe useful tone completes 13 periods, but the 20 Hz term only 1.3.

In both cases fs=2000 Hz. I generate a single record and compare the first 130 samples with all 200, keeping the signal identical.

Try it yourself with GX-TXT

I carried out the experiments that follow with GX-TXT, free software you can install on Linux. There is no need to take my numbers on trust: follow the steps, rebuild the signal, the interfering tone and the reference, and compare your readings with mine. Then change something — the length of the record, the frequency or amplitude of the interfering tone, the time constant of the filter — and see how the reading moves. It is the best way to really understand what a lock-in measures, and to have some fun too.

4. I build the signal and the reference in the Worksheet

I use a new session in GX-TXT v0.9.8.10-dev-112-p012, in the working copy aligned with the micropatches applicable up to MP047. I open Viewers (1), search for Worksheet in Search (2) and choose Worksheet (3). I save the empty sheet.

In the Functions panel (4) I search for and select numeric.uniform_grid (5).

I set start=0 (6), stop=0.0995 (7), spacing=200 (8), Options=mode="count" (9). I set Output cell=A1 (11), press Preview fields (12), wait for the fields to be captured, choose x in Result field (10) and press Apply result (13). Column A contains the time grid in seconds, from 0 to 99.5 ms. The record nominally represents 100 ms; the sample at 100 ms belongs to the next record.

I search for and select signal.generate.sine (14), time=A1:A200 (15), frequency=200 (16), modulation=empty() (17), Options=amplitude=1 phase_rad=0 (18). I set Output cell=B1 (20), press Preview fields and wait for completion, select value_real (19) and press Apply result. B contains the dimensionless reference.

For the interfering tone I leave the other parameters unchanged, change frequency to 180 (21) and Output cell=C1 (22); I repeat Preview fields and Apply result with value_real. I obtain C, the interfering tone in volts with unit amplitude.

In the Cell & Formula panel I select D1 (23), enter (24) the following formula and press Apply (25):

=numeric.multiply(B1:B200,0.01)

The useful signal is proportional to the reference, with a peak amplitude of 0.010 V and zero phase. The values in column D are small; for example in row 3 I read about 0.00951 V, not exactly 0.01 V because the sample does not coincide with the maximum of the sine wave.

In E1 (26) I enter (27) and apply (28) the sum:

=numeric.add(C1:C200,D1:D200)

In F1 (29) I enter (30) and apply (31) the product:

=numeric.multiply(E1:E200,B1:B200)

I look at the first values of F: row 4 contains about 0.953 V. The useful DC component is only 5 mV according to the model, so it cannot be read directly from a single sample of the product.

5. I compare the two integration durations

In G1 (32) I enter (33) and apply (34) two means of the same product:

=vector(numeric.mean(F1:F200),numeric.mean(F1:F130))

In H1 (35) I enter (36) and apply (37) the scale factor:

=numeric.multiply(G1:G2,2)
SamplesDurationMean of the product (mV)Normalized reading (mV)
200100 ms5.000010.0000
13065 ms65.8895131.7790

The values are rounded from G and H. With 100 ms I obtain the amplitude I am looking for despite the presence of an interfering tone one hundred times stronger. With 65 ms the reading is more than thirteen times the actual one: the problem is not that the reference has changed, but that I have not averaged over an integer number of periods of the 20 and 380 Hz terms. The useful term at 400 Hz, instead, completes 26 periods even in the 65 ms record.

5.1. Check with the two signals separately

I can check the origin of the error by performing the same detection on the interfering tone alone. In I1 (38) I enter (39) and apply (40):

=vector(2*numeric.mean(numeric.multiply(C1:C200,B1:B200)),2*numeric.mean(numeric.multiply(C1:C130,B1:B130)))

The reading at 65 ms is 0.12177902 V: it is a false signal due to the interfering tone even when the 200 Hz signal is not present.

In J1 (41) I repeat (42–43) on the useful signal alone:

=vector(2*numeric.mean(numeric.multiply(D1:D200,B1:B200)),2*numeric.mean(numeric.multiply(D1:D130,B1:B130)))

A false signal from the interfering tone

For the useful signal alone I read 10 mV in both windows. With the composite signal, in the short window, the contribution of about 121.779 mV from the interfering tone adds to the useful 10 mV. The mean is linear with respect to the product with a fixed reference. Selectivity does not depend only on the multiplication, but also on the frequency response of the operation I perform after the product.

These are deterministic numerical checks, not bench measurements. I have not yet applied a real low-pass filter.

5.2. I compare the readings

In K1 (44) I enter (45) =vector(100,65) and press Apply (46): the two durations are in milliseconds.

Procedure in GX-TXT: configuring and publishing the chart (Figures 14–15)

I select H1:K2 (48) and open Chart (47); I press Add selection (49). In the chart I keep I set X column=K (50), Y columns=H I J (51), First row=1 (52), Last row=2 (53). I choose Kind=scatter (54), Panels=overlay (55), Marker=circle (56). I set X minimum=55, X maximum=110 (57–58), Y minimum=−0.01 and Y maximum=0.15 (59–60). I apply (61), wait for the regeneration, then press Publish immutable Graph to Plots (62).

At 65 ms the blue point is at about 0.132 V, the red one at 0.122 V, the green one at 0.010 V. At 100 ms the blue and green coincide, while the red falls on zero. I do not join the points: I calculated two durations, not a continuous response curve. The original CSV (x=K, y1=H, y2=I, y3=J) reports the results with the precision of the Dataset; for the interfering tone alone at 100 ms there remains 8.704 × 10−16 V, a numerical residue and not an indication of rejection achievable in the laboratory.

Procedure in GX-TXT: axis labels and rerendering (Figure 17)

I complete the presentation of the graph in Plots: I select p0001 (63), open Presentation (64), Title and labels… (65), write Observation window (ms) in the X / bottom label field (66) and Normalized reading (V) in the Y Left label field (67). I save (68) and, from Render (69), choose Rerender selected (70).

6. Progressive integration

So far I have compared two durations of the mean. Now I want to understand what happens between these two points: does the lock-in reading always improve as the observation time increases? I keep the same 200-sample record and the same signals. I do not generate new realizations.

For each number of samples N, with Δt = 0.0005 s, I define the cumulative sum SN and the rectangular integral JN:

\[ S_N = \sum_{n=0}^{N-1} z[n], \qquad J_N = \Delta t\, S_N, \qquad T_N = N\Delta t. \]

The integral has units of V·s. The normalized reading in volts is AX,N = 2JN/TN = 2SN/N. The nominal duration includes N sampling intervals; the last sample is at instant (N−1)Δt. I start from N=1, not from zero, to avoid a division by zero. I use a rectangular sum consistent with the discrete mean of the previous section, not the trapezoidal rule.

6.1. From the product to the cumulative reading

I reopen the Workspace of the session and check that columns A–K and the first graph are present. I open Functions (71), select numeric.cumulative_sum (72), set values=F1:F200 (73) and Output cell=L1 (75). I press Preview fields (76), choose values in the Result field (74) and press Apply result (77). Column L contains SN.

I select M1 (78), enter (79) the following formula and press Apply (80). Since column A contains the instants in seconds, I multiply by 2000 Hz and add one. I obtain the number of samples included in each mean, from 1 to 200.

=numeric.add(numeric.multiply(A1:A200,2000),1)

In N1 (81) I enter (82) and apply (83) the following product: N contains the nominal duration expressed in ms.

=numeric.multiply(M1:M200,0.5)

In O1 (84) I enter (85) and apply (86) the multiplication by Δt in seconds. O contains the cumulative integral in V·s.

=numeric.multiply(L1:L200,0.0005)

In P1 (87) I enter (88) and apply (89) the formula for the normalized reading, equivalent to 2JN/TN:

=numeric.divide(numeric.multiply(L1:L200,2),M1:M200)

6.2. The estimate changes with the window duration

Procedure in GX-TXT: chart, publication and labels (Figures 24–26)

I select N1:P5 (91), open Chart (90) and press Add selection (92). For the new graph I set X column=N (93), Y columns=P (94), First row=1 (95), Last row=200 (96), Kind=line (97), Panels=overlay (98), Marker=none (99). I choose limits X=0–105 ms (100–101), Y=−0.3–1.2 V (102–103); I press Apply (104), wait for the regeneration and choose Publish immutable Graph to Plots (105). The limits also include the initial readings very far from 10 mV.

In Plots I select p0002 (106), open Presentation (107), Title and labels… (108), write Observation window (ms) in the X / bottom label field (109) and Normalized reading (V) in the Y Left label field (110). I save (111) and choose Render (112), Rerender selected (113).

The original CSV (x=duration in ms, y1=reading in V) contains all 200 results. Some values are:

SamplesDuration (ms)Normalized reading (mV)
10.50
21318.406
421070.297
1005010.000
13065131.779
20010010.000

The reading at 0.5 ms is zero because the first sample of the product is zero; this does not mean that the useful signal is absent. As the duration increases, the estimate initially even exceeds 1 V, then becomes negative and goes back to oscillating around a much smaller value. At 50 and 100 ms the components of the product at 20, 380 and 400 Hz complete an integer number of periods, so they contribute with zero mean. The reading returns to 10 mV; at 65 ms I find exactly the result of the previous step, within the numerical precision of the calculation.

This test shows that the rejection of the interfering tone does not increase monotonically with T. Under ideal conditions, the oscillating contribution tends to decrease as the duration grows, but the exact cancellations observed here depend on the frequencies being coherent with the record. The curve is not a step response: each point represents a mean with a fixed time origin and a different duration. It is not yet the output of a low-pass filter with a fixed time constant; I will study that case separately.

7. I replace the mean with a low-pass filter

The progressive mean of the previous section uses all the samples from the origin and gives each the same weight. Its interval grows as I acquire data. An analog output filter, instead, can work continuously with a fixed time constant. How does the reading change if I use the simplest RC low-pass instead of the mean?

I consider an ideal first-order RC, with unit static gain and time constant τ=RC. I call u(t)=2z(t) the normalized product and w(t) the output of the filter, both in volts. The model is:

\[ \tau\frac{dw}{dt} + w = u(t), \qquad H(s) = \frac{1}{1+s\tau}. \]

For a sinusoidal component of frequency f, the magnitude of the analog transfer function is:

\[ |H(j2\pi f)| = \frac{1}{\sqrt{1+(2\pi f\tau)^2}}, \qquad f_c = \frac{1}{2\pi\tau}. \]

DC passes unchanged in steady state, while the oscillating components are attenuated, not cancelled. I choose τ=10 ms and τ=50 ms: the corresponding analog cut-off frequencies are about 15.9 Hz and 3.18 Hz. With these two time constants I can see the trade-off between rejection of the 20 Hz tone and speed of the filter.

7.1. From the ideal circuit to the discrete model

I am not yet simulating a circuit with real components. I use the causal digital filter equivalent to the RC model when the input is held constant during each sampling interval Δt=0.0005 s. Integrating the differential equation over the interval in which the value u[n] is constant, I obtain:

\[ p = e^{-\Delta t/\tau}, \qquad w[n] = p\,w[n-1] + (1-p)\,u[n], \qquad w[-1]=0. \]

Row N of the Worksheet therefore represents the value at the end of the corresponding interval, T=NΔt, with the input sampled at the beginning of the interval. I use the same nominal abscissa N as for the progressive mean. The transfer function of the discrete filter, referred to this indexing convention, is (1−p)/(1−p z−1), where z is now the variable of the Z-transform, not the time-domain product previously called z(t).

In the Scientific Worksheet the numeric.digital_filter operation accepts the vector to be filtered, the numerator b and the denominator a. For the recurrence just derived I set b=[1−p], a=[1,−p]. The filter starts from the zero state, as the function provides; no zero-phase processing or backward filtering.

7.2. I apply the two filters to the same product

I reopen the Worksheet used in the previous sections. In Functions (114) I search for filter (115) and select numeric.digital_filter (116).

For τ=10 ms I enter in the fields y (117), numerator (118) and denominator (119), respectively:

numeric.multiply(F1:F200,2)
vector(0.048770575499286)
vector(1,-0.951229424500714)

I set Output cell=Q1 (120), press Preview fields (121), wait for the results to be captured, choose y in the Result field (122) and press Apply result (123). The input is the product F already calculated, multiplied by two to keep the same normalization as the progressive mean. Q contains 200 filtered values in volts.

For the second filter I leave y unchanged and replace numerator (124) and denominator (125) with:

vector(0.009950166250832)
vector(1,-0.990049833749168)

I set Output cell=R1 (126), repeat Preview fields (127), check Result field=y (128) and apply the result (129). R contains the 200 values filtered with τ=50 ms. I have not modified F or the progressive mean P.

7.3. I compare the three readings

Procedure in GX-TXT: comparison chart, publication and labels (Figures 31–33)

I select N1:R5 (130), open Chart (131) and press Add selection (132). N contains the nominal time in milliseconds, P the progressive mean, Q and R the two filtered outputs.

I set the title Progressive mean vs RC filters (133), X column=N (134), Y columns=P Q R (135), First row=1 (136), Last row=200 (137). I choose Kind=line (138), Panels=overlay (139), Marker=none (140). I keep X from 0 to 105 ms (141–142) and Y from −0.8 to 1.2 V (143–144), so as not to cut off the large initial oscillations. I press Apply (145), wait for the regeneration and choose Publish immutable Graph to Plots (146).

In Plots I select graph p0003 (147); Presentation (148), Title and labels (149): X / bottom label=Elapsed time (ms) (150), Y Left label=Normalized reading (V) (151). I save (152), open Render (153) and choose Rerender selected (154). I wait for the completion confirmation.

The blue curve P is the progressive mean; the red Q is the output of the 10 ms filter and the green R that of the 50 ms filter. The line joining the samples is a graphical representation of the discrete results, not a new measurement between one sample and the next.

With the 10 ms filter the 20 Hz component remains clearly visible: the output value oscillates on a scale much larger than the 10 mV I am looking for. With τ=50 ms the oscillations are reduced, but do not disappear. The progressive mean behaves differently: it returns exactly to the wanted reading at 50 and 100 ms, where the tones of the product complete an integer number of periods. Neither RC has a transmission zero at 20 Hz.

From the original CSV (x=N, y1=P, y2=Q, y3=R) I read the following instantaneous estimates, rounded in mV:

Time (ms)Progressive mean (mV)RC 10 ms (mV)RC 50 ms (mV)
5010.000403.27422.002
65131.779398.041148.261
10010.000405.99130.096

I must not interpret these three instants as a measurement of the steady-state attenuation alone: the output includes the initial transient, the useful DC component and the residues of the components at 20, 380 and 400 Hz, with their respective phases. At 100 ms the 50 ms filter has worked for just two time constants. Even if the input were pure DC, its step response from the zero state would still be 1−exp(−2), i.e. about 86.5% of the final value. And, in the presence of the interfering tone, the steady state is not a perfectly constant voltage.

Coherent mean or RC filter?

To eliminate an interference at a known frequency the coherent mean can therefore be very effective; to follow slow variations of the signal with a continuous reading, however, a filter suited to the dynamics I want to measure is needed. The comparison does not make either solution universally preferable. Step response, filter order, equivalent noise bandwidth and the quantitative choice of τ will be the subject of the article dedicated to the output filter.

8. What does a single-phase lock-in measure?

Along this path I separated three operations: the product with a reference, integration over a finite duration and low-pass filtering. The product transfers the coherent component to DC; for a unit reference the ideal normalized reading is A cos φ, i.e. the signed projection of the signal onto the reference phase. For φ=0 it coincides with the peak amplitude A; for φ=90° it vanishes even though the signal exists.

The results at a glance

  • Useful signal 10 mV at 200 Hz, interfering tone 1 V at 180 Hz, unit reference at 200 Hz, fs = 2 kHz.
  • Coherent 100 ms record (200 samples): normalized reading 10.000 mV; also 10.000 mV at 50 ms.
  • 65 ms record (130 samples): 131.779 mV, of which 121.779 mV is a false signal from the interfering tone.
  • First-order RC filter: at 100 ms the reading is 405.991 mV with τ = 10 ms and 30.096 mV with τ = 50 ms; the components are attenuated, not cancelled.

With a useful signal of 10 mV and an interfering tone of 1 V I verified that the duration of the mean is decisive: 100 ms return 10 mV, but 65 ms return 131.779 mV. It is therefore not enough to multiply two signals to obtain a selective measurement. The first-order filter, even with unit static gain, attenuates the non-DC components without cancelling them exactly; increasing the time constant improves the attenuation, at the expense of speed.

The tests are deterministic and numerical. They do not include random noise, multiplier non-linearity, RC tolerances or saturation. They do not yet demonstrate the sensitivity achievable on the bench. Before designing a circuit it is also worth understanding better how the response depends on the phase, the frequency difference and the waveform of the reference. This is the subject of the next article, Phase, non-sinusoidal references and harmonics.

#electronics #GX-TXT #signals

Other steps of this project

Leave a Reply

Your email address will not be published. Required fields are marked *