Function File: f = sgolay (p, n)
Function File: f = sgolay (p, n, m)
Function File: f = sgolay (p, n, m, ts)

Computes the filter coefficients for all Savitzsky-Golay smoothing filters of order p for length n (odd). m can be used in order to get directly the mth derivative. In this case, ts is a scaling factor.

The early rows of F smooth based on future values and later rows smooth based on past values, with the middle row using half future and half past. In particular, you can use row i to estimate x(k) based on the i-1 preceding values and the n-i following values of x values as y(k) = F(i,:) * x(k-i+1:k+n-i).

Normally, you would apply the first (n-1)/2 rows to the first k points of the vector, the last k rows to the last k points of the vector and middle row to the remainder, but for example if you were running on a realtime system where you wanted to smooth based on the all the data collected up to the current time, with a lag of five samples, you could apply just the filter on row n-5 to your window of length n each time you added a new sample.

Reference: Numerical recipes in C. p 650

See also: sgolayfilt.

Package: signal