Wednesday, May 8, 2019

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: enter image description here 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).



Answer



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.


No comments:

Post a Comment

digital communications - Understanding the Matched Filter

I have a question about matched filtering. Does the matched filter maximise the SNR at the moment of decision only? As far as I understand, ...