Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
Public Member Functions | Protected Member Functions | Protected Attributes

SavitzkyGolayFilter Class Reference
[SignalProcessing]

Computes the Savitzky-Golay filter coefficients using QR decomposition. More...

#include <OpenMS/FILTERING/SMOOTHING/SavitzkyGolayFilter.h>

Inheritance diagram for SavitzkyGolayFilter:
ProgressLogger DefaultParamHandler

List of all members.

Public Member Functions

 SavitzkyGolayFilter ()
 Constructor.
virtual ~SavitzkyGolayFilter ()
 Destructor.
template<typename PeakType >
void filter (MSSpectrum< PeakType > &spectrum)
 Removed the noise from an MSSpectrum containing profile data.
template<typename PeakType >
void filterExperiment (MSExperiment< PeakType > &map)
 Removed the noise from an MSExperiment containing profile data.

Protected Member Functions

virtual void updateMembers_ ()
 This method is used to update extra member variables at the end of the setParameters() method.

Protected Attributes

std::vector< DoubleRealcoeffs_
 Coefficients.
UInt frame_size_
 UInt of the filter kernel (number of pre-tabulated coefficients).
UInt order_
 The order of the smoothing polynomial.

Detailed Description

Computes the Savitzky-Golay filter coefficients using QR decomposition.

This class represents a Savitzky-Golay lowpass-filter. The idea of the Savitzky-Golay filter is to find filtercoefficients that preserve higher moments, which means to approximate the underlying function within the moving window by a polynomial of higher order (typically quadratic or quartic). Therefore we least-squares fit for each data point a polynomial to all points $ f_i $ in the window and set $g_i$ to be the value of that polynomial at position $ i $. This method is superior to adjacent averaging because it tends to preserve features of the data such as peak height and width, which are usually 'washed out' by adjacent averaging.

Because of the linearity of the problem, we can reduce the work computing by fitting in advance, for fictious data consisiting of all zeros except for a singe 1 and then do the fits on the real data just by taking linear combinations. There are a particular sets of filter coefficients $ c_n $ which accomplish the process of polynomial least-squares fit inside a moving window. To get the symmetric coefficient-matrix $C \in R^{frameSize \times frameSize}$ with

\[ C= \left[ \begin{array}{cccc} c_{0,0} & c_{0,1} & \cdots & c_{0,frameSize-1} \\ \vdots & & & \vdots \\ c_{frameSize-1,0} & c_{frameSize-1,2} & \ldots & c_{frameSize-1,frameSize-1} \end{array} \right]\]

The first (last) $ \frac{frameSize}{2} $ rows of $ C $ we need to smooth the first (last) $ frameSize $ data points of the signal. So we use for the smoothing of the first data point the data point itself and the next $ frameSize-1 $ future points. For the second point we take the first datapoint, the data point itself and $ frameSize-2 $ of rightward data points... . We compute the Matrix $ C $ by solving the underlying least-squares problems with the singular value decomposition. Here we demonstrate the computation of the first row of a coefficient-matrix $ C $ for a Savitzky-Golay Filter of order=3 and frameSize=5: The design-matrix for the least-squares fit of a linear combination of 3 basis functions to 5 data points is:

\[ A=\left[ \begin{array}{ccc} x_0^0 & x_0^1 & x_0^2 \\ \\ x_1^0 & x_1^1 & x_1^2 \\ \\ x_2^0 & x_2^1 & x_2^2 \\ \\ x_3^0 & x_3^1 & x_3^2 \\ \\ x_4^0 & x_4^1 & x_4^2 \end{array} \right]. \]

To smooth the first data point we have to create a design-matrix with $ x=[0,\ldots, frameSize-1] $. Now we have to solve the over-determined set of $ frameSize $ linear equations

\[ Ac=b \]

where $ b=[1,0,\ldots,0] $ represents the fictious data. Therefore we solve the normal equations of the least-squares problem

\[ A^TAc=A^Tb. \]

Now, it is possible to get

\[ c_n=\sum_{m=0}^8 \{(A^TA)^{-1}\}_{0,m} n^m, \]

with $ 0\le n \le 8$. Because we only need one row of the inverse matrix, it is possible to use LU decomposition with only a single backsubstitution. The vector $c=[c_0,\ldots,c_8] $ represents the wanted coefficients. Note that the solution of a least-squares problem directly from the normal equations is faster than the singular value decomposition but rather susceptible to roundoff error!

Note:
This filter works only for uniform profile data! A polynom order of 4 is recommended. The bigger the frame size the smoother the signal (the more detail information get lost!). The frame size corresponds to the number of filter coefficients, so the width of the smoothing intervall is given by frame_size*spacing of the profile data.
The data must be sorted according to ascending m/z!
Parameters of this class are:

NameTypeDefaultRestrictionsDescription
frame_length int11  The number of subsequent data points used for smoothing.
This number has to be uneven. If it is not, 1 will be added.
polynomial_order int4  Order or the polynomial that is fitted.

Note:

Constructor & Destructor Documentation

Constructor.

virtual ~SavitzkyGolayFilter (  )  [virtual]

Destructor.


Member Function Documentation

void filter ( MSSpectrum< PeakType > &  spectrum  )  [inline]

Removed the noise from an MSSpectrum containing profile data.

void filterExperiment ( MSExperiment< PeakType > &  map  )  [inline]

Removed the noise from an MSExperiment containing profile data.

virtual void updateMembers_ (  )  [protected, virtual]

This method is used to update extra member variables at the end of the setParameters() method.

Also call it at the end of the derived classes' copy constructor and assignment operator.

The default implementation is empty.

Reimplemented from DefaultParamHandler.


Member Data Documentation

std::vector<DoubleReal> coeffs_ [protected]

Coefficients.

UInt frame_size_ [protected]

UInt of the filter kernel (number of pre-tabulated coefficients).

UInt order_ [protected]

The order of the smoothing polynomial.


OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:53 using doxygen 1.7.1