smoothdata

Smooths noisy data with a chosen method.

Category: Data Import and Analysis > Preprocessing Data

Syntax

B = smoothdata(A)

Smooths with a moving average whose window is chosen automatically.

B = smoothdata(A, method, wlen)

Uses method with a window of wlen elements.

Description

smoothdata collects the usual smoothers behind one interface. 'movmean' averages inside the window; 'movmedian' takes the median and keeps edges; 'gaussian' is a weighted average whose weights follow a bell curve, so nearby points count more; 'sgolay' fits a low-degree polynomial in each window and preserves peaks better.

A longer window removes more noise at the price of flattening real features.

Input arguments

A
Numeric vector or matrix (columns are smoothed).
method
'movmean', 'movmedian', 'gaussian' or 'sgolay'.
wlen
Window length.

Output arguments

B
Smoothed array of the same size as A.

Example

Mean versus median

x = [1 5 2 8 3];
smoothdata(x, 'movmean', 3)
smoothdata(x, 'movmedian', 3)
Output
ans = 1×5

    3.0000    2.6667    5.0000    4.3333    5.5000
ans = 1×5

    3.0000    2.0000    5.0000    3.0000    5.5000

See also

movmean movmedian smoothdata2 filter