LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Phase error in vi

Solved!
Go to solution

Folks,

I have a fairly simple vi, but it is too large to post here.  I am using the Express Simulate Signal vi to generate four sine waves plus a tach signal.  The signals pass through the Express Trigger and Gate vi, then through an Express Bandpass Filter.  Finally, I pull the phase information out what will be the incoming signal, once the vi is running with a DAQmx input, using the 'Extract Single Channel Tone Information' vi to get the magnitude and phase of the fundamental frequency.  The phase is exactly 60 degees less then my original phase inputs.  I changed one of the Simulate Signal vi's phase and the result was exactly the same, 60 degrees less.  Question is, what part of my vi is imparting this 60 degree error?  My guess is the bandpass filter.  Any suggestions?

0 Kudos
Message 1 of 17
(3,361 Views)

I answered my own question, it is indeed the band pass filter.  So, now the question is, how can filter my incoming 'real word' signal, when the time comes, without inducing phase error with a band pass filter?

Regards, 

Ron

0 Kudos
Message 2 of 17
(3,356 Views)

Consider a filter that tries to remove "noise" from "signal" (usually by supressing the higher frequencies).  So what do you know at time "t"?  You know the signal at that time and at earlier times.  A common method of "smoothing" is to average the signal (which amounts to integrating it over some interval going backward in time).  Because you are using information that already occurred, this "going back in time" produces the phase lag that you observe.  When one speaks of a "phase lag", the usual model is a sine wave, whose integral is a cosine wave, delayed (shifted to the right on the time axis) by 90°.

 

You can build digital filters that are phase-less, but you have to cheat -- you need to use future data in constructing your filter (which you can do by sampling the data and averaging both before and after the time point) -- the only RC circuits that know how to do this kind of "future" filterings used the capacitors in the "Back to the Future" car, not yet invented.

 

Bob Schor

Message 3 of 17
(3,332 Views)

I found this vi on a thread on this board for a zero phase shift filter by James.  I took from his vi what I needed for a bandpass filter.  What am I missing?!  This filter isn't even in the ball park.  If it gave me the correct phase, I would work around the magnitude error, but the phase isn't even correct.

Download All
0 Kudos
Message 4 of 17
(3,303 Views)

Hi Coryman,

 

I had a chance to look at your post. Just to get some context of your problem, you are trying to create a bandpass filter with modified code (from user James). From the VIs I see posted they appear identical. What is the difference between these two VIs? What graphical output are you expecting with this filtering?

 

Most importantly, did the original VI you found perform as expected when run?

Jacob C.
Applications Engineering
National Instruments
0 Kudos
Message 5 of 17
(3,283 Views)

Jacob,

My apologies.  Here is the vi by James.  My point was that there was a large phase shift (29 degrees) in the response, yet the filter is touted as 'zero phase shift'.   i took from his vi what I needed to provide filtering to a sine wave.  Since there was also loss of 90% of the magnitude, I am assuming there is supposed to be a correction factor applied?

0 Kudos
Message 6 of 17
(3,278 Views)

You will understand a lot more once you have taken a class in Signal Theory and understand some basic concepts, such as Time-Domain vs Frequency-Domain analysis, the meaning of "Signal" and "Noise" (particularly from the viewpoint of the Frequency Domain), and Finite vs Infinite Signal Analysis.

 

Let me give you a Simple Lesson -- consider a 10Hz Sine Wave with 0 phase offset that you sample at 1kHz.  Each cycle will be represented by 100 values, namely sin(2 pi t / 100) where time "t" is measured in milliseconds (since we are sampling at 1kHz).  As t goes from 0 to 25 to 50 to 75 to 100, the sinusoid goes from 0 to 1 to 0 to -1 to 0.

 

Now add "noise", say a random number in the range -1 to 1, to each data point.  Plot that -- what a mess!  You can hardly see the sinusoid.  [Incidentally, it is really simple to write some LabVIEW code to do these calculations "by hand", though there are functions that "do all the work for you".  However, for a beginner, learning where to find the Sin function (look in the Mathematics Palette -- if you can't see it, push the little button at the bottom of the Palette List and the hidden Palettes will appear).  You can find "2 pi" on the Numeric Palette under Math Constants.  Try plotting a 100-point sinusoid, then plot 100-point (sinusoid + noise).]

 

So how to clean this up?  Here's an idea -- let's replace each point of the sinusoid with the average of three points, our point, the point to the left, and the point to the right.  The "Signal" (Sinusoid) will be a little "flattened" by this procedure (in most places, the center point will be larger, or smaller, than its neighbors, but the difference will be small), while the "random noise" will devolve towards its mean value of 0, and be much more attenuated than the signal.  Hey, you just "invented" a "Low-Pass Filter", so-called because low frequency "Signals" (your Sinusoid can be considered to have Frequency 1, as it varies by 1 cycle over the 100 points) are little affected by the Filter, whereas higher-frequency "Noise" gets attenuated, or "filtered out".

 

This "filter" has one other property that's important to note.  If I have an infinite signal, then I can look at my data point, points before it (which I've already sampled), and points after it (which I have not yet sampled).  But since I'm "filtering as I go", I can only deal with the data I already have, namely my data point and its predecessors.  But now consider our three-point average -- I can't center it on the current point, since I don't (yet) have the "next" point, so I use the current point and the two preceding points.  This, however, gives me the "improved Signal" at the previous point, i.e. it introduces a time shift, which is equivalent to a phase lag.  Aha, so that's where it comes from ...

 

Do some (numerical) experimentation.  If you've got some resistors and capacitors, an oscilloscope and a function generator, you can also do some "electrical" experimentation.  You can easily build a low-pass filter out of a resistor in series with a capacitor -- the product RC is called the "time-constant" of the filter, and 1/RC is called the "corner frequency".  If you built your filter correctly, you'll see the frequencies above 1/RC are more than half-way attenuated, and have phase lags > 45°, whereas frequencies below 1/RC show less attenuation and smaller phase lags.

 

Thought problem -- assuming you could "predict the future" and use the next point in your 3-point filter, could you eliminate the Phase Lag?  Would this also eliminate the filter's attenuation?  [Don't know?  Do the (numerical) Experiment!]

 

Bob "It's Only Math" Schor

Message 7 of 17
(3,271 Views)

Bob,

You are correct.  My background is in digital signal processing, but all on the digital side and mostly fft analysis of rotating machinery.  I used to teach seminars on digital signal processing.  I know, for example the windows used to prevent leakage from not having the time signal start and end at zero amplitude, so using a hanning window would ensure that, but it also had a gain to account for the attenuation of the signal due to the window.

It wasn't until I was at the point in my vi to vectorially subtract the slow roll orbit from the 'at speed' orbit that I figured I had better go back and check my phase and magnitudes to see what I had saved.  There I discovered the bandpass filter (Express) was introducing a 50 degree lag in all of my phase readings.  What was interesting, is that the phase lag was consistent no matter what the frequency or the initial phase or magnitude.  Also, the magnitude was not attenuated at all.  It looked like a simple case of adding 50 degrees to the phase readings, but without knowing why that's just bad coding.  

So, here is sit, looking at plenty of forum input that talks about zero phase filtering and yet none of them accomplish it.

Ron

0 Kudos
Message 8 of 17
(3,254 Views)
Solution
Accepted by topic author Coryman

common ways to overcome the phase lag of a filter in a phase measurement:

 

  • Since you usually measure a phase in relation to another signal, just apply the filter on both signals and measure the difference.
  • If you know the phase lag you can correct it. 
  • For a finit number of samples (no 'real' time) filter twice, the second time reversed . Phase lags cancel out and/but the filter order is know 2 times the original order.

 

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 9 of 17
(3,238 Views)

Henrik,

Yes, that was my thought on why a 50 degree subtraction put all of the phases where they I initially were before filtering!  I will pass the tach through the same filter and that will be my check.  Thank you.  I'll give you Kudos when I'm on my computer.  Phone won't let me.

0 Kudos
Message 10 of 17
(3,233 Views)