Author Topic: Time-shift millions of ADC samples for best overlap with a periodic signal  (Read 1152 times)

0 Members and 1 Guest are viewing this topic.

Online RoGeorgeTopic starter

  • Super Contributor
  • ***
  • Posts: 8498
  • Country: ro
- there are about 6 or 12 or 24 millions of 8bits ADC samples, downloaded from the oscilloscope (in a single file)
- the signal observed by the oscilloscope was periodic, but it was not synchronous with the ADC sampling clock
- thousands of signal-periods can fit in those 24 millions of ADC samples
- the period of the signal is known, but it has some time-jitter, and some amplitude-noise

The goal is to overlap/align all those thousands of captured signal-periods into one.  Want to align them for averaging all the captured periods into a single period, so I can later compare this averaged single-period waveform, with an expected ideal waveform.

Any ideas how to do that?
Or, if that's a known DSP processing step, what search therms to use in order to find such algorithms?



To be more specific, I want at first to average all the captured periods of a signal into a single (complete) period, then to try to best-fit an expected/mathematical step response with the measured waveform.

For example, let's say I have a series RC circuit, fed with a square wave voltage.  R is known, C is not known.  The oscilloscope is measuring the output waveform on the capacitor, and captures a few kilo-periods of charging/discharging.

Then, I want to best-fit the many measured charge/discharge cycles, with the theoretical step response of an RC.  Or else said, to minimize the square root errors between the ideal step response function and the measured signal+noise, until I get the unknown C (with a much higher resolution than the 8 bits of this ADC, because of all the oversampling+noise).



(Next step would be to change the model of the unknown (ideal) C, with a more complex RLC circuit for that unknown capacitor.  Then to calculate the theoretic step response for the new/more complex model, and try again to best-fit the theoretical response with the measured signal, in order to identify all the new components added to the capacitor model).

Ultimate goal would be to extract the model of an unknown component, by trying to best fit the theoretical step-response with the measured response.
« Last Edit: January 18, 2026, 02:46:13 pm by RoGeorge »
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 9171
Yes, this is a normal signal processing technique: https://en.wikipedia.org/wiki/Cross-correlation
 
The following users thanked this post: RoGeorge

Offline Marco

  • Super Contributor
  • ***
  • Posts: 7755
  • Country: nl
Kinda, but specifically it's a maximum a posteriori estimation problem.

You can just ad-hoc solve it in a lot of ways to get close, but I wouldn't be smart enough to know whether the ad-hoc method introduces a bit of bias.
 

Online PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 3369
  • Country: au
- there are about 6 or 12 or 24 millions of 8bits ADC samples, downloaded from the oscilloscope (in a single file)
- the signal observed by the oscilloscope was periodic, but it was not synchronous with the ADC sampling clock
- thousands of signal-periods can fit in those 24 millions of ADC samples
- the period of the signal is known, but it has some time-jitter, and some amplitude-noise
How much time-jitter?
If you know the period, and the signal to noise is not poor, you can certainly collect groups and fractionally slide them left/right for best-fit to an improving average.
Some errors will not be random however, so you may find 8b ADC is a bit limiting.


For example, let's say I have a series RC circuit, fed with a square wave voltage.  R is known, C is not known.  The oscilloscope is measuring the output waveform on the capacitor, and captures a few kilo-periods of charging/discharging.

Then, I want to best-fit the many measured charge/discharge cycles, with the theoretical step response of an RC.  Or else said, to minimize the square root errors between the ideal step response function and the measured signal+noise, until I get the unknown C (with a much higher resolution than the 8 bits of this ADC, because of all the oversampling+noise).
(Next step would be to change the model of the unknown (ideal) C, with a more complex RLC circuit for that unknown capacitor.  Then to calculate the theoretic step response for the new/more complex model, and try again to best-fit the theoretical response with the measured signal, in order to identify all the new components added to the capacitor model).
Ultimate goal would be to extract the model of an unknown component, by trying to best fit the theoretical step-response with the measured response.
Fitting to a known curve like an RC decay should be possible to good precision, as you can allocate many points along the known curve for the fit.
One the waveform gets unknown, fit is harder and there may be many solutions for the model.

A while ago we assisted someone do an improved frequency counter with a sound card.
The sound card sample rate is somewhat modest, 48-384kHz ballparks, but the vertical resolution is very good, so you can use multiple points to interpolate/fit the rise and fall times to calculate an ideal crossing time.
You can get to ppm levels quite easily, and uncover the clock offset of your PC, or the sound card.



 

Online RoGeorgeTopic starter

  • Super Contributor
  • ***
  • Posts: 8498
  • Country: ro
How much time-jitter?

Both instruments (the oscilloscope and the signal generator that feeds the RC under test) are driven by a quartz.  However, 24 million samples is a lot, and even the small phase noise of the quartz clocks will accumulates as significant jitter in time, after millions of clocks.

I did once such a test, with the AWG connected directly to the oscilloscope.  The trigger was on the first edge.  After a few millions of oscillations, the last edge of the signal was jumping all over the screen (some 200ns or so, as seen at minute 1:05 in https://youtu.be/Okhv8sCQyOM?t=60 ).
« Last Edit: January 18, 2026, 11:41:18 pm by RoGeorge »
 

Online ejeffrey

  • Super Contributor
  • ***
  • Posts: 4849
  • Country: us
How much time-jitter?

Both instruments (the oscilloscope and the signal generator that feeds the RC under test) are driven by a quartz.  However, 24 million samples is a lot, and even the small phase noise of the quartz clocks will accumulates as significant jitter in time, after millions of clocks.

Can you just turn on averaging on the scope and use multiple triggers?  Ideally, your signal generator would have a sync output that would produce a square pulse for triggering the scope. That way there is no accumulation of timing error.  It will be slower because you won't hit 100% duty cycle, but will completely sidestep this problem.  Set your averages as high as it can go in hardware, then do multiple runs in software and average them.
 

Online mtwieg

  • Super Contributor
  • ***
  • Posts: 1812
  • Country: us
For example, let's say I have a series RC circuit, fed with a square wave voltage.  R is known, C is not known.  The oscilloscope is measuring the output waveform on the capacitor, and captures a few kilo-periods of charging/discharging.
In this example, what I would do is use the square wave as the trigger source for the oscilloscope and use an averaging acquisition mode, with a span of just a few periods. Then the scope will do the averaging for you. Doing so retrospectively is much messier, especially if the actual waveform lacks clear features to lock to.

But I don't think simply acquiring one waveform would be very useful. You should acquire at least two different nodes (i.e. input and output). If the real circuit is a higher order, then you would want to acquire that many nodes in the circuit (plus one).
 

Online PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 3369
  • Country: au
Both instruments (the oscilloscope and the signal generator that feeds the RC under test) are driven by a quartz.  However, 24 million samples is a lot, and even the small phase noise of the quartz clocks will accumulates as significant jitter in time, after millions of clocks.

Such long-term wobble is less of an issue, as you resync with each measurement cycle. Crystals at both ends will be well below analog circuit noise floor jitter.

You could allocate a virtual time base of say 1/10th of the generator or scope sampling times if those are significant fractions of your measurement period.
The vertical axis information is then used to tune your y-axis nudges for fractional sample time fit.
 
 

Offline MariuszD

  • Frequent Contributor
  • **
  • Posts: 703
  • Country: pl
This method is known as coherent averaging.

My primitive attempt from years ago. The synchronization with the slope wasn't done well.
« Last Edit: January 19, 2026, 06:29:13 am by MariuszD »
 
The following users thanked this post: RoGeorge

Offline Berni

  • Super Contributor
  • ***
  • Posts: 5391
  • Country: si
The easiest way is to simply feed the signal generator output into another scope channel and use that as the sync source. You can very quickly sync up a square wave by looking at crossings, then optionally you can slide it back and forth by a few samples to pick the one with the smallest difference between the signals.

Real test equipment feeds back the stimulus signal too. They can't trust the signal source to be perfect (especially as the DUT loads it down). So instead they just accept the source is imperfect and instead just measure exactly how imperfect the source is and take it into account in the processing later on. An example of an instrument that does this fully digitally is the Agilent 89410A. It does a FFT of the input and output and subtracts the two to get the frequency and phase response of your DUT, This response would be enough information to fit a RLC circuit onto the response. In general network analyzers make rather good RLC meters for really tiny capacitances and inductances.

At one point i used a scope and signal generator fed via resistor to make a sensitive capacitance meter for quickly measuring into femtofarads. I just used the scopes built in averaging to get a clean waveform to measure the rise time on (using the scopes built in features) and then run that trough math.
 

Online Mahagam

  • Regular Contributor
  • *
  • Posts: 137
  • Country: pl
Re: Time-shift millions of ADC samples for best overlap with a periodic signal
« Reply #10 on: January 19, 2026, 10:18:11 am »
Most of the scopes can do averaging internally. Use it.
 

Offline gf

  • Super Contributor
  • ***
  • Posts: 1832
  • Country: de
Re: Time-shift millions of ADC samples for best overlap with a periodic signal
« Reply #11 on: January 19, 2026, 06:14:28 pm »
- there are about 6 or 12 or 24 millions of 8bits ADC samples, downloaded from the oscilloscope (in a single file)
- the signal observed by the oscilloscope was periodic, but it was not synchronous with the ADC sampling clock
- thousands of signal-periods can fit in those 24 millions of ADC samples
- the period of the signal is known, but it has some time-jitter, and some amplitude-noise

The goal is to overlap/align all those thousands of captured signal-periods into one.  Want to align them for averaging all the captured periods into a single period,

1) Zero-pad the long sequence of samples to double length or more, then calculate the linear autocorrelation using the FFT.
2) Find the peaks of the autocorrelation. Their positions (indices) represent the lags of interest. Only consider positive lags.
3) Starting at each lag index, extract M samples from the long sequence to create aligned short sequences, each of length M
    (such that M samples cover 1–2 periods of the signal, for example, or whatever you want).
4) Average the short sequences.

[ As PCB.Wiz said, you could also upsample for higher resoluton, but for the 1st step I suggest you start with the native sample rate. ]

A simpler way to find the lags would be a simulated  trigger. Find all indices idx where sample[idx] < threshold and sample[idx+1] >= threshold. But expect it to be more prone to noise than the autocorrelation.
EDIT: You also need to implement some hysteris to avoid false triggers in the presence of noise
« Last Edit: January 20, 2026, 11:20:58 am by gf »
 
The following users thanked this post: amyk, RoGeorge


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->