Click or drag to resize

WhittakerHendersonSmoother Class

A simple C# implementation of Whittaker-Henderson smoothing for data at equally spaced points, popularized by P. H. C. Eilers in "A Perfect Smoother", Anal. Chem. 75, 3631 (2003).
C#
It minimizes
sum(f - y)^2 + sum(lambda* f'(p))
where y are the data, f are the smoothed data, and f'(p) is the p-th
derivative of the smoothed function evaluated numerically. In other
words, the filter imposes a penalty on the p-th derivative of the
data, which is taken as a measure of non-smoothness.
Smoothing increases with increasing value of lambda.

The current implementation works up to p = 5; usually one should use
p = 2 or 3.

For points far from the boundaries of the data series, the frequency
response of the smoother is given by

   1/(1+lambda* (2-2* cos(omega))^2p);

where n is the order of the penalized derivative and
omega = 2 * pi * f / fs, with fs being the sampling frequency
(reciprocal of the distance between the data points).

Note that strong smoothing leads to numerical noise (which is smoothed
similarly to the input data, thus not obvious in the output).
For lambda = 1e9, the noise is about 1e-6 times the magnitude of the
data. Since higher p values require a higher value of lambda for
the same extent of smoothing (the same bandwidth), numerical noise
is increasingly bothersome for large p, but not for p <= 2.
Inheritance Hierarchy
SystemObject
  Altaxo.Calc.RegressionWhittakerHendersonSmoother

Namespace: Altaxo.Calc.Regression
Assembly: AltaxoCore (in AltaxoCore.dll) Version: 4.8.3448.0 (4.8.3448.0)
Syntax
C#
public class WhittakerHendersonSmoother

The WhittakerHendersonSmoother type exposes the following members.

Constructors
 NameDescription
Public methodWhittakerHendersonSmoother Creates a WhittakerHendersonSmoother for data of a given length and with a given penalty order and smoothing parameter lambda. This constructor is useful for repeated smoothing operations with the same parameters and data sets of the same length. Otherwise, the static Smooth(Double, Int32, Double) method is more convenient.
Top
Methods
 NameDescription
Public methodStatic memberBandwidthToLambda Calculates the smoothing parameter lambda for a given penalty derivative order and desired bandwidth (the frequency where the response decreases to -3 dB, i.e. 1/sqrt(2)). This bandwidth is valid for points far from the boundaries of the data.
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Public methodStatic memberNoiseGainToLambda Calculates an approximation of the smoothing parameter lambda for a given white-noise gain. This is valid for points far from the boundaries of the data; the noise gain is much higher near the boundaries.
Public methodStatic memberSavitzkyGolayBandwidth Calculates the bandwidth of a traditional Savitzky-Golay (SG) filter.
Public methodSmooth(Double, Double) Smooths the data with the parameters passed to the constructor.
Public methodStatic memberSmooth(Double, Int32, Double) Smooths the data with the given penalty order and smoothing parameter lambda. When smoothing multiple data sets with the same length, using the constructor and then Smooth(Double, Double) will be more efficient.
Public methodStatic memberSmoothLikeSavitzkyGolay Smooths the data in a way comparable to a traditional Savitzky-Golay filter with the given parameters degree and m.
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Top
Fields
 NameDescription
Public fieldStatic memberMAX_ORDER The maximum supported penalty derivative order (p).
Top
Remarks
Reference: Michael Schmid, David Rath, and Ulrike Diebold, "Why and how Savitzky-Golay filters should be replaced", ACS Measurement Science Au 2022 2 (2), 185–196. DOI: 10.1021/acsmeasuresciau.1c00054.
C#
Implementation notes:

Storage of symmetric or triangular band-diagonal matrices:
For a symmetric band-diagonal matrix with bandwidth 2 m - 1
we store only the lower right side in b:

b(0, i)   are diagonal elements a(i, i)
b(1, i)   are elements a(i+1, i)
    ...
b(m-1, i) are bottommost (leftmost) elements a(i+m-1, i)

where i runs from 0 to n-1 for b(0, i) and 0 to n - m for the
further elements at a distance of m from the diagonal.

A lower triangular band matrix is stored exactly the same way.
See Also