savgolmat
Returns the Savitzky-Golay filter coefficients as a 2-D array.
savgolmat computes the same coefficients that savgol uses, but returns them instead of filtering a signal. It gives all the derivatives at once, so the kernels can be inspected, plotted, or applied to data with other opcodes.
Syntax
Initialization
iwinsize -- the number of samples in the window. It must be odd and at least 3.
iorder -- the degree of the fitted polynomial, from 0 to iwinsize - 1.
idelta (optional, default 1) -- the spacing between two samples. Row d of the result is scaled by 1 / ideltad, so with the default of 1 the derivatives are per sample. It must be greater than 0.
imat -- an array of iorder + 1 rows and iwinsize columns. Row d holds the coefficients that give the d-th derivative of the fitted polynomial at the centre of the window, already multiplied by d!. Row 0 is the smoothing kernel. The columns go from the oldest sample of the window to the newest.
The dot product of row d with iwinsize consecutive samples gives what savgol outputs with ideriv = d for that window. Even rows are symmetric and odd rows are antisymmetric.
Invalid values cause an initialization error.
Examples
This example prints the kernels for a window of 5 samples and order 2. Row 0 is the classic [-3, 12, 17, 12, -3] / 35 smoothing kernel. It then applies each row to five samples of a parabola and recovers its value, slope and curvature at the centre. It uses the file savgolmat.csd.
Its output is:
row 0: [ -3 12 17 12 -3] / 35
row 1: [ -2 -1 0 1 2] / 10
row 2: [ 2 -1 -2 -1 2] / 7
derivative 0 at the centre: 9
derivative 1 at the centre: 6
derivative 2 at the centre: 2
See also
Credits
Author: Pasquale Mainolfi
Italy
New in Csound version 7.0
October 2026