scopes to measure phase shift

If you have the FFT of two sinusoids, A(f) and B(f) and want the phase shift, the formula is a weighted average of ATAN2 ( AIMAG(A), REAL(A) ) - ATAN2( AIMAG(B), REAL(B) ) for all the significant frequency channels using statistical weight W(f) = ||A|| ||B||/( ||A|| + ||B|| )

where ATAN2(x, y) is the arctangent of the ratio x/y, with the usual caveat that the y=0 case has a well-determined arctangent, but not ratio

and ||A|| means the sum of squares of real and imaginary parts of A, represented by the Fortran syntax REAL(A), AIMAG(A)...

The formula accounts for noise in sampling, and the (likely) nonnegligible peak width of the frequency distribution.

Reply to
whit3rd
Loading thread data ...

I doubt it's anything much more complicated than looking at the time difference between the zero-crossings (*) of the two waveforms, averaging some number of measurements, and multiplying by 360/(mean period).

Transform methods are very difficult to automate reliably. Numerical Hilbert transforms don't work well except for pretty narrow-band signals, due to the giant discontinuity at zero frequency, and even Fourier methods are flaky when you expect them to work over arbitrary waveforms and data lengths. If the data consist of long runs with many cycles, then a carefully-designed windowed FFT can do a good job, but a short data run with just a cycle or two of some ghastly waveform won't give a good result that way.

Triggering and averaging is a lot more forgiving.

Cheers

Phil Hobbs

(*) There's probably some mildy-adaptive scheme for choosing the reference voltage for the 'zero crossings'.

--
Dr Philip C D Hobbs 
Principal Consultant 
ElectroOptical Innovations LLC / Hobbs ElectroOptics 
Optics, Electro-optics, Photonics, Analog Electronics 
Briarcliff Manor NY 10510 

http://electrooptical.net 
http://hobbs-eo.com
Reply to
Phil Hobbs

You don't need to window if you restrict the frequency to something that is exactly commensurate with your timebase.

Cross correlation of the two waveforms is probably the way to go.

I'd be very surprised if they did it any other way.

For a single spot frequency it may be cost effective to multiply and sum each channel with an ideal precomputed sine wave and then use ATAN2 on the two resulting summed components to get the right phase quadrant.

--
Regards, 
Martin Brown
Reply to
Martin Brown

All true, except that it's an _oscilloscope_ we're talking about here.

The likelihood of the firmware in a general-purpose scope going to those lengths is pretty small IMO. Scopes have to work with ugly waveforms, duty cycles far from 50%, and so on. Having a dedicated sine-wave mode is more the province of a lock-in amplifier.

The sheer range of special cases required to get even vaguely sensible results from correlations between completely arbitrary waveforms and user setups would be way more trouble than it's worth. It would also be almost impossible to test adequately.

It's not a particularly well-defined problem, anyway: in general the fundamental and harmonics will have different phase shifts, so the correlation peak won't correspond to the phase difference between the fundamental components.

For example, the correlation method would produce head-scratching results when somebody tries to compute the phase error in a PLL whose reference and VCO signals have different duty cycles, as they commonly do. The natural way to quote that is to look at the delay between edges, choosing whichever edge the scope is triggering on at the time. That is, you'd look at the delay from rising edge to rising edge or falling edge to falling edge.

So my vote goes to testing the zero crossings, perhaps with some interpolation for improved precision, and maybe even least-squares spline interpolation for improved noise immunity. At low speeds, running the digitizer at full speed and doing a boxcar average would help too, as in "high-res" modes.

Then once you have the delta-t and the period, you can compute the phase and then average that over N acquisitions. That would give a pretty good result, easily good enough for scope accuracy.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs 
Principal Consultant 
ElectroOptical Innovations LLC / Hobbs ElectroOptics 
Optics, Electro-optics, Photonics, Analog Electronics 
Briarcliff Manor NY 10510 

http://electrooptical.net 
https://hobbs-eo.com
Reply to
Phil Hobbs

The real problem is that there ain't no "Lissajous app" :-)

--
Regards, Joerg 

http://www.analogconsultants.com/
Reply to
Joerg

This is why companies are now almost dragging engineers back out of nursing homes.

No kidding, I think many electronics companies would greatly benefit if they ran a senior living center on the side, at a slight discount and with a large electronics lab plus meeting rooms in the basement, _with_ real whiteboards and pens. This would also prevent a lot of design mishaps that are discovered too late, the kind where ol'Leroy could have told them this isn't going to work, and why.

--
Regards, Joerg 

http://www.analogconsultants.com/
Reply to
Joerg

Speaking of old farts fixing things, some of my people spent a lot of time this week chasing an oscillation in an inverting opamp circuit that, to me, shouldn't oscillate. So I asked, "Are you sure it's really oscillating?" It wasn't. It had a 14 dB gain peak around 1 MHz, and an AM station on Sutro Tower hit that frequency precisely. Adding

3 pF across the feedback resistor killed the gain peak, and putting the board in its metal box fixed the rest.

We have fancy new horrible LED lighting, so we checked that for EMI. None. I've seen fluorescents with electronic ballasts that were ghastly. I want to do an EMI survey of our offices so people will be aware of what they might mistake for oscillations.

Oscilloscopes should have loudspeakers and headphone jacks, to let you hear the signal, or its envelope, or the product of waveforms, things like that. Stereo maybe.

--

John Larkin         Highland Technology, Inc 

lunatic fringe electronics
Reply to
John Larkin

We can suck out waveforms (we have Python code for the Rigol scopes) so we can do math. We could auto-zero the sine waves to correct for any zero offset, maybe lowpass filter a bit, and then do zero crossings. Or equivalently curve fit near the crossings to smooth things out, before the zero crossing measurement. I still think some sort of cross-correlation would be fun. We'll know the frequency, so we can do a precise 90 degree phase (time) shift on one channel, so we can get good resolution on the zero crossing of a cross-correlation... better than looking for a peak.

Whatever we do, it would be easy to verify. I'm testing a box that needs near-zero phase shift with sine waves, so only need to measure

+- a few degrees around zero.
--

John Larkin         Highland Technology, Inc 

lunatic fringe electronics
Reply to
John Larkin

Trying to make a zero-crossing (time) measurement will be more error-prone than necessary. After all, the sampling has captured the full curve, why not USE the whole curve, rather than the small snippet near zero?

Curve fitting near the crossings is going to be a partway patch on the time quantization problem, but going through an FFT does the whole thing, and does it right. Unlike curve-fitting, the FFT is neither throwing data out, nor giving gain to the noise.

Reply to
whit3rd

I checked to see what there was in the way of EE work earlier this year: absolutely nothing round here. Zero. Nearest I could find (too far away) was bigcorp.

NT

Reply to
tabbypurr

Cross-correlation would use the entire waveform. There might be windowing issues... gotta think about that.

Again, it needs a windowing function to smooth out the ends of the acquisition.

The scope can also do a lot of signal averaging for us, before we slurp the waveform data. That helps a lot with a zero-crossing system, given low distortion, which we expect.

Curve fitting does smooth out the scope's time and amplitude quantization.

I guess the FFT is easy nowadays; there are Python libraries for everything.

--

John Larkin         Highland Technology, Inc 
picosecond timing   precision measurement  

jlarkin att highlandtechnology dott com 
http://www.highlandtechnology.com
Reply to
John Larkin

You're massively over-complicating a very simple objective, John. You should get yourself one of these little beauties:

formatting link

100% analogue. Never tells lies.
--
This message may be freely reproduced without limit or charge only via  
the Usenet protocol. Reproduction in whole or part through other  
protocols, whether for profit or not, is conditional upon a charge of  
GBP10.00 per reproduction. Publication in this manner via non-Usenet  
protocols constitutes acceptance of this condition.
Reply to
Cursitor Doom

Those electronic ballasts are surprisingly complex and component-packed for the job they do and the ones I've seen have absolutely no EMI screening whatsoever, so AFAIC, the sooner they die out the better.

--
This message may be freely reproduced without limit or charge only via  
the Usenet protocol. Reproduction in whole or part through other  
protocols, whether for profit or not, is conditional upon a charge of  
GBP10.00 per reproduction. Publication in this manner via non-Usenet  
protocols constitutes acceptance of this condition.
Reply to
Cursitor Doom

John has got sine waves, and he has got a two channel sampling scope.

He just has to least squares fit one sine wave to each channel, with three parameters each - DC offset, frequency and phase.

The parameters are orthogonal, so you can do it in a single - computationally intensive - pass.

Futzing around with zero-crossings doesn't make sens ein this particular application.

--
Bill Sloman, Sydney
Reply to
bill.sloman

What do you mean by cross-correlation ? Is it just multiplying the two signals together? (like a lockin?) If so then it stinks at the maximum. (phase wise) cosine squared.

George H.

Reply to
George Herold

Mine does. It worked fine till I asked it to remember a trace, and then it went dark and hasn't responded since.

Is that a basis for a relationship, I ask you?

Cheers

Phil Hobbs

(who used a 468 with great profit circa 1982.)

--
Dr Philip C D Hobbs 
Principal Consultant 
ElectroOptical Innovations LLC / Hobbs ElectroOptics 
Optics, Electro-optics, Photonics, Analog Electronics 
Briarcliff Manor NY 10510 

http://electrooptical.net 
http://hobbs-eo.com
Reply to
Phil Hobbs

The example code from one of the articles posted in this thread took two buffers (same size and sample rate) and ran an N^2 algorithm multiply-and-add every pair, rotating one buffer to try every possible alignment, and remembering the best one.

It looked like the least efficient possible algorithm to compute the correlation, but it illustrated the principle.

What's the most efficient known way of doing this for non-pathological signals? I get that FFT would work for any signal, but if you know the fundamental frequency you're looking for, why not just multiply each signal by quadrature I and Q to get a phase for each, then subtract for relative phase?

Clifford Heath.

Reply to
Clifford Heath

Analog storage scopes were awful. Besides, we automate all our testing.

--

John Larkin         Highland Technology, Inc 

lunatic fringe electronics
Reply to
John Larkin

Multiply two waveforms and take the integral of the product. Shift one of them a bit in time and do it again. Graph the integral vs the time shift. That's a cross-correlation. If you do that to two copies of the same signal, that's an auto-correlation.

The cross-correlation of my two sine waves will cross zero at 90 degrees time shift if the two sines are exactly in phase. The advantage of the correlation is that it uses the entire waveform, so has much lower noise effects than a simple zero crossing compare.

This is pretty good:

formatting link

--

John Larkin         Highland Technology, Inc 

lunatic fringe electronics
Reply to
John Larkin

It sounds like a convolution.

Calculate the FFT of both buffers, multiply them pointwise, and then calculate the IFFT of the result.

Mike

Reply to
MikeP

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.