One of the new functions in the MATLAB Signal Processing toolbox for R2015b is the Hampel Filter. It appears to be used for outlier removal and from the examples, it looks like it might do a better job than a median filter.

Unfortunately, as of yet there appears to be no readily available digestible description of the filter (such as a Wikipedia page).

So, what is a Hampel Filter? How does it work? How computationally expensive is it? When does it work well? When does it not work so well?


The documentation clearly describes its function: "For each sample of x, the function computes the median of a window composed of the sample and its six surrounding samples, three per side. It also estimates the standard deviation of each sample about its window median using the median absolute deviation. If a sample differs from the median by more than three standard deviations, it is replaced with the median."

The $3\sigma$ rule is enforced via the estimator $\sigma \approx 1.4826\ \operatorname{MAD}$.

The most costly operation must be the median of seven elements, possibly achieved by sorting, which can be performed efficiently in a sliding window.

Possibly relevant reference: "Hampel F. R., ”The influence curve and its role in robust estimation,” Journal of the American Statistical Association, 69, 382–393, 1974."

  • 1
    $\begingroup$ Is this the universal definition of the filter? A window of 6 surrounding samples sounds arbitrary - is there a reason why this is chosen? $\endgroup$ – Damien Oct 21 '15 at 7:52
  • $\begingroup$ Rephrase: is the parameter selection merely empirical, or is there a theoretical basis to its selection? $\endgroup$ – Damien Oct 21 '15 at 8:14
  • $\begingroup$ No idea. Probably a compromise between accuracy of the estimator vs. geometric stationarity of the signal. $\endgroup$ – Yves Daoust Oct 21 '15 at 8:19
  • 2
    $\begingroup$ @Damien The window size depends on your data. It's not necessarily fixed at 6. $\endgroup$ – ddzzbbwwmm Jan 19 '18 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.