08-15-2017 08:49 AM
@randomguy77 wrote:
So does just the mean ptbypt need to be in a loop, or should I have the entire section that is finding the phase in a loop as well, or should the whole vi be in a loop, and then a subloop that has the mean calculation being done?
Your entire application should be in a loop. Then you add a stop button to stop the loop. This is the alternative to using the Run Continuously, which was only designed to be a debugging tool.
08-15-2017 08:50 AM
You'll want a loop around the whole VI, after all that is what Run Continuously does, right? It executes all of the code over and over, except that each time is like the first time. Think of it like this, when you click Run Continuously, it's like you clicking the run button but after the code finishes execution the first time, there is an invisible mouse cursor waiting to click the run button again....and again....and again.
When you put a loop around your code, you only need to use the Run button once and provide a stop condition when you are ready for the program to exit (boolean button, loop count, etc). This allows the Mean function to function properly and maintain a running total of input values.
08-15-2017 09:41 AM
Thanks for you help. I obviously didn't realize that the run continuous button was only for debugging. I added the loop at it starting taking the average.
Can someone let me know if this:
http://digital.ni.com/public.nsf/allkb/F4BB644ECCA595D886256FFE00722E29
is the best way to find phase? I'm using the second method listed as they are square waves, but I am not getting a constant phase. There should only be a few degrees of variance between the signals, but it is jumping a lot while calculating it. It is jumping down to around -270, so it is almost like it is taking the other signal first at times to calculate the phase. Can that be caused by just not having a high enough sampling rate?
08-15-2017 10:18 AM
What does your actual signal look like? Your graphs are showing the phase difference.
08-15-2017 10:30 AM
This is the input graph of the two signals. When it graphs them it shows the phase correctly. They stay around 90 degrees.
08-15-2017 11:03 AM
It sounds like you have a synchronization issue. Since you start sampling at some random time relative to your waveforms, you could start sampling when the first waveform is already high but the second is still low. Since the Pulse Measurement defaults to using the first pulse, the second signal's pulse center will be before the first. This will give you the -270 degree phase. So you should add a check to see if your data makes sense. If the calculated phase is less than -5 degrees (assuming both are in phase and with some jitter, this is not unreasonable), then redo the pulse measurements on the second waveform using 2 for the pulse number (an input to the Pulse Measurement VI) and recalculate the phase. Or you can just add 360 to the calculated phase when it is out of range.