sgolayfiltΒΆ

sgolayfilt computes a moving average using the Savitzky-Golay algorithm.

rvY2 = sgolayfilt(rvY1)
rvY2 = sgolayfilt(rvY1, p)
rvY2 = sgolayfilt(rvY1, p, nNeighbor)

Return Value

The return value rvY2 is a real vector.

Parameters

rvY1

rvX is a real vector with at least p elements.

p

Order of polynom (1 to 10, default = 3).

nNeighbor

nNeighbor specifies the window width. The window width is 2 * nNeighbor + 1. Default value = 20.

Example

../../_images/savitzky-golay.png
def test_sgolay()
{
    N = 200;
    t = linspace(0, 10, N);
    s = sin(2*PI/5*t);
    srand(1);
    sr = s + 0.3 * (rand(size(t))-0.5);
    // Sinus
    h = plot(t, s);
    XYSetProps(h[3], "curve-color='black'")
    XYSetLegendText(h[3], "sinus");
    // sin+rand
    h = plot(t, sr,  h[2]);
    XYSetProps(h[3], "curve-color='blue'")
    XYSetLegendText(h[3], "sinus+random");
    y = moving_average(sr, 10)
    h = plot(t, y,  h[2]);
    XYSetProps(h[3], "curve-color='red'")
    XYSetLegendText(h[3], "moving average (smooth())");
    // smooth(sin+rand)
    y = sgolayfilt(sr, 3, 20);
    h = plot(t, y, h[2]);
    XYSetProps(h[3], "curve-color='green'")
    XYSetLegendText(h[3], "Savitzky-Golay Filter");
}

History

Version Description
5.8.0 New

id-931091