This is a pre-release version (latest).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy latest / scipy / signal / _savitzky_golay / savgol_coeffs

function

scipy.signal._savitzky_golay:savgol_coeffs

source: build-install/usr/lib/python3.14/site-packages/scipy/signal/_savitzky_golay.py:11

Signature

def savgol_coeffs(window_length, polyorder, deriv = 0, delta = 1.0, pos = None, use = conv, *, xp = None, device = None)

Summary

Compute the coefficients for a 1-D Savitzky-Golay FIR filter.

Parameters

window_length : int

The length of the filter window (i.e., the number of coefficients).

polyorder : int

The order of the polynomial used to fit the samples. polyorder must be less than window_length.

deriv : int, optional

The order of the derivative to compute. This must be a nonnegative integer. The default is 0, which means to filter the data without differentiating.

delta : float, optional

The spacing of the samples to which the filter will be applied. This is only used if deriv > 0.

pos : int or None, optional

If pos is not None, it specifies evaluation position within the window. The default is the middle of the window.

use : str, optional

Either 'conv' or 'dot'. This argument chooses the order of the coefficients. The default is 'conv', which means that the coefficients are ordered to be used in a convolution. With use='dot', the order is reversed, so the filter is applied by dotting the coefficients with the data set.

xp : array_namespace, optional

Optional array namespace. Should be compatible with the array API standard, or supported by array-api-compat. Default: numpy

device : any

optional device specification for output. Should match one of the supported device specifications in xp.

Returns

coeffs : 1-D ndarray

The filter coefficients.

Notes

Examples

import numpy as np
from scipy.signal import savgol_coeffs
savgol_coeffs(5, 2)
✓
array([-0.08571429,  0.34285714,  0.48571429,  0.34285714, -0.08571429])
savgol_coeffs(5, 2, deriv=1)
✗
array([ 2.00000000e-01,  1.00000000e-01,  2.16125056e-16, -1.00000000e-01,
       -2.00000000e-01])
Note that use='dot' simply reverses the coefficients.
savgol_coeffs(5, 2, pos=3)
savgol_coeffs(5, 2, pos=3, use='dot')
✓
array([-0.14285714,  0.17142857,  0.34285714,  0.37142857,  0.25714286])
savgol_coeffs(4, 2, pos=3, deriv=1, use='dot')
✗
array([ 0.45, -0.85, -0.65,  1.05])
`x` contains data from the parabola x = t**2, sampled at t = -1, 0, 1, 2, 3. `c` holds the coefficients that will compute the derivative at the last position. When dotted with `x` the result should be 6.
x = np.array([1, 0, 1, 4, 9])
c = savgol_coeffs(5, 2, pos=4, deriv=1, use='dot')
✓
c.dot(x)
✗
np.float64(6.00000000000001)

See also

savgol_filter

Aliases

  • scipy.signal.savgol_coeffs

Referenced by