# Numerical issues in scipy's Savitzky Golay filter coefficients for large polynomial order

Consider the design of a Savitzky-Golay filter of window length 101 and (high) polynomial order 20. Using scipy version 1.10.1, the filter coefficients can be obtained in python as:

from scipy import signal
h = signal.savgol_coeffs(window_length=101, polyorder=20) For reference, in Matlab r2022b

order=20; framelen=101; b = sgolay(order,framelen); h = b((framelen+1)/2,:);


which looks more reasonable. For lower order polynomials, the results coincide much more closely.

It looks like scipy's implementation solves a least squares problem where the design matrix is computed as:

 order = np.arange(polyorder + 1).reshape(-1, 1)
A = x ** order


leading to a condition number > 1e29!

Is there some other way to get these coefficients in python?

• Do you need to compute these at run-time? If not, you could simply store the Matlab-computed coefficients in a file and use these in your Python application
– Jdip
Aug 8 at 9:25
• Indeed, that's the approach that I've wound up taking.
– rhz
Aug 8 at 16:25

The trick here will be tweaking the ratio between $$\boldsymbol{Q}$$ and $$\boldsymbol{R}$$ to have similar results.