hampel

Remove outliers using a Hampel filter.

Syntax

h = hampel(x)

h = hampel(x,k)

h = hampel(x,k,sigma)

h = hampel(x,k,sigma,'usenan')

Inputs

x
The data sample. For matrix inputs the filter is applied to the first non-singleton dimension.
Type: double
Dimension: vector | matrix
k
The number of samples used in the moving window analysis. (default: 6)
For even values, the number will be split between the left and right sides of each sample. For odd values the number will be centered with respect to each sample.
Type: integer
Dimension: scalar
sigma
The number of standard deviations from the moving median used to identify outliers. (default: 3)
Type: double
Dimension: scalar
'usenan'
Use this flag to replace outliers by NaN values. Otherwise, outliers are replaced by moving median values.
Type: string

Outputs

h
The hampel filtered results.
Dimension: vector | matrix

Example

x = [1,2,3,4,8,-4,9,-3,-2,-1,9,3,4,2,0];
y = hampel(x,[],[],'usenan')
y = [Matrix] 1 x 15
1  2  3  4  8  -4  9  -3  -2  -1  NaN  3  4  2  0

Comments

The moving standard deviation is approximated from the moving median absolute deviation from the median, assuming normally distributed deviations.