06-12-2011 08:48 PM
Hi;
In my controller implementation for a remotely-operated undrerwater vehicle for an academic research, I am trying to implement Savitzky-Golay filter to take the derivative of fairly noisy position data coming from a depth sensor(see the example graph of data coming in) in order to obtain the velocities ON THE FLY. To do that, first, I initiliaze an array of size 2k+1, and then each time depth data double value arrives, I am deleting the zero-indexed element from this array and put the new data point to the end of the array to move the data window for the Savitzk-Golay block. The final array is carried over to the next iteration through the shift register.
However, when I implement this filter, I am obtaining positive velocity values when I expect negative values or vice versa. Given this, I am wondering if there is anyone out there who could be kind enough to tell me if I am using the Savitzky-Golay derivatives correctly. Also is my method to move the data window correct? I attached the picture of the LabVIEW code that does the on the fy filtering.
Kind Regards,
06-13-2011 05:28 AM
I can't see anything wrong with your implementation of the SG filter (except that you should consider using the "Savitzky Golay Filter PtByPt.vi" which is intended for this kind of real-time use), but I wonder if SG is the best for your application. The velocity you get from your VI is an estimate of the velocity at the middle of your 2k+1 data-point array (ie. k intervals in the past), rather than the best estimate of velocity at the time of most recent reading. With very noisy data you will have to use quite a large value of k to get a meaningful value, and thus will be controlling your vehicle with outdated velocity values. You might be better off with a filter that is designed to provide an estimate of current velocity, such as an exponentially-weighted moving average.
-- James