LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Slope calculation driving me nuts

Hi all,
I have a rather odd issue that I can't seem to fix. I have a potentiometer monitoring position, from which I am attempting to derive velocity. I have smoothed out the displacement curve so it is fairly linear, yet any of the linear fit coefficients, Savitzky filters, derivatives/differentials (ptbypt or otherwise), build array methods of calculating the slope are not working for me. I've searched around and tried to base my methods off the shipping examples but to no avail. This is driving me nuts and I'm very much under the gun, so if anyone can help me overcome my own stupidity I would greatly appreciate it. The picture I've attached shows the smoothed displacement graph on the left, as well as some of the results I've gotten with derivatives. I've also attached the main program and the subvi I am using.
Thanks again!
Download All
0 Kudos
Message 1 of 18
(3,234 Views)
Derivative functions, as you have noticed, tend to exacerbate any variations in the original data.

What do you want to do with the velocity when you get it calculated? Is it being displayed to a user for general information purposes or is it being used as part of a closed loop feedback system? This can make a difference in what method(s) you may use. Another way to ask the question is, given data like that in your Data1.jpg image, what should the velocity be? The 5 seconds of smoothed LT2 data pictured have an average velocity of 0.19 mm/s, which is quite different from the Point-by-point derivative plot.

Lynn
0 Kudos
Message 2 of 18
(3,162 Views)
Lynn,
Thanks for the reply. We don't have a closed loop feedback setup, but we would like to display the average velocity (as you noted from the smoothed LT2 plot) and manually adjust a flow control valve to ensure that the velocity is consistent from test to test. I am now to the point where I can get information from the Savitsky-Golay implimentation (I don't even recall if I had incorporated it in the VI I uploaded, since I've gone through so many versions), but none of the variations on derivatives and linear fits have yielded anything close to the average obtained from the smooth LT2 plot, as you noticed with the one in the jpeg.
0 Kudos
Message 3 of 18
(3,161 Views)
What if you use linear regression (Linear Fit.vi) on the data segment of interest and just use the slope output? That should produce essentially the same result as I calculated with a straightedge from your graph.

The VI you posted was broken (datatype mismatch) and had no data. If you post a newer vesion of your VI, run it with your hardware to capture some typical data (for example in "Input Data"). Then Make Current Value Default and save the VI. The Input Data array will then have set of your data. Another option is to save the data to a spreadsheet-style text file and include a reader.

Lynn
0 Kudos
Message 4 of 18
(3,150 Views)
I've experimented with the linear fit but haven't been able to get results, as I get an error due to unequal array sizes. I haven't been able to work around it (I'm a bit of a newbie that probably isn't as good with some of the basics as I should be at this point). Sorry about attaching the wrong version of the VI. I tried saving all the default values but some of them did not work. I've attached another screen shot for your reference.
Thanks again for your time and patience.
john
0 Kudos
Message 5 of 18
(3,143 Views)
You could also try SciWare's S-G filter.  It's pretty cool, since it allows non-uniformally spaced data and gives you the smoothed derivative w/o much loss like you see in other deriv. calcs.
http://www.sciware.com.au/freesoftware/index.html
0 Kudos
Message 6 of 18
(3,143 Views)
Thank you for the idea, but I have not had much luck getting accurate results with the Sciware filter. I've experimented with the window size and polynomial order parameters but can't seem to get it to yield the correct results.
0 Kudos
Message 7 of 18
(3,138 Views)
Odd - seems to work pretty well for me even for really horrible data.
Order=1
Window=25% of data set
LV7 example attached.
Message 8 of 18
(3,130 Views)
That definitely gets me closer; I didn't try that setup for window size before. That setup is within 25-50% accurate, which is tremendous relative to what I had been achieving. I will keep playing with that some more to see if it gets me where I need to be. Thanks!
0 Kudos
Message 9 of 18
(3,118 Views)
Well, it was nice while it lasted. Regardless of window size, when I slow the test down to more reasonable speeds I am back into 100-500% error, with seemingly no rhyme or reason to the error. I figured this would be trivial once I had a relatively smooth and linear displacement curve.
0 Kudos
Message 10 of 18
(3,077 Views)