12-12-2016 11:32 AM
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
Solved! Go to Solution.
12-12-2016 12:42 PM
@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.
12-12-2016 01:04 PM
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.
12-12-2016 01:50 PM
@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)
12-13-2016 03:35 AM - edited 12-13-2016 03:36 AM
using the point by point unwrap as a startpoint:
However quick&dirty ... not tested
12-13-2016 06:34 AM
@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".
12-13-2016 07:19 AM
I coded up something quick using the Unwrap.VI to find the indexes.
12-13-2016 07:00 PM - edited 12-13-2016 07:06 PM
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.
So thanks again for all the great ideas.