Polybench® for biosignals / reference 1.34.1
Implements the Savitzky-Golay smoothing FIR filter

Savitzky Golay Filter

Overview

Savitzky-Golay smoothing FIR filters (also known as least-squares smoothing filters or polynomial smoothing filters) are generally used for smoothing and differentiation.

The zeroth differentiation filters are typically used to smooth the data, i.e. to increase the signal-to-noise ratio without greatly distorting the signal. The higher differentiation filters are used for differentiating a signal, without amplifying (high-frequency) noise.

Operator ports

Input S: Floating point values

Output SG(S): Floating point values

Properties

Find more information about changing properties here: "Properties Viewer"

WindowInTime
type: See description
The moving window size in seconds (minimal window size is the duration of three sample intervals)

Because the window size must be an odd number of samples, the size is automatically adjusted. See RealWindowInTime for the corrected window size.

WindowInSamples
type: Integer value
The moving window size as number of samples. Must be a positive, odd number. The window size must be at least 3 samples and at least one more than the polynomial degree.


PolynomialDegree
type: Integer value
The polynomial degree used for the linear least-squares fitting. Must be at least 1, and at least one less than the window size, and at least one more than the derivative.

The Savitzky-Golay filter uses a linear least squares method in order to fit a polynomial on the data points in the selected window. It follows that the lower the polynomial, the less precize the data points can be described, and the more the fitted data points will be smoothed. That is an intended effect, because that also reduces noise.

It would not make sense to choose a very high polynomial, because that makes the signal-to-noise ratio worse.

On the other hand, the polynomial must of course be at least one more than the order of derivative that is required.

Derivative
type: Integer value
Derivative order of the output. If set to 0, the input signal will be smoothed. If set to 1, the output will be the smoothed, first derivative of the input; 2 is the second derivative, etc.


OutputConversion
type: Select from the list
Select if the output is a differential (no time scaling) or the derivative (with time scaling).
Select one of those presets:
Differential
The operator's output is the differential; this means the values are not time scaled.
Derivative
The operator's output is the derivative, so that the unit contains a time component (it is time scaled).


NumberFormat
type: See description
Specifies the format in which the window setting and the differentiation vector values are displayed (default ;3 for 3 digits after dot or comma)

More information about number formatting can be found here: "Number format codes".

RealWindowInTime
type: See description [this value cannot be changed]
The moving window length as calculated by the system, expressed in seconds


Caption
type: Word or phrase
The name of the object in the project. This name must not contain '.', '$' nor '@' characters.

For more information about the rules and usage of the Caption property, please refer to "Caption property - background and usage".

Documentation
type: See description
Optional documentation of this object. If this object is an operator, the Documentation text is displayed below the operator symbol.

Variable Parameters

Find more information about Variable Parameters here: "Variable Parameters"

WindowInSamples
type: See description
The moving window size as number of samples. Must be a positive, odd number. The window size must be at least 3 samples and at least one more than the polynomial order.

If a window size with an even number is specified, then the window size is increased by one automatically.

WindowInTime
type: See description
The moving window size in seconds (minimal window size is the duration of one sample interval)


RealWindowInTime
type: See description [this value cannot be changed]
The moving window as calculated by the system, expressed in seconds


PolynomialDegree
type: See description
The polynomial degree used for the linear least-squares fitting. Must be at least 1, and at least one less than the window size, and at least one more than the derivative.

See the PolynomialDegree property for more information.

Derivative
type: See description
Derivative order of the output. If set to 0, the input signal will be smoothed. If set to 1, the output will be the smoothed, first derivative of the input; 2 is the second derivative, etc.


DifferentiationVector
type: Parameter list (see "Parameter List")
Differentiation filter vector (column in G-matrix that is used for the specified derivative).

Note that if you add up all values in the vector, that the outcome is 1.

Details

Example of usage: smoothing

The picture below shows how a noisy sinus signal is being smoothed. First, a noise signal is added to a sinus. Then the signal is lead through the Savitzky-Golay filter, that is using a window of 21 samples and a polynomial degree of 2.
In order to depict the original signal and the smoothed signal overlayed, the original signal has to be delayed by one half of the window time.



The next picture shows the difference between a naive differentiation, and the first derivative using Savitzky-Golay, for a noisy sinus. The naive method just subtracts the previous sample from the current, and then scales with a time factor in order to get the derivative from the differential.
The result is shown in blue. It is expected that the first derivative of a sinus is a cosinus. In the picture it can be seen that the result is a sinusoid, but it is very noisy.
Now, using the Savitzky-Golay to get the first derivative (settings: window is 21 samples, polynomial is 2 and derivative is 1), shown in red, it can be seen that the result is much smoother. Note that this signal lags one half of the window size behind.



How to interpret the settings of the Savitzky-Golay filter

In general one can say that the higher the polynomial degree is chosen, the better the filter can predict higher frequency noise, and the less smooth the result will be. Note that to get the Nth derivative, the polynomial degree should be at least N+1.
A polynomial degree of 1 will result in smoothing equal to what the Averager operator ("Averager") does.

The size of the window has an effect on the smoothness. The larger the window, the more samples are part of the equation, and the stronger the smoothing effect will be.

Start-up behavior

Since the filter is calculated for the specified window size, after starting up, the window will not be completely filled with samples, thus causing noise at the output. Because the signals analyzed are assumed to have a physiological origin, not having strong fluctuations in a short time span, we thought it to be least disruptive if the window is filled with the value of the first incoming sample.

Efficiency

This filter does not require much calculation power when running signals through it. To calculate the filter parameters internally, some calculation power is required, but this is being done only once before the filter is applied. For larger window and polynomial degree settings, the calculation power for getting the filter parameters strongly increases.

Literature

The next references describe the background of this filter in more detail:

- Savitzky, A. and Golay M.J.E. (1964) Smoothing and differentiation of data by simplified least squares procedures. Analytical Chemistry, 36(8): 1627-1964

- Orfanidis, S.J. (1996) Introduction to Signal Processing. Englewood Cliffs, NJ: Prentice-Hall