How do I smooth a signal without flattening its peaks?

Use the Savitzky-Golay filter smooth_golay(). Instead of averaging, UniPlot fits a small polynomial through a window of consecutive points and takes the value of the polynomial in the middle of the window. The noise is removed, but peaks keep much more of their height and width than with a moving average.

Three noisy peaks smoothed with a moving average and with a Savitzky-Golay filter

Same window width, different result: the moving average smooth(12) (orange) cuts the peaks, smooth_golay(4, 25) (blue) follows them.

How it works

  1. Click the curve in the diagram to select it.

  2. Right-click the curve, choose Edit Filter Functions…, select smooth_golay and click =>.

  3. Click Edit and set the two parameters of smooth_golay(nPolynomialOrder, nWindowSize): the order of the polynomial (1 to 10) and the number of points in the window. The window must not be larger than the number of points of the curve.

  4. Click OK.

In a script:

XYSetFilterFunctions(hData, "smooth_golay(4, 25)");

Keeping single peaks exactly

Like smooth(), the filter has an optional peak filter factor between 0 and 1 as third parameter. Original points that deviate from the smoothed curve by more than the factor times the largest deviation are put back.

Noisy signal with a short dip, smoothed with and without peak filter

Left: original signal with a short dip. Middle: smooth_golay(3, 20, 0.5) keeps the dip. Right: smooth_golay(3, 20, 0) smooths it away.

Why it helps

  • Peak values, for example maximum pressure or maximum force, stay close to the measured values after smoothing.

  • The shape of short events is preserved, so durations and rise times can still be evaluated.

  • Like all filters, it is stored in the dataset and recalculated for new data.

Good to know

  • On a slowly changing signal, the moving average and the Savitzky-Golay filter give almost the same result. The difference shows on peaks and sharp bends.

  • Isolated spikes are better removed with smooth_median first, for example smooth_median(5);smooth_golay(4, 25).