sgolaydiff.m

From Spinach Documentation Wiki
Jump to: navigation, search

Savitzky-Golay differentiation of noisy sampled signals by local least-squares polynomial fitting.

A window of npoints consecutive samples is placed around each sample of the signal; the window is centred on the sample in the interior of the array and slides to the nearest fully contained position at the two ends, so the fits are sided there. The local sample offsets are referred to the current sample and divided by their largest absolute value, a Vandermonde matrix of the scaled offsets is built up to poly_order, and the local polynomial coefficients are obtained for all M signals at once by QR-backed least squares. The requested derivative at the expansion point is then factorial(der_order) times the coefficient of the corresponding power, divided by the scaling factor raised to der_order. The independent variable is the sample index, so the result refers to a unit sampling step.

Syntax

    dy=sgolaydiff(y,der_order,npoints,poly_order)

Parameters

    y          - N-by-M signal matrix; rows are samples and
                 columns are independent signals

    der_order  - derivative order; order 0 returns the
                 smoothed signal

    npoints    - odd number of points in the local least-
                 squares window

    poly_order - order of the local polynomial

Outputs

    dy         - N-by-M derivative matrix on a unit-step
                 uniform grid

Notes

sgolaydiff(s,1,7,3) is recommended for differentiating EPR spectra; use a tight integration tolerance and increase the number of field/frequency axis points.

The window length must be odd and must not exceed the number of samples, the derivative order must not exceed the polynomial order, and the polynomial order must be smaller than the window length.

See also

fftdiff.m, fourdif.m, pseudomodulation.m, apodisation.m, Kernel utilities

Version 2.13, authors: Ilya Kuprov