TT Lab
Get started
Learn Learning paths Courses

Electronics Foundations — Validating Sensor Inputs

An 875 Hz Signal Disguised as 125 Hz

Continue in TT Lab

In one line

Just because 125Hz appears in the samples, you cannot say the original input was also 125Hz. You change the observation clock, the analog filter, and the numerical convergence one at a time to check how far things can be distinguished.

Why this was needed

The person in charge of a space greenhouse sensor reports that a 125Hz vibration appears whenever the fan is turned on. In the previous unit you lengthened the ADC acquisition time to reduce the memory of the previous channel. But this time the strange frequency does not disappear even though the voltage settles sufficiently. Does the fan really have a 125Hz component, or are we observing a fast vibration slowly and seeing it under a different name?

The acquisition-time problem asks whether a single sample is close enough to the target voltage. The aliasing problem asks whether different continuous signals can produce the same sample sequence. The former is a problem of reducing the error of each sample, and the latter is a problem of distinguishability lost through observation. Increasing the number of bits or printing more decimal places does not solve both problems together.

Analog Devices' input filter FAQ explains that out-of-band components fold into the band of interest after sampling, and that such a component cannot be distinguished from a signal that was originally in the band. Here we do not stop at quoting that principle but produce two real ngspice output files and compare them. It is not an experiment that applies voltage to equipment.

How it works

There are two clocks

The time step at which the simulator calculates the circuit is different from the interval at which we pull samples from the result. ngspice keeps time points in order to solve the circuit equations. You must not treat the row number of the waveform file as the ADC clock. Because of the small time step in the first interval or the internal adaptive calculation, the row spacing can differ from the observation period.

This circuit is a cosine input of 1V amplitude, a series 1kΩ resistor, and a capacitor connected to ground. With the capacitor, the cutoff frequency is fc=1/(2πRC), and you compare 300Hz and 80Hz. No filter is implemented with a 10¹²Ω load instead of the capacitor. Because of this load the gain is not mathematically exactly 1, but the difference is far smaller than this lab's tolerance.

The ngspice official tutorial explains the flow of defining a circuit with a netlist and handling transient analysis results as a file. The provided helper takes care of only that job. You write yourself the parts that pick samples, compute the spectrum, and judge the conditions. The version used is the ngspice42 included in the image, and we do not assume it is the same as the installed version in the web documentation.

The maximum step dt of the circuit calculation is 2µs and 1µs, and the total length is 90ms. The observation starts at 24ms, with 64 samples. If you change the observation rate fs from 1000Hz to 4000Hz, you actually change tᵢ=0.024+i/fs as well. For the 1kHz observation the last sample is at 87ms, and for the 4kHz observation it is at 39.75ms. Changing only the frequency axis of the same 64 numbers by a factor of four is not a new measurement.

If the original file does not have the exact observation time, you linearly interpolate the output voltage of the two rows just before and after it. You must select v(out) after the filter, not the input column v(in). Extrapolation that arbitrarily extends beyond the range is rejected. If the file was cut off partway, you do not produce a normal report just because some of the needed samples exist. A loader that first checks whether it is a complete 90ms waveform is provided.

Why different frequencies get the same name

The first Nyquist zone of a real signal is 0 to fs/2. For a positive input frequency f, if you compute r=f mod fs, the observed frequency in that zone is min(r,fs−r). When fs=1000, 125, 875, 1125, and 1875Hz all fold to 125Hz. If you use only abs(fs−f), it looks right in the first neighboring zone but is wrong in farther zones.

Substitute the cosine samples. cos(2π(fs−f)i/fs)=cos(2πi−2πfi/fs)=cos(2πfi/fs). The start point of 24ms and the two inputs here also match in phase, so the sample sequences of the no-filter 125Hz and 875Hz overlap within the numerical tolerance. It does not mean the sample sequences are always the same for an arbitrary start point, phase, or filter. That is because an RC filter changes not only the amplitude but also the phase.

So the comparison function does not look only at the maximum amplitude of the spectrum. After checking the same fs, start point, and sample count, it finds the maximum absolute difference of each sample. A magnitude spectrum discards phase information. For example, a cosine with the opposite sign has the same magnitude spectrum but not the same sample sequence. Here the name indistinguishable means that they could not be distinguished within the stated observation and the 100µV tolerance.

Why we compute the DFT directly

For 64 samples xᵢ, compute Zₖ=(1/N)Σxᵢ exp(−j2πki/N). The frequency of the k-th bin is kfs/N. For a real signal, the one-sided result keeps only k=0..N/2. The amplitude of an interior bin is 2|Zₖ|, but the DC and Nyquist bins are |Zₖ|. If you unconditionally double even the two endpoints, you overstate the amplitude of a constant voltage and of a signal that alternates in sign.

At 1kHz the bin spacing is 15.625Hz, and 125Hz is bin 8. At 4kHz the spacing is 62.5Hz, and 125Hz is bin 2 and 875Hz is bin 14. Both observations were chosen so that an integer number of signal periods fits in the DFT window. This condition is called coherent sampling. Thanks to that, you can study aliasing itself without mixing in window-function correction or peak estimation between bins.

If a frequency does not match a bin, the energy can spread across several bins. Then you must not use only the maximum bin's amplitude as the original signal's amplitude. The two input pairs of this analysis contract are limited to [125,875] and [375,625]. So as not to attach a frequency name to floating-point residue of a no-signal case, if the maximum amplitude is 1µV or less, peak_hz is null. This is this lab's reporting convention and not a universal sensor detection limit.

Having a filter and satisfying the requirement are different things

The steady-state gain of a first-order RC is G(f)=1/√(1+(f/fc)²). This f is the original frequency that actually entered the filter. If you convert 875Hz to the already folded 125Hz and then compute the RC gain, you reverse the order of filtering and sampling.

Suppose you want to preserve the desired 125Hz amplitude at 0.9V or more and reduce the interfering 875Hz to 0.1V or less. The input amplitude is 1V for both. The rounded values of the analytical formula are as follows. In the actual run report, the values observed from the file go in instead of the calculated values.

Condition Desired 125Hz amplitude Interfering 875Hz amplitude Both satisfied?
No filter About 1.000V About 1.000V No
fc=300Hz About 0.923V About 0.324V No
fc=80Hz About 0.539V About 0.091V No

The 80Hz filter reduces the interference but also reduces the desired signal too much. If none of the three candidates is the answer, should we keep looking for a fourth fc? Working out the inequalities, the passband condition is fc≥125/√(1/0.9²−1) and the stopband condition is fc≤875/√(1/0.1²−1). These are about 258.09Hz or more and 87.94Hz or less. Since the intervals do not overlap, this requirement cannot be satisfied by any single RC.

This is not a lab failure but a design conclusion. You must not widen the tolerance or quietly change the requirement to fill the candidate list. In the next design you should examine the filter order, the observation rate, the input-band assumptions, and so on. A table saying that these three filters failed and a proof that the whole single-RC range has no intersection are evidence of different strength.

Report numerical accuracy and design suitability separately

Solve the same circuit with dt=2µs and 1µs, and check whether the sample difference at the two observation rates is within 100µV. Then check whether the frequencies and amplitudes of the four reports match the folding formula and the RC analytical formula. Having converged does not make it the correct circuit. An input column connected wrongly can also converge stably to the same wrong answer as you reduce the time step.

Finally you check both the desired-band and interference-band requirements. The report leaves convergence, model agreement, and the design requirement as separate fields. An execution error is left as an error, and the case where no filter is acceptable after a normal analysis is left as an empty candidate list. If you merge the two, you cannot tell whether you must change the model or fix the execution environment.

What it looks like in the field

If a team handling sensor, audio, or vibration data finds a low-frequency peak, it first checks the input band, the filter position, and the real sample clock. It does not trust only the number sample_rate written in the file and keeps the timestamps and the acquisition settings together. The value of analysis automation lies not only in drawing graphs quickly but also in letting anyone who reruns it compare the same conditions.

Analog Devices' ideal ADC aliasing explanation distinguishes the roles of oversampling and of analog and digital filters. Interference that has already folded into the band of interest cannot be picked out and removed by a digital low-pass alone. We do not claim to have run the Java applet on this page and refer only to the principle it explains. The real basis for calculation is this lab's stored waveform.

These results are about an ideal RC and uniform sampling. Noise, quantization, clock jitter, a nonlinear ADC, active-filter stability, and part variation across temperature are not in the model. So we do not extend it to performance certification or a safety judgment of a real board. The acquisition switch model of the previous step is also not automatically merged into this circuit. To combine the conclusions of different experiments, you must first verify the model connections.

What you will do in the next lab

In 8 steps you build, in order, the folding function, time interpolation, one-sided DFT, file analysis, sample comparison, the RC requirement interval, filter judgment, and a condition-comparison CLI. You read together the netlist, settings, logs, and original waveforms the helper made and the JSON report you made yourself. The final task is to re-observe at 4kHz the inputs you could not distinguish at 1kHz so as to distinguish them, and to explain why an empty candidate list for a single RC is a legitimate conclusion.