Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use Savitzky-Golay smooth coefficient to calculate derivatives

Savitzky-Golay smoothing filter can be used to calculate the coefficients so as to calculate the smoothed y-values by applying the coefficients to the adjacent values. The smoothed curve looks great.

According to the papers, the coefficients can also be used to calculate the derivatives up to 5th order. The coefficients calculation parameter ld would need to be set to the order of derivatives. For the first derivative, the appropriate setting is ld=1, and the value of the derivative is the accumulated sum divided by the sampling interval h.

My question is: how to use the obtained coefficients to calculate the accumulated sum? how is the derivative calculated? any sample code?

like image 321
Lin Song Yang Avatar asked Aug 26 '10 00:08

Lin Song Yang


1 Answers

To calculate the derivatives using Savitzky-Golay smoothing filter, the polynomial coefficients computation has a parameter b, the value b[derivative] must be set to 1.0, the array be will be used in the LU decomposition call.

The key to get derivatives right is to understand the polynomial formula: Y = a0 + a1 * z + a2 * z^2 + ... + ak * z^k. The values a0, a1, a2, ..., ak are actually the smoothed values within the moving window, z = (x - x0) / h, for the centre point of the moving window, we can assume z = 0 since x = x0.

Therefore, in the derivative calculations:

dY/dx = a1/h; and d2Y/dx2 = 2a2/h^2.

Where a1, a2 are the smoothed values of y by using the coefficients calculated on the corresponding derivatives.

like image 166
Lin Song Yang Avatar answered Nov 15 '22 08:11

Lin Song Yang