For background info I am an EE/CE that is 10 years out of school and has since worked writing firmware and dealt mostly with digital communications and signals, so now I am having to reach back to my (very) atrophied analog knowledge.

I am working with a 4 channel ADC, and I am trying to get a rough estimate of the input skew between channels when a 'simultaneous' capture is performed.

I got the device with all 4 channels hooked up to a single sine wave from my function generator, performed the capture, and am now trying to analyze the data.

I know the maximum amplitude of the sine wave as well as the frequency. I remember calculating instantaneous voltage for known phase angles, but I can't seem to figure out how to get the phase angle from voltage (I am aware that there will be two possible angles for a given voltage.)

My overall game plan is to determine the angle of each reading, then using the known frequency get skew time by \$sk = (Ch2\angle - Ch1\angle) * (360 \div hz) \$

  • How a can I get phase angle for a point on a known sine wave?
  • Is there a better way to go about what I am doing?
  • 1
    \$\begingroup\$ If you have the derivative of the signal also (or an equivalent) you can get the phase angle uniquely; the sine passes the same value once when going up and once when going down. One stand-in for derivative is to take the difference with the previous sample. \$\endgroup\$
    – AJN
    Jun 17, 2020 at 15:41
  • \$\begingroup\$ Are two signals guaranteed to be pure sine waves of same frequency ? Will there be significant noise ? There may be better methods of calculating skew. You may want to search for phase detection schemes. Phase detectors are part of phase-locked loops and are well researched topic. Alternately, why not just subtract once channel with time delayed version of the other channel and search for the delay which results in minimum difference signal. that delay is the time delay between the signals. \$\endgroup\$
    – AJN
    Jun 17, 2020 at 15:43
  • \$\begingroup\$ +1 to what @AJN said- It's easy if you have 2 noiseless perfectly sinusoidal waveforms of known amplitude and frequency. If anything is non-ideal or noisy it becomes a much bigger challenge. \$\endgroup\$
    – John D
    Jun 17, 2020 at 15:48
  • 1
    \$\begingroup\$ Phase is relative. To get absolute values you must choose stable reference at same identical frequency.. Consider a PLL. But more import why do you want to measure this? \$\endgroup\$ Jun 17, 2020 at 15:51
  • 1
    \$\begingroup\$ Use a square wave and save yourself the hassle. It will give you the time difference and this relates to the phase but, the time difference is probably more important. \$\endgroup\$
    – Andy aka
    Jun 17, 2020 at 17:48

3 Answers 3


If the fundamental frequency of the two waveforms you are comparing is known, then a DFT of each, over samples for exactly one period will give you a nice complex number for each fundamental, whose argument (angle) can be calculated and subtracted for a phase difference.

You don't actually need a full FFT or DFT over the entire spectrum, you just require information for the fundamental, which can be obtained from just four simple O(n) operations. We do what the DFT algorithm does, but only for the fundamental component. For each signal, sample set \$v\$ (consisting of N samples), calculate:

$$ \sum^{N-1}_{n=0} v_ncos(\frac{2\pi n}{N}) $$

for the real part, and

$$ \sum^{N-1}_{n=0} v_nsin(\frac{2\pi n}{N}) $$

for the imaginary part. Then do the same for the second signal. Now you have two complex numbers, and you need to find the difference of their arguments, which will be phase difference in radians.

Notice that I didn't scale those values in any way, because you are not interested in amplitude, only phase.

Update: Doing this in real time isn't that difficult. This is just a sum of products. If you keep track of those products in a FIFO list of fixed length, then as each sample comes in you can update the total by subtracting the oldest product in the list, which is then "popped" and discarded, and adding the new product, which is then "pushed" into the list. Wow, that's difficult to explain in words.

If that sounds too complex (heh), and the signal isn't too noisy or harmnonically "busy" (if they are sinusoids, then it's easy), you could approach the problem with software-implemented hysteresis.

In software, mimic comparators with positive feedback (for hyseresis), in which you determine the instants in time when the comparators' outputs rise. The time difference between the rising edges is then the phase delay between the two signals.

For example, iterate the samples of a few periods of each, to find their maximum \$V_{MAX}\$ and minimum \$V_{MIN}\$ values. You then calculate hysteresis thresholds to be \$\frac{1}{3}\$ of the way between them, and \$\frac{2}{3}\$ of the way:

$$ \begin{aligned} V_{L} &= V_{MIN} + \frac{1}{3} \left( V_{MAX} - V_{MIN} \right) \\ \\ V_{H} &= V_{MIN} + \frac{2}{3} \left( V_{MAX} - V_{MIN} \right) \\ \\ \end{aligned} $$

Now iterate the samples again, setting a flag whenever a sample exceeds \$V_H\$, and clearing it when the sample value drops below \$V_L\$. Do that for the two signals you wish to compare. The number of samples between rising edges (the flags going high) for each is proportional to the delay between the two.

To perform this in real-time, keep track of peaks and troughs in the waveforms as the samples come in, updating \$V_{MAX}\$ and \$V_{MIN}\$, and recalculating \$V_L\$ and \$V_H\$ accordingly. You could implement some kind of moving average to follow \$V_{MAX}\$ and \$V_{MIN}\$ over time.

This may not be as accurate as a DFT, because it's more sensitive to noise, but it's pretty simple, and works without any knowledge of the frequencies involved. In fact, you can determine frequency also from those edges.

  • \$\begingroup\$ Related answer: electronics.stackexchange.com/a/650308/311631 in this case you only need the first part (no testing for impedance). Though, taking the argument (angle) of complex ratios, does get the phase between channels. \$\endgroup\$ Mar 21 at 10:47

You need to know the exact time difference between the instants when each of the waveform peaks.

If V1 peaks at t1 and V2 peaks at t2, or you somehow measure the time interval delta_t between their peaks, you can calculate the phase difference between them by using the following formula. T is the time period of the wave-forms.

phase difference (in degrees) = delta_t * 360 / T = (t1 - t2) * 360 / T

There are some other methods like zero crossing detection or more sophisticated techniques using FFT but I think the peak detection, like I described above, will give you a good estimate with minimal effort.

See the figure "normal measurement" for what I am trying to say. But sometimes your signal is noisy (see figure "noisy measurement"), and in that case, peak detection algorithm will have some innaccuracy depending on SNR.

enter image description here

enter image description here


Assuming you have some calculation hw (computer or micro) you can use FFT or sine-wave fitting.

  1. with FFT you calculate the angle of the fundamental you have applied for each of the four channels; for accurate results sampling must be synchronous, otherwise the real frequency will occur in between two bins (picket fence effect); in this latter case you should use interpolation e.g. by using 3-point DFT interpolation.
  2. sine wave fitting will remove most of the distortion and noise, so that you can then apply simplified calculations (e.g. zero crossings) knowing that the signal you use is really sinusoidal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.