# Savitzky-Golay filter parameters

I am trying to smooth a series of data in order to obtain a continuous function that could represent that given data set. It came out that the Savitzky-Golay method could be a good way.

Now, I don't know much about smoothing and/or interpolate, but I managed to obtain a good result, at a first glance: The blue points are my data, and the red line is the result from a SG filter applied with a window = 15 and a polynomial order = 13. Now, I could try some other combinations of window&order, but more generally I would like to know the principles of the best meeting of these two parameters, especially in my case, where the data have no smooth trend (like a sinusoidal).

Let's call the window length $M$, and $N$ is the order of the polynomial. One important thing to realize is that you use a polynomial of order $N$ to approximate $M$ data points. This means that you use $M$ points to compute $N+1$ polynomial coefficients (an $N^{th}$ order polynomial has $N+1$ coefficients). So if $N+1=M$ then you do not smooth at all but you just use the polynomial to interpolate the data points. In your example this is almost the case, i.e. there is hardly any smoothing. Generally, $N$ is chosen considerably smaller than $M$ to achieve some smoothing (and also for numerical stability). The smaller $N$ compared to $M$, the more smoothing you will get. What remains is the choice of $M$, but as far as I know there are no general guidelines. In practical examples I've seen polynomial orders of $4$ or $5$ with much larger values for $M$. With all this in mind it remains to try several combinations of $M$ and $N$ and choose the one that fits best your application.
• Indeed, I can obtain the same result with a polynomial order much smaller $\sim 5$, but with a window size $<13$ otherwise the smoothed model become too unrepresentative of the features of the original pattern. What do you mean by considerably smaller? Is it included in the number I have just posted? – Py-ser Apr 16 '14 at 5:51
• @Py-ser Yes, the window size is often chosen more than a factor 2 greater than the polynomial order. How much of a difference between $N$ and $M$ is desired, depends on the data and the amount of desired smoothing. – Matt L. Apr 16 '14 at 6:56