LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I find slope of a waveform

Sounds like you could us a Savitzky-Golay filter. Check out a copy of Numerical Recipes in C, 2nd edition from your local library and read up on the techniques. Then check out this discussion thread for some LabVIEW code.

http://forums.ni.com/ni/board/message?board.id=170&message.id=102065
0 Kudos
Message 11 of 18
(1,716 Views)
Gray, Thanks!

I checked the other thread and downloaded both; your .llb and Sciware's VIs

The Sciware demo makes me believe this is what I am looking for.
However, there is too much complexity and I am not into this kind of coding.

So, can you help me filter out only the relevant VI?

My objective is simple: I have X and Y data. X is equally spaced and Y could be anything.
I need to smooth Y without any change in number of X points or their values.
Also, I need to give the user a control which can be used to decide how much to smooth.

Another small question: How can I activate Y-scale to appear on both sides of the graph?

Looking forward to your help.

Best,
Gurdas
Gurdas Sandhu, Ph.D.
ORISE Research Fellow at US EPA
0 Kudos
Message 12 of 18
(1,706 Views)
Mike,

Are you human? My wife sometimes claims that I am an alien from another planet.

When I took a more careful look today I see that I made an error in rushing. Here is the corrected statement:

Start is in units of samples.
The time t(Start) is the time the beginning of the Waveform Subset.
The time t is i=dt where i is the iteration counter and dt is the waveform time increment.

At x=0, t = t(Start) = Start * dt

The modified intercept B is B = b - m*dt*Start
The line in the t-coordinate system is given by

z = m*t + B
= m*t + b - m*dt*Start
= m*dt*(i - Start) + b

The attached VI includes this correction and plots the regression line with the original data.

Lynn
0 Kudos
Message 13 of 18
(1,851 Views)
Lyyne:
I started from scratch and I think this vi is doing the sdame thing. Instead of using the waveforem suset lib vi I just seperated the Y array directly.
I just found the slope and intercept from the specific range then substituted them into a waveform and appended.
I think it's ok, can you take a look and see if it makes sense?
Thanks,
Mike
0 Kudos
Message 14 of 18
(1,844 Views)
Ok Lynn:
You win, the 4th vi looks like what I want, I still don't understand it but with your blessing I will use it.
Much Thanks,
Mike
0 Kudos
Message 15 of 18
(1,684 Views)
It looks OK. The only thing I saw was that the slope is different. If you multiply the X-array into the Linear Fit VI by dt, then the slope becomes the same as in the earlier versions.

Lynn
0 Kudos
Message 16 of 18
(1,677 Views)
Question 1 - How do you use a Savitzky-Golay filter and not lose points at the ends of the data
The Savitzky-Golay algorithm is a convolution algorithm, so it will reduce the number of points available by the width of the filter. However, there are two good options for dealing with this, one trivial, the other difficult.
  1. Trivial - take more data than you need and toss the extra points when you are finished with the convolution. This is what I have always done. If you use the code I posted, it will take a 5 to 19 point filter width (less to more filtering). You will need to toss (n-1)/2 points from each end, where n is the filter width.

  2. Difficult - If you have no control over the number of points and you need to preserve it, you will need to generate several Savitzky-Golay filters (requires coding the Savitzky-Golay algorithm - code I posted is a look-up table). The Savitzky-Golay filter is the mathematical equivalent of taking the points in the filter width, calculating a least-squares polynomial fit to them, then using the fit to calculate the value of the point of interest in the curve. Normally, the point of interest is the center point in the filter. To fill in the edges, you need to calculate the Savitzky-Golay coefficients for a point not in the center of the filter width. Of course, since you are only using these filters once, it would probably be more efficient to use a standard polynomial least squares fit. The results will be identical (barring weird algorithm round-off error issues).
Take home message. Use S-G Operation.vi to filter your data. If you can, take more data than you need and toss the ends after the filter. If you can't take more data, use General Polynomial Fit.vi to calculate the quadradic or cubic fits then back calculate the value using standard formulae for each of the end points. I have not looked at the Sciware code. It may already do this for you.

Question 2 - How do you get a Y-axis graph on both sides of a LabVIEW graph
These instructions are for LabVIEW 7.1. I have not checked them for other versions.
  1. Pop up on the existing Y-axis scale and select Duplicate Scale. You should now have two scales on the left of your graph.

  2. Pop up on the newly created scale and select Swap Sides. You will now have a scale on both ends of your graph.
However, there is a caveat. Data in a LabVIEW graph is associated with one and only one scale. As such, the new scale will not autoscale with data, since it is not associated with any data. If you want this behavior, it is easiest to turn autoscale off both axes and do the scaling yourself. Alternately, you can write data to the graph, read the autoscaled values from one scale (use graph property node) and write them to the other. I have not tried this. You may need a delay between the data write and the read of the autoscaled axes parameters to allow the autoscale to occur.
Message 17 of 18
(1,662 Views)

Hi,

I have a velocity waveform that has multiple peaks on it, i need to find the acceleration from this graph:-

My idea is:- (min value(0) - max value(first peak)) / (t1(corresponding to min value) -(t2(corresponding to peak value))).

but problem is how to find t1 and t1 peak value for a continuous acquiring data ?

can i get some vi which i can try.  

Arpit
0 Kudos
Message 18 of 18
(271 Views)