Gaplad › Free tools & guides › Despike a time series

Free tool · runs in your browser

Despike a time series with a Hampel filter.

Spikes are single bad readings: a loose connection, a bird on the sensor, a radio glitch. They wreck means, maxima and every model trained on them. Find them with a Hampel filter, check each one, and download the cleaned record.

Drop a CSV or Excel file here

Read in this browser tab. Nothing is uploaded. One timestamp column (or Year/Month/Day columns) and any number of value columns.

Paste data instead

How the Hampel filter decides

For each reading xi, take the observations in a window around it (half the window each side, gaps skipped). Compute their median m and the median absolute deviation MAD = median(|x − m|). Scaled by 1.4826, the MAD estimates the standard deviation of normal data while ignoring outliers. The reading is a spike when

|xi − m| > t × 1.4826 × MAD

Where the window is so quantised that the MAD is zero (a sensor that steps in whole units), the filter falls back to an upper percentile of the deviations so real spikes still stand out, and a perfectly flat window is skipped rather than flagging every tiny change.

Why not a moving average or a 3-sigma rule?

A spike inflates the mean and the standard deviation of its own window, so the very reading you want to catch raises the bar it is measured against. The median and MAD barely move. That robustness is the whole point of the Hampel filter and why it is the standard first pass for logger data.

Spikes are not the only problem

Error codes, frozen sensors and re-installed sensors need different detectors. The free QC check runs all of them at once.

Questions

What is a Hampel filter?

A moving-window outlier detector. For each reading it takes the median of the surrounding window and the median absolute deviation (MAD) of that window. A reading more than t × 1.4826 × MAD away from the median is called a spike. Medians are not dragged around by the spike itself, which is why the Hampel filter works where a moving average or a standard-deviation rule fails.

Which window and threshold should I use?

Start with the defaults (12 observations, 5 sigmas), which were tuned on real logger data to rarely flag a true event. Lower the threshold to 3 to catch smaller spikes at the risk of clipping real peaks. Widen the window if spikes come in bursts of two or three readings; keep it short if your signal changes quickly.

Should I replace spikes with the median or leave them blank?

Leave them blank if anything downstream will fill gaps or compute statistics: a blank is honest about what you do not know. Replacing with the local median is the textbook Hampel filter and gives a continuous series, but the replaced values look like measurements, so keep the flag column.

Will it remove real peaks, like a flood or a pollution episode?

It can, if the event is only one or two readings wide relative to the window. Click any spike in the table to zoom in and check it before you accept it. The threshold is conservative by default for that reason.

Despiked? Now fill the holes honestly

Blanked spikes are gaps, and so are the dropouts that were already there. Gaplad fills them with whichever method wins on your own data, and flags every filled value.

Open Gaplad, free How to choose a method