# LabVIEW

cancel
Showing results for
Did you mean:

Highlighted

## phase shift base signal

Hello,
I have two sinusoids which have a phase difference which varies slowly over time,  the difference being indicative of position. To measure the phase difference, i have used a premade vi called "Graph and Calcuate Phase differece". I have also used an example online to somewhat sucessfully calculate the phase some of the time.  The example would be the code that was posted in this thread.

These examples work great with theoritcal signals, but there is a problem (see figure below) I am having in practice..  Since the phase shift can occur in the range [-360,+360], i believe the index of the peaks are getting lost, causing it to pick up the next peak in the sequence, thus, causing a phase shift (see figure below, plot of phase shift) to be measured.  Another way of saying this is that after a small amount of phase shifting occurs, the lead peak begins to references the next peak in the comparison signal.

Im at  loss on how to identify the peaks and track them so i can accurately measure phase shift.  Any help is appreciated. Im sure this is soemthing that has been done before, esp since there is a vi just for measuring phase shift. I guess i just dont know the key words to find it...

Below is a screen shot showing the two signals. The bottom plot is showing there is a relative small shift in phase which periodically jumps.

many thanks
Jim from CT

Message Edited by JimmyinCT2 on 01-23-2008 07:17 PM
Message 1 of 7
(6,598 Views)

## Re: phase shift base signal

Hi Jim,

Try using "Dual channel Spectral Measurement" express VI instead. Assuming you're using LabVIEW 8.5, it can be found under Signal Processing>>Waveform measurement.

Regards,
Stanley Hu
National Instruments
Applications Engineering
http://www.ni.com/support
Message 2 of 7
(6,572 Views)

## Re: phase shift base signal

it turns out there are 3 or 4 vis in the example i download, linked in above.

one of the examples, called phase measurement,  will correct for this type of shifting of the range [-360 to 360], the one called "phase difference" wont and will give out phase shifts greather then 360..

anyway, maybe that will help someone in the future more then the typical upgrade answers..

Message 3 of 7
(6,556 Views)

## Re: phase shift base signal

Im still having trouble measuring phase shift.

I did use the dual channel spectral measurement vi that was mentioned above.

I made a movie of what the signal looks, how the phase shift bumps,  and also the visual code used

www.engr.uconn.edu/~jmacione/output.avi (50mb, so might want to right click and save to disk)

Im at a loss here on how to get a stable measurment

Message Edited by jimmyinCT on 01-25-2008 05:07 PM
Message 4 of 7
(6,533 Views)

## Re: phase shift base signal

Maybe I'm not looking in the right place but the output looked completely wrong to me.

Here's a vi I made a while ago to measure phase shifts (of the most dominate frequency), you just need to input the two waveforms to compare against. Maybe this will work for you (hopefully I copied the newest working version). I'm not sure how well it would work in you application though.

Another thing to consider is if your phase shift is varying constantly (like 1 degree per second), then your signals may just not be the same frequency (or maybe they're being measured by devices with independent clocks).

If your still having problems, try posting some sample data (could be embedded as default values in a control) and an example vi that uses that data.

Matt W

Message 5 of 7
(6,526 Views)

## Re: phase shift base signal

dahhh, okay, i think i finally figured out what is going on here, and i think im just being somewhat dumb or maybe just assuming to much.

Looking at matts example helped a lot as i see why.

with one of the old VIs for measuring phase shift, we were getting a phase shift range of [-360, 360] or more.    We were just assuming that was the range here with this new VI.

With the new dual channel measurement (or the example you posted), when phase is measured, there is an inflection point at some angle of phase difference..  The way your example works (and the express vi) is with an inflection at 180 degrees.  So, lets imagine we have a measurement of phase shift that is 178 degrees, as this difference increases, the next is 179,  and then 180..  Now as it continues to move, the next phase measurement will not bet 181 but instead -179.   As the signal continues to move in the same direction, its then 178, 177, 176.. So there is an inflection point at 180 degrees with two sinusoids, in simple terms, its because the phase difference of one sinusoid to the other has shifted and is now being measured in reference to the next peak in the series.

Its troubling for measurements are if you turn on a machine that is measuring phase, and it happens to be right near -/+180, it can cross that boundary often, creating substantial noise.   Also, that for certain types of peak detection, such as for motion, its desirable to have a larger range such as [-360,360] which should be theoretically possible (like the first vi we used)  but i guess [-720, 720] could be done too assuming there is enough difference between the peaks.  It would have been awesome to have a VI that measures peak movement outward to infinity.   We were originally using a VI that calculated out these larger differences, think it was doing the calcs in frequency domain (imaginary nums) rather then cross correlation like the example.

.

I think for now, we are going to have to work inside the range [-180,180] and initialize our hardware to 0 phase so we dont start near the inflection point and see if that works.

Message Edited by jimmyinCT on 01-26-2008 07:54 PM
Message 6 of 7
(6,502 Views)

## Re: phase shift base signal

Thanks a lot. Matt
Message 7 of 7
(6,120 Views)