From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

First and second derivative of a signal by using splines

Dear LabView users, I need to calculate first and second derivatives of a signal (experimental data acquired in function of time).

I ask you to confirm to me, that the piecewise polynomial as given by the Spline Interpolation 1D VI contains the coefficients of the polynomial 

a(x-xi)^3 + b(x-xi)^2 + c(x-xi) + d

and not the coefficient of the polynomial

ax^3 + bx^2 + cx + d

 

If so, c and 2b should be, respectively, the first and the second derivatives evaluated at the current point xi. 

 

Please, let me know if I am right. 

0 Kudos
Message 1 of 9
(4,151 Views)

I have used the Savitsky-Golay filter to calculate derivatives. It is based on fitting a polynomial to a segment of the data and determining the derivative from the polynomial.  The Detailed Help for the Savitsky-Golay Filter Coefficients.vi shows how to get the derivatives.

 

Because it is calculating derivatives of polynomials rather than derivatives of noisy data, it does not have the issues of emphasis of the noise that the standard numerical differentiation does.

 

Lynn

Message 2 of 9
(4,125 Views)

Thank you. I am going to check. Unfortunately, the method that I wanted to use, (the splines piecewise polynomial) is really too slow. 

0 Kudos
Message 3 of 9
(4,099 Views)

Savitsky-Golay can be slow, too. You can tune it by the choice of polyomial order and the number of sidepoints. Keep both as low as will give good results on your data. The polynomial order must be one higher than the derivative (I think). So for second derivatives you need third order polynomials (cubic).

 

Lynn

Message 4 of 9
(4,092 Views)

I, too, prefer the Savitzky-Golay method of determining derivatives. The standard LabVIEW derivative function, Derivative x(t) never uses more than four points and defaults to two for any given derivative. This makes it very noise sensitive, especially since you need to run it twice to get a second derivative. Savitzky-Golay allows you to use as many points as you wish, allowing you to tune speed vs. noise immunity. It also allows you to directly calculate the second derivative.

 

When you pick the number of points, you need to specify one more than the derivative order you are trying to calculate. However, this minimum number of points will give you maximum noise. The polynomial order should be equal or greater than the derivative you are trying to calculate. I would probably start with a second order polynomial and either five or seven points centered on the point of interest and tune as needed.

 

There is a very good writeup of Savitzky-Golay techniques in Numerical Recipes (section 14.8).

 

Let us know if you need more help.

Message 5 of 9
(4,074 Views)

Hi, I started to check the Savitzky-Golay vi's. Unfortunately, I found them very difficult to use for my needs (that is to extract the derivatives).  I want to ask you if the vi's supplied in the labview palette can be used with non-uniformly data (that is my case xi=xi(ti), where the times ti are not equally spaced: I need the derivatives in the points ti). 

 

0 Kudos
Message 6 of 9
(4,035 Views)

The Savitsky-Golay VIs all use simple arrays as data inputs and they have no timing information inputs which means that they assume uniformly sampled data.

 

This puts you back to interpolation which returns you to your original question. Sorry for the detour. 

 

Lynn

Message 7 of 9
(4,025 Views)

Savitzky-Golay is essentially a mathematical trick to allow you to do a least squares fit by running a convolution. You may be able to apply the trick, even with unevenly spaced data, but you will need to work out the math yourself. Check out the Numerical Recipes link I referenced above. You will need to look at the least squares fitting chapters, as well. Good luck!

Message 8 of 9
(4,003 Views)

Thank you all of you. I have solved my problem by fitting myself with a polynomial in the spirit of Savitzky-Golay method, that is by taking a running window of data, 

0 Kudos
Message 9 of 9
(3,968 Views)