When a Sine Wave Disappears into Noise
In the first article I managed to recover the amplitude of a signal even in the presence of a much larger interfering voltage. Now I want to separate two problems: the presence of other deterministic components and the presence of random noise. For this experiment I do not yet introduce a second sine wave. I want to see what changes if I keep the same signal and increase only the noise.
1. What does a 1 mV signal mean?
A sine wave with peak amplitude A has an RMS value of A/√2. If A is expressed in volts, the square of the RMS value is expressed in V²: it is the mean square value, not a power in watts. To obtain the power dissipated in a resistance R, you have to divide by R.
\[ s(t) = A\sin(2\pi f_0 t), \qquad V_{s,\mathrm{rms}} = \frac{A}{\sqrt{2}}. \]
For a sequence of N noise samples nk, I define the RMS value as the square root of the mean of the squares. If the noise has zero mean, the mean square value coincides with the population variance; in the finite sequence I must not assume that the mean is exactly zero.
\[ V_{n,\mathrm{rms}} = \sqrt{\frac{1}{N}\sum_{k=0}^{N-1} n_k^2}. \]
For signal and noise referred to the same impedance, I can express the power signal-to-noise ratio as the ratio of the squares of the RMS values:
\[ \mathrm{SNR} = \frac{V_{s,\mathrm{rms}}^2}{V_{n,\mathrm{rms}}^2}, \qquad \mathrm{SNR}_{\mathrm{dB}} = 10\log_{10}(\mathrm{SNR}) = 20\log_{10}\frac{V_{s,\mathrm{rms}}}{V_{n,\mathrm{rms}}}. \]
A negative SNR
A negative SNR in decibels means that the mean square value of the noise is larger than that of the signal, not that the signal has a negative power.
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 signals and compare your results with mine. Then change something — the generator seed, the number of samples, the noise level — and see how the signal-to-noise ratio and the spread of the estimates move. It is the best way to really understand what noise does to a measurement, and to have some fun too.
2. I set up a reproducible experiment in GX-TXT
I create a separate session in Sessions → Session → New Session. I enter LockIn_02_sinusoide_rumore in the Session name field (1) and confirm with Create (2). I use GX-TXT DEV112 P012 with the fixes described in the previous article. After every Dataset operation I wait until it has actually finished before going on.

I choose Viewers → Worksheet and save the sheet with Save. I will build the 200 Hz signal with a peak amplitude of 1 mV, using 200 samples at 2,000 Hz. I will use the same noise realization at different scales, so as to isolate the effect of its amplitude. This is not yet a test with independent realizations.
I build the time samples and the sine wave
I open the Functions panel of the Scientific Worksheet (3), look for numeric.uniform_grid (4) and set start = 0, stop = 0.0995, spacing = 200 and Options = mode="count" (5). I press Preview fields (6), wait for the result, choose the x field (7) and the destination A1 (8), then Apply result (9). Column A contains 200 instants, from 0 to 99.5 ms: the discrete window has a nominal length of 100 ms.

I select signal.generate.sine (10). In the time field I enter A1:A200; frequency = 200, modulation = empty() (11). In Options I write amplitude=1 phase_rad=0 (12). After Preview fields I choose value_real and B1 (13), then Apply result. I keep the voltage values in millivolts: the numerical amplitude 1 corresponds to 1 mV.

The same realization at different noise levels
I select signal.generate.white_noise (14), use A1:A200 as the time grid and empty() in the frequency and modulation fields (15). I set amplitude=1 seed=23001 (16), then Preview fields, value_real, destination C1 (17) and Apply result. C contains the noise vector that I will use as a base. The amplitude parameter is the theoretical standard deviation of the distribution: the P012 Signal provider multiplies standard normal samples by this factor, without imposing an exact RMS on the finite sequence. Here σ = 1 mV. The seed is fixed so that the test can be reproduced; the RMS value of the realization is not necessarily exactly 1 mV.

I add the noise to the sine wave
I switch to the Cell & Formula tab (18). I use Go to (19) to choose the destination cell and enter the formula (20), confirming it with Apply (21). The function numeric.multiply multiplies each element of the vector by the given scalar; numeric.add adds the vectors element by element.
| Cell | Formula | Signal |
|---|---|---|
| D1 | =numeric.add(B1:B200,numeric.multiply(C1:C200,0.1)) | s + 0.1n |
| E1 | =numeric.add(B1:B200,C1:C200) | s + n |
| F1 | =numeric.add(B1:B200,numeric.multiply(C1:C200,10)) | s + 10n |

3. I measure the signal-to-noise ratio
In the sheet I calculate the RMS value of the sine wave in H1 with =numeric.rms(B1:B200), that of the noise in H2 with =numeric.rms(C1:C200) and the mean of the noise in H3 with =numeric.mean(C1:C200). The results (23) are 0.70710678 mV, 0.87951363 mV and −0.0077152801 mV respectively. So I have noise with a mean close to zero, but not identically zero. Its actual RMS is lower than the nominal value set: for a finite realization it is not obliged to coincide with it.
For the three cases I calculate the SNR in H4:H6 using the RMS value of the signal and that of the noise measured over the same interval. I do not use the RMS value of the total input in place of the RMS value of the noise.
| Cell | Formula | Noise RMS (mV) | SNR (dB) |
|---|---|---|---|
| H4 | =20*numeric.log10(H1/(0.1*H2)) | 0.087951 | 18.104849 |
| H5 | =20*numeric.log10(H1/H2) | 0.879514 | −1.8951515 |
| H6 | =20*numeric.log10(H1/(10*H2)) | 8.795136 | −21.895151 |

A factor of ten on the noise is 20 dB
Multiplying the noise by ten multiplies its mean square value by one hundred: the SNR drops by 20 dB. The three values obtained from the sheet confirm this relationship. The comparison keeps the noise realization fixed; it does not represent three independent acquisitions. To evaluate the variability of a measurement, independent sequences will be needed instead.
4. I look at the waveforms on the same scale
In the Worksheet I select A1 and open Chart (26). With Add selection (27) I create a chart, then set X column = A and Y columns = B D E F (28), First row = 1 and Last row = 200 (29), Kind = line, Panels = overlay (30), Legend = above. I press Apply (31) and wait for the chart to actually display all four series.

Publishing the graph in Plots (Figure 8)
I save the sheet, wait for the Dataset operations to finish and press Publish immutable Graph to Plots (32). In this version of GX-TXT you have to wait a moment after Dataset operations: before starting the next one, I check that the previous one has actually finished. I also wait for the chart to render. The command produced the Dataset worksheet_chart_1796035933237099, containing 200 rows and five columns (time and four voltages).
In the Plots tab (33) I select Plot p0001 (34), where I find the published figure.


The red curve closely follows the blue one, while the green one is already clearly distorted. In the purple curve the noise fluctuations dominate the waveform. The sine wave has not disappeared mathematically: it is still there with the same amplitude and phase. It is direct reading in the time domain that becomes difficult. The common scale highlights how different the amplitudes are, but it compresses the smaller traces; a comparison on panels with separate scales will make the details easier to read.
These three cases do not yet allow a statistical estimate of the uncertainty of a measurement. The next step is to compare different noise realizations and the effect of the observation time.
I look at the four waveforms separately
To see the differences in shape more clearly, I go back to the Chart tab of the Worksheet and choose Panels = separate (35). I confirm with Apply (36) and enlarge the chart area by dragging the horizontal divider between the table and the charts upwards (37). With four panels you need to leave enough room for the ordinates, the titles and the legend. I wait until all four traces are displayed.

Now I can see that, at the lowest noise level, the periodicity of the sine wave is still evident. In the intermediate case it is no longer so easy to recognize each period, and in the worst case the waveform is dominated by noise. The vertical scales are different: this representation helps to compare shapes, while the chart in Figure 9, on a common scale, compares amplitudes.
5. I change the noise realization
So far I have multiplied the same sequence by different factors. This let me control the amplitude of the noise, but not study the variability from one measurement to another. I now set up a second experiment: I keep the nominal noise scale at 1 mV and use five different seeds of the Gaussian generator.
For each sequence I want to evaluate both the RMS value of the noise and the in-phase estimate I would obtain with an ideal reference at the signal frequency. With a reference rk = sin(2π · 200 tk) and input sk + nk, over N samples the estimate is
\[ \hat{A}_N = \frac{2}{N}\sum_{k=0}^{N-1} (s_k + n_k)\, r_k. \]
I use windows of 20, 100 and 200 samples, i.e. 10, 50 and 100 ms respectively. Each of them contains whole periods of the sine wave, so the deterministic part of the calculation returns the amplitude that was set. The reference contains no noise. The windows of the same realization share their first samples: the corresponding estimates are not independent of each other.
In the ideal case of independent noise samples with zero mean and variance σ², the random contribution to the estimate has variance (4σ²/N²) Σ rk². For the coherent windows I chose, Σ rk² = N/2, so
\[ \mathrm{Var}(\hat{A}_N) = \frac{2\sigma^2}{N}, \qquad u(\hat{A}_N) = \sigma\sqrt{\frac{2}{N}}. \]
What I expect
So I expect a spread that decreases as the inverse of the square root of the number of samples. I do not expect the error of every single sequence to decrease monotonically. Five realizations are enough to illustrate this concept, not to check the statistical law accurately or to establish a detection limit.
I generate the sequences with the Worksheet
In the same sheet I keep C1:C200 (seed 23001) and repeat the guided operation signal.generate.white_noise of Figure 4, with time = A1:A200, frequency and modulation = empty(). I change only the seed in the Options field (38), keeping amplitude = 1, and the destination (39). For each new seed I press Preview fields, wait for value_real to be captured and press Apply result (40).
| Seed | Noise column |
|---|---|
| 23001 | C |
| 23002 | I |
| 23003 | J |
| 23004 | K |
| 23005 | L |

I calculate the estimates over windows of different length
In Cell & Formula I choose N2 (41). I use a formula that returns a vector of five scalars: RMS and mean of the noise, then the three in-phase estimates. The results extend from N2 to N6 (43). The sine wave is still B; the first random sequence is C. For the first realization I enter (42):
=vector(numeric.rms(C1:C200),numeric.mean(C1:C200),2*numeric.mean(numeric.multiply(numeric.add(B1:B20,C1:C20),B1:B20)),2*numeric.mean(numeric.multiply(numeric.add(B1:B100,C1:C100),B1:B100)),2*numeric.mean(numeric.multiply(numeric.add(B1:B200,C1:C200),B1:B200)))
The sums are performed element by element before averaging. The windows use the first 20, 100 and 200 samples. For the other realizations I repeat the formula in O2, P2, Q2 and R2, replacing every reference to column C with I, J, K and L respectively, without changing the references to the sine wave B.

Comparing the results
The five sequences produced the values shown in the table. The signal amplitude is still 1 mV and the reference is still ideal. The RMS value refers to the whole sequence of 200 samples, while the three estimates refer to different windows.
| Seed | Noise RMS (mV) | Noise mean (mV) | Â 10 ms (mV) | Â 50 ms (mV) | Â 100 ms (mV) |
|---|---|---|---|---|---|
| 23001 | 0.879514 | −0.007715 | 0.926591 | 1.006956 | 1.016509 |
| 23002 | 1.019167 | −0.063164 | 1.144135 | 0.941695 | 0.915589 |
| 23003 | 1.007134 | −0.039970 | 1.288479 | 1.105615 | 1.076557 |
| 23004 | 0.972958 | 0.010748 | 0.503935 | 0.793357 | 0.920839 |
| 23005 | 1.023241 | −0.072139 | 0.877044 | 1.053974 | 1.058663 |
Storing the results in a Dataset (Figure 13)
To keep the numerical quantities I select N2:R6 and use Data → Publish Dataset…. In the window I check the range (44), assign the identifier lockin.s02.seed_comparison (45), leave the option that treats the first row as a header disabled (46), assign the seeds to the columns (47) and press Publish Dataset (48), once the previous operations have finished.

At 10 ms the estimates range from about 0.504 to 1.288 mV; at 100 ms from about 0.916 to 1.077 mV. In this small set of tests the spread decreases. Not every single estimate, however, improves monotonically: for seed 23002 the 100 ms estimate moves slightly further from the true value than the 50 ms one. This is a property of the random nature of the measurement, not a contradiction of the theoretical variance law.
The table is a first comparison of five realizations; to estimate the spread precisely I will have to increase the number of tests and calculate the sample statistics.
Micropatch MP005 for GX-TXT DEV112 P012
To keep the Worksheet with all its formulas and history, I use micropatch MP005 (bug 237, ZIP). The fix enables the compact representation without loss of history, already supported by the framework. It does not delete the recorded steps and does not change the calculations.
With GX-TXT closed, I extract the ZIP and replace plugins/modules/viewer.scientific_worksheet/api/workspace_native.tcl in the P012 framework directory with the file provided. I restart GX-TXT, respecting the order of the micropatches. MP005 is distinct from MP004. I verified saving and then reopening the same workbook: the five formulas and all the results are still there. The test was carried out on P012 with the previous fixes.
From five estimates to the standard deviation
I can now quantify the spread I observed in the table. For each window length, I denote by aj the estimate for seed j, with M = 5 the number of realizations. I calculate the arithmetic mean and the sample standard deviation:
\[ \bar{a} = \frac{1}{M}\sum_j a_j, \qquad s_a = \sqrt{\frac{\sum_j (a_j – \bar{a})^2}{M-1}}. \]
I compare sa with σ√(2/N), using σ = 1 mV, i.e. the theoretical standard deviation set in the generator, not the RMS of a single sequence. The theoretical quantity is the standard deviation of a single estimate; it is not the uncertainty of the mean of the five estimates.
I reopen the saved Worksheet. In Go to I enter T2 (49); in the Cell & Formula tab I enter the following formula (50) and press Apply (51). The command numeric.std calculates the sample standard deviation. For each of the rows N4:R4, N5:R5 and N6:R6 I obtain, in order, the mean, the sample standard deviation and the theoretical prediction.
=vector(numeric.mean(N4:R4),numeric.std(N4:R4),numeric.sqrt(2/20),numeric.mean(N5:R5),numeric.std(N5:R5),numeric.sqrt(2/100),numeric.mean(N6:R6),numeric.std(N6:R6),numeric.sqrt(2/200))

The nine quantities are now shown in T2:T10 (52). Each group of three cells corresponds to a different window length. I have kept the voltage unit in millivolts.

| Window | N | Mean (mV) | Sample std. dev. (mV) | Theoretical std. dev. (mV) |
|---|---|---|---|---|
| 10 ms | 20 | 0.948037 | 0.298781 | 0.316228 |
| 50 ms | 100 | 0.980319 | 0.120706 | 0.141421 |
| 100 ms | 200 | 0.997631 | 0.075727 | 0.100000 |
The sample spread falls from about 0.30 to 0.076 mV. In this particular set of tests the means also get closer to the value of 1 mV. It is not guaranteed, however, that all the single estimates get closer to the true value as the window gets longer. The standard deviation describes the spread between realizations, not the maximum possible error.
The result is qualitatively consistent with the theoretical 1/√N dependence: I do not claim to verify it precisely with only five realizations. The sample deviations are all smaller than the theoretical predictions, but with four degrees of freedom their variability is high. Moreover, the windows of the same sequence are nested: I do not treat the three time columns as three independent experiments. I cannot derive a detection limit or an uncertainty for a real circuit from this table.
6. What have I learned from this experiment?
A sine wave can be hard to recognize in the time domain even when its amplitude does not change. The signal-to-noise ratio in decibels lets me quantify the comparison. Synchronous detection, if I know the frequency and phase of the signal, turns the useful component into a measurable average contribution; random noise leaves a residual spread which, in the ideal model, decreases as the number of samples grows. In the next articles I want to understand how physical noise sources and their spectral distribution affect this possibility. So far I have used only synthetic signals: I have not yet simulated or built the circuit.
The results at a glance
- The same noise realization at three scales: SNR of +18.105, −1.895 and −21.895 dB; multiplying the noise by ten lowers the SNR by 20 dB.
- Five independent seeds, windows of 10, 50 and 100 ms: sample standard deviations of the estimates 0.299, 0.121 and 0.076 mV, against theoretical predictions of 0.316, 0.141 and 0.100 mV.
- Means of the five estimates: 0.948, 0.980 and 0.998 mV, for a true signal of 1 mV.
In the next article, The origin of electronic noise, I move from synthetic noise to physical mechanisms: Johnson–Nyquist thermal noise, shot noise and 1/f noise.