scipy 1.8.0 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
savgol_filter(x, window_length, polyorder, deriv=0, delta=1.0, axis=-1, mode='interp', cval=0.0)

This is a 1-D filter. If x has dimension greater than 1, :None:None:`axis` determines the axis along which the filter is applied.

Notes

Details on the :None:None:`mode` options:

'mirror':

Repeats the values at the edges in reverse order. The value closest to the edge is not included.

'nearest':

The extension contains the nearest input value.

'constant':

The extension contains the value given by the :None:None:`cval` argument.

'wrap':

The extension contains the values from the other end of the array.

For example, if the input is [1, 2, 3, 4, 5, 6, 7, 8], and :None:None:`window_length` is 7, the following shows the extended data for the various :None:None:`mode` options (assuming :None:None:`cval` is 0):

mode       |   Ext   |         Input          |   Ext
-----------+---------+------------------------+---------
'mirror'   | 4  3  2 | 1  2  3  4  5  6  7  8 | 7  6  5
'nearest'  | 1  1  1 | 1  2  3  4  5  6  7  8 | 8  8  8
'constant' | 0  0  0 | 1  2  3  4  5  6  7  8 | 0  0  0
'wrap'     | 6  7  8 | 1  2  3  4  5  6  7  8 | 1  2  3
versionadded

Parameters

x : array_like

The data to be filtered. If x is not a single or double precision floating point array, it will be converted to type numpy.float64 before filtering.

window_length : int

The length of the filter window (i.e., the number of coefficients). If :None:None:`mode` is 'interp', :None:None:`window_length` must be less than or equal to the size of x.

polyorder : int

The order of the polynomial used to fit the samples. :None:None:`polyorder` must be less than :None:None:`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. Default is 1.0.

axis : int, optional

The axis of the array x along which the filter is to be applied. Default is -1.

mode : str, optional

Must be 'mirror', 'constant', 'nearest', 'wrap' or 'interp'. This determines the type of extension to use for the padded signal to which the filter is applied. When :None:None:`mode` is 'constant', the padding value is given by :None:None:`cval`. See the Notes for more details on 'mirror', 'constant', 'wrap', and 'nearest'. When the 'interp' mode is selected (the default), no extension is used. Instead, a degree :None:None:`polyorder` polynomial is fit to the last :None:None:`window_length` values of the edges, and this polynomial is used to evaluate the last :None:None:`window_length // 2` output values.

cval : scalar, optional

Value to fill past the edges of the input if :None:None:`mode` is 'constant'. Default is 0.0.

Returns

y : ndarray, same shape as `x`

The filtered data.

Apply a Savitzky-Golay filter to an array.

See Also

savgol_coeffs

Examples

>>> from scipy.signal import savgol_filter
... np.set_printoptions(precision=2) # For compact display.
... x = np.array([2, 2, 5, 2, 1, 0, 1, 4, 9])

Filter with a window length of 5 and a degree 2 polynomial. Use the defaults for all other parameters.

>>> savgol_filter(x, 5, 2)
array([1.66, 3.17, 3.54, 2.86, 0.66, 0.17, 1.  , 4.  , 9.  ])

Note that the last five values in x are samples of a parabola, so when mode='interp' (the default) is used with polyorder=2, the last three values are unchanged. Compare that to, for example, :None:None:`mode='nearest'`:

>>> savgol_filter(x, 5, 2, mode='nearest')
array([1.74, 3.03, 3.54, 2.86, 0.66, 0.17, 1.  , 4.6 , 7.97])
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

scipy.signal._signaltools.lfilter scipy.signal._savitzky_golay.savgol_coeffs scipy.signal._signaltools.filtfilt scipy.signal._savitzky_golay.savgol_filter

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /scipy/signal/_savitzky_golay.py#230
type: <class 'function'>
Commit: