LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Detecting Phase Wrap

Solved!
Go to solution

Hello,

I'm attempting to compute gain margin.  Is anyone aware of a function that will detect the locations (indicies) in an array of phase data where the phase wraps?  I have access to all NI toolkits as well but have not been able to find a function do to so.

 

I've attached a simple example that attemps to detect the indicies in the phase array where the phase wraps around ±180° but think that it may be succeptable to false positives resulting from signal noise.

 

Any suggestions on a better way to do this are greatly appreciated!

 

Thanks for your time.

Steve

0 Kudos
Message 1 of 8
(4,983 Views)

@Electromecha wrote:

Hello,

I'm attempting to compute gain margin.  Is anyone aware of a function that will detect the locations (indicies) in an array of phase data where the phase wraps?  I have access to all NI toolkits as well but have not been able to find a function do to so.

 

I've attached a simple example that attemps to detect the indicies in the phase array where the phase wraps around ±180° but think that it may be succeptable to false positives resulting from signal noise.

 

Any suggestions on a better way to do this are greatly appreciated!

 

Thanks for your time.

Steve


No need to reinvent the wheel. There is a VI in the "Signal Processing->Signal Operation" called Unwrap Phase.vi. I've used it successfully many times without any issues from noise.

 

Phase WrapVI.JPG

Message 2 of 8
(4,959 Views)

Thank you for your response.  I understand that the VI you indicated unwraps the phase, but I'm looking specifically for the indicies where the phase wraps.  This VI does not output that information.

0 Kudos
Message 3 of 8
(4,942 Views)

@Electromecha wrote:

Thank you for your response.  I understand that the VI you indicated unwraps the phase, but I'm looking specifically for the indicies where the phase wraps.  This VI does not output that information.


@Your original approach appears very close Look for the product of connsecutive numbers to be negative.  However, you can get fales "Wraps" (e.g. @Index 359) if the product is a small negative number.  Use Less Than -900 (filters 30 degrees to - 30) 


"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 8
(4,920 Views)

using the point by point unwrap as a startpoint: 

However quick&dirty ...  not tested

unwrap with detect.png

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 ǝɥʇ'


Message 5 of 8
(4,879 Views)

@Electromecha wrote:

Thank you for your response.  I understand that the VI you indicated unwraps the phase, but I'm looking specifically for the indicies where the phase wraps.  This VI does not output that information.


I don't know the specifics of your algorithm why you need the indexes of the wraps. But here is a method to consider using the Unwrap.VI

 

I ran your data using Unwrap.vi and plotted it out below. For the unwrapped data, "wraps" now occur at 180 +/- N*(360) degrees. i.e., at -180, -540, -900, -1260, etc. One advantage of this method is that it gives you the opportunity to curve fit/filter the unwrapped data to smooth out any noise present in the signal before you search for the "wraps".

Data.JPG

0 Kudos
Message 6 of 8
(4,867 Views)

I coded up something quick using the Unwrap.VI to find the indexesWrap (Method 2).png.

Message 7 of 8
(4,861 Views)
Solution
Accepted by topic author Electromecha

These have all been great ideas and potential solutions.  Thanks to all of you!  What an awesome forum this has always been.

 

For more background, this all came about because I support a mechanism control system that was using the NI Control Design and Simulation Toolkit, specifically the CD Gain and Phase Margin.vi.  The mechanism is injected with sine sweeping disturbances and the resulting system response is captured and analyzed as a control system.  The phase margin output from the CD Gain and Phase Margin.vi was accurate but the module always threw a warning stating that the gain margin was infinite.  And indeed the gain margin output was Inf.

 

So I couldn't get the answer out of the toolkit and needed to implement the calculations for gain margin manually:

http://www.mit.edu/afs.new/athena/course/2/2.010/www_f00/psets/hw3_dir/tutor3_dir/tut3_g.html

 

The key step in the process of determining gain margin is knowing where the phase data wraps.  Hence, why I originally created this post.  You need to find all the wrap locations and then transfer those indicies to the open loop bode plots to determine the minium gain margin of all the wrap locations.  Fun!

 

So I got the 'work around the toolkit' code working well enough but wasn't satisfied and after receiving jamiva's initial response to this post, I circled back around to the Unwrap Phase.vi and unwrapped the phase signal before passing to the CD Gain and Phase Margin.vi. Voila!.  The gain margin is now reported correctly.  The help desn't specify that the phase needs to be unwrapped, but no biggie, you can't tell users how to do everything because the documentation would be endless and to a control engineer this is probably obvious.

 

I'm not able to share any source code other than sample concepts but here's a picture of what ultimately solved the problem.

 

Unwrap Phase.png

 

So thanks again for all the great ideas.

Message 8 of 8
(4,838 Views)