From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Phase Difference

Solved!
Go to solution

I'm trying to measure the phase difference between 2 different sinewaves.  One is a constant, my reference, 7 Vp@ 400 hz.  The other varies as a rotor is turned.  This can be anywhere from 0 ( when the rotor is in the middle of a ref point) to 1.70 Vp @400 hz when the rotor is out to an extreme.  I've been using the Extract Multiple Tone Information.vi ( 2 separate vis) to get the phase of the rotor and the ref.  The way the device I'm using works ( a synchro) is the output is either in phase w the reference or its not.  If its in phase the synchro moved clockwise, out of phase it moved CC.   I then subtract one phase result from the other and arbitrarily chose 45 degrees to be my limit.  If the difference between the 2 is > 45 they are out of phase.  Less..in phase.  The problem I'm having is that , I think, sometimes when the rotor is real close to zero like 100 mv the Extract Multiple Tone Information.vi  can't read it and I get zero phase.  The HELP doesn't tell you the minimum "threshold" that vi can measure.  I've been using .01 then .001 neither of which seems to help.  Does anyone think this is my problem??  That the rotor measurement is too small to use the Extract Multiple Tone Information.vi  ?  Any suggestions/comments on my above method?

thxs..

0 Kudos
Message 1 of 42
(3,534 Views)

The usual way to measure relative phase between two signals is by using a Hilbert Transform on one of them and then solving for Phase with Euler's Formula. 
I'm no expert on the actual process but it's pretty easy to find articles on the details. 

—Ben
Prevent your computer from sleeping programmatically!
Use Power Requests
Download from GitHub

0 Kudos
Message 2 of 42
(3,507 Views)

I'll have to show my ignorance..been out of school a long time.  Googled Hilbert Transform and then solving for Phase with Euler's Formula and was totally confused.

0 Kudos
Message 3 of 42
(3,490 Views)

Also not an expert on the techniques of phase measurement, but would add that it's *ALSO* important to control (or at least know) the time difference between when the signals were digitized.

 

Some devices perform simultaneous sampling.  Most of them share a single A/D converter via multiplexing, putting a small time delay between the conversion times of the different channels in a task.  You can set or query a DAQmx Timing property for the AI Convert Clock Rate.

 

With a multiplexing device if you feed the same signal to both ai0 and ai1, the data for ai0 will *appear* to have phase lag relative to ai1 due to the finite speed of the AI Convert Clock.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
Message 4 of 42
(3,487 Views)

in my case its so fast it doesn't matter.

0 Kudos
Message 5 of 42
(3,482 Views)

You can try the following. Back saved to 2015. You may have to play around with your input signals, theoretically the amplitude of each shouldn't matter as they cancel out. But if your inputs are noisy not sure how it will work. Experiment with this.

 

Snip.png

 

mcduff

 

PS Note in the example above if the random phase is less than -180, for example, -246, the computed phase wraps around, that is you get 114.

EDIT

You also get wrap around when greater than 180.

 

The atan2 function range is -180 to 180, so it wrap between those values.

 

Message 6 of 42
(3,462 Views)

Another challenge migth be noise. If you get close to the optimum position, all signal left is noise (as far as I understood your setup)

 

A maybe more robust method: You use your reference to exactly measure the frequency (400Hz but I assume your DAQ isn't  locked to the 400Hz, tone detection with ~20 periodes should do the job) and apply a linear sine fit at that (~400Hz) frequency (a*sin(wt)+b*cos(wt)+c , a and b define the angle)    for a length of data that is as long as possible to assume a constant frequency  but at least one 400Hz periode. 

For the samplerate I would choose 10kSPS or more ...

It's about the same than the hilbert transform way posted, just without the hilbert transform ... I just don't have enougth experience with the hilbert transform and noise.... but worked a lot with the sine fitting....  If you know your hammer, all problems first look like a nail 😄

However IF your output is zero there is no phase defined!  So if the detected amplitude is very low the uncertainty of the detected phase will raise due to noise.

 

BTW: A syncro would give you two (90° shifted) signals, so if one signal is near zero, the other would give you about max amplitude.

 

Edit: And if you want to hook up a generator to a power net, the final test as far as I remember, is to monitor the voltages across the switch... before you close the switch. I remember 3 ligthbulbs in our student energy lab experiment....

 

 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 7 of 42
(3,382 Views)

There is another method you could try, but I imagine this one may be more susceptible to noise.

 

  1. Make sure your sin waves have a zero mean, that is, no offset.
  2. Determine the zero crossings for each sin wave.
  3. The phase is the difference of zero crossing times divided by the period of the sine wave. (t1-t2)/T
  4. This gives a phase difference with respect to the period, multiply by 360 or 2pi to get degrees or radians.

mcduff

0 Kudos
Message 8 of 42
(3,359 Views)

I do not have LV handy but some ideas...

 

Using PLL for the reference and measured signal then compare the phase of both...

 

Extract Signal tone and compare the phase returned...

 

The right hardware (like that used for LVDT and Resolvers) could make this dirt simple.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 42
(3,349 Views)

@Ben wrote:

I do not have LV handy but some ideas...

 

Using PLL for the reference and measured signal then compare the phase of both...

 

Extract Signal tone and compare the phase returned...

 

The right hardware (like that used for LVDT and Resolvers) could make this dirt simple.

 

Ben


If I am understanding you correctly, this is similar to a "Lock-in" Amplifier.

  1. Take one of your signals as the reference.
  2. Multiply it and the other signal together.
  3. Low Pass filter the result.
  4. The resulting signal is (A1 A2)/2 Cos[Phase difference], where A1, A2 are the amplitudes of the sine waves, and Phase Difference is the phase difference between the two signals.
  5. Better yet add an additional multiplication by shifting your reference 90 degrees, and follow the same steps. Now you have I & Q, so phase is ArcTan[-Q/I].

I thought about recommending this before, but the Hilbert method has the advantage that no low-pass filtering is needed, less steps.

 

mcduff

0 Kudos
Message 10 of 42
(3,344 Views)