Hampel - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


SignalProcessing

  

Hampel

  

apply the Hampel filter to a 1-D signal to remove outliers

 

Calling Sequence

Parameters

Options

Description

Examples

Compatibility

Calling Sequence

Hampel( signal )

Hampel( signal, radius )

Hampel( signal, radius, numstddevs )

Parameters

signal

-

1-D rtable or list of data.

radius

-

(optional) positive integer which defines the radius, in number of sample points, of each window used to determine if a point is an outlier. The default is 3.

numstddevs

-

(optional) positive numeric value which specifies the number of standard deviations a sample point must be within the median to not be considered an outlier. The default is 3.0.

Options

• 

output : The type of output. The supported options are:

– 

hampelsignal: 1-D Array or Vector of the Hampel-filtered signal. This is the default.

– 

medians: 1-D Array or Vector containing the medians for each sample point of the original signal.

– 

outliers: Vector containing the indices for the outlier sample points of the original signal.

– 

standarddeviations: 1-D Array or Vector containing the standard deviations for each sample point of the original signal.

– 

record: Returns a record with the previous options.

– 

list of any of the above options (excluding record): Returns an expression sequence with the corresponding outputs, in the same order.

Description

• 

The Hampel command takes a 1-D data set, and replaces outlier sample points with the median value with respect to neighboring points.

• 

To determine if a given sample point, say with index i, is an outlier, a window of neighboring points is considered:

1. 

Define the window to be the points signal[max(a,i-r)..min(b,i+r)], where a and b are, respectively, the lower and upper indices of signal, and r=radius.

2. 

Compute the median mu and median absolute deviation mad of the window.

3. 

Approximate the standard deviation of the window as sigma=rho*mad, where rho=-1/sqrt(2)/inverfc(3/2) and inverfc() is the inverse of the complementary error function. The value of rho is approximately 1.483.

4. 

If abs(signal[i]-mu)>numstddevs*sigma, that is, the sample point is more than numstddevs standard deviations from the median, the point is labeled an outlier.

• 

The filtered signal is formed by taking the original signal, and replacing the outliers their respective medians.

• 

Maple will attempt to coerce the provided signal to a 1-D Array or Vector of float[8] datatype, and an error will be thrown if this is not possible. For this reason, it is most efficient for the input to already be a float[8] 1-D Array or Vector.

• 

The input signal cannot have an indexing function, and must use rectangular storage.

• 

The Hampel command is not thread safe.

Examples

withSignalProcessing:

Example 1

A5,5,10,5,5,0,5,5

A5,5,10,5,5,0,5,5

(1)

BHampelA,1,0.5,output=hampelsignal,outliers

B5.5.5.5.5.5.5.5.,36

(2)

Example 2

• 

Consider the following signal:

n51:

XVectorn,i5+cos4πi1n1,datatype=float8

• 

To this, add outliers:

YcopyX:

Y3X3+4.0:

Yfloorn2Xfloorn2+2.5:

Y2X23.0:

Y=Y

• 

Now, compute the Hampel-filtered signal Z of X with, say, radius of 3 sample points and 2.0 standard deviations. Here, we return the full record:

HHampelY,3,2.0,output=record

• 

For the plot, we require only the filtered signal:

ZArrayTools:-AliasHhampelsignal:

• 

Finally, plot all three signals:

dataplotX,Y,Z,view=1..n,0..10,labels=time,amplitude,title=Signals,font=Verdana,15,legend=original signal,original signal with outliers,filtered signal,legendstyle=font=Verdana,15,symbolsize=5,color=green,red,blue,thickness=6,3,3

Compatibility

• 

The SignalProcessing[Hampel] command was introduced in Maple 2021.

• 

For more information on Maple 2021 changes, see Updates in Maple 2021.

See Also

ArrayTools

dataplot

erfc

SignalProcessing