5

Is there a way to incorporate the uncertainties on my data set into the result of the Savitzky Golay fit? Since I am not passing this information into the function, I asume that it is simply calcuating the 'best fit' via an unweighted least-squares process. I am currently working with data that has non-uniform uncertainty, and so the fit of the data could be improved by including the errors that I have for my main dataset.

The wikipedia page for the Savitzky-Golay filter suggests how I might go about alter the process of calculating the coefficients of the fit, and I am staring at the code for scipy.signal.savgol_filter, but I cannot get my head around what I need to adjust so that this will do what I want it to.

Are there any ready-made weighted SG filters floating about? I find it hard to believe that no-one else has ever needed this tool in Python, but maybe I have missed something.

RobG
  • 51
  • 2

1 Answers1

1

Check out this Python module: https://github.com/surhudm/savitzky_golay_with_errors

This python script improves upon the traditional Savitzky-Golay filter by accounting for errors or covariance in the data. The inputs and arguments are all modelled after scipy.signal.savgol_filter


Matlab function sgolayfilt supports weights. Check the documentation.

Nirmal
  • 1,285
  • 2
  • 13
  • 23