SciDAVis  1.D4
Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
SmoothFilter Class Reference

#include <SmoothFilter.h>

Inheritance diagram for SmoothFilter:
Filter

List of all members.

Public Types

enum  SmoothMethod { SavitzkyGolay = 1, FFT = 2, Average = 3 }

Public Member Functions

int method ()
void setMethod (int m)
void setMethod (SmoothMethod m)
void setPolynomOrder (int order)
 Sets the polynomial order in the Savitky-Golay algorithm.
void setSmoothPoints (int points, int left_points=0)
 SmoothFilter (ApplicationWindow *parent, Graph *g, const QString &curveTitle, int m=3)
 SmoothFilter (ApplicationWindow *parent, Graph *g, const QString &curveTitle, double start, double end, int m=3)
- Public Member Functions inherited from Filter
int dataSize ()
 Returns the size of the fitted data set.
bool error ()
 Filter (ApplicationWindow *parent, Table *t=0, const char *name=0)
 Filter (ApplicationWindow *parent, Graph *g=0, const char *name=0)
virtual QString legendInfo ()
 Output string added to the plot as a new legend.
virtual bool run ()
 Actually does the job. Should be reimplemented in derived classes.
void setColor (int colorId)
 Sets the color of the output fit curve.
void setColor (const QString &colorName)
 Sets the color of the output fit curve. Provided for convenience. To be used in scripts only!
virtual void setDataCurve (int curve, double start, double end)
bool setDataFromCurve (const QString &curveTitle, Graph *g=0)
bool setDataFromCurve (const QString &curveTitle, double from, double to, Graph *g=0)
void setInterval (double from, double to)
 Changes the data range if the source curve was already assigned. Provided for convenience.
void setMaximumIterations (int iter)
 Sets the maximum number of iterations to be performed during an iterative session.
void setOutputPoints (int points)
 Sets the number of points in the output curve.
void setOutputPrecision (int digits)
 Sets the precision used for the output.
void setTolerance (double eps)
 Sets the tolerance used by the GSL routines.
virtual void showLegend ()
 Adds a new legend to the plot. Calls virtual legendInfo()
 ~Filter ()

Private Member Functions

void calculateOutputData (double *x, double *y)
 Calculates the data for the output curve and store it in the X an Y vectors.
void init (int m)
void smoothAverage (double *x, double *y)
void smoothFFT (double *x, double *y)
void smoothModifiedSavGol (double *x, double *y)
 A variant of the Savitzky-Golay algorithm able to handle non-uniformly distributed data.
void smoothSavGol (double *x, double *y)
 Savitzky-Golay smoothing of (uniformly distributed) data.

Static Private Member Functions

static int savitzkyGolayCoefficients (int points, int polynom_order, gsl_matrix *h)
 Compute Savitzky-Golay coefficients and store them into #h.

Private Attributes

int d_left_points
 The number of left adjacents points used by the Savitzky-Golay algorithm.
SmoothMethod d_method
 The smooth method.
int d_polynom_order
 Polynomial order in the Savitzky-Golay algorithm.
int d_right_points
 The number of (right) adjacents points used to smooth the data set.

Additional Inherited Members

- Protected Member Functions inherited from Filter
QwtPlotCurve * addResultCurve (double *x, double *y)
 Adds the result curve to the target output plot window. Creates a hidden table and frees the input data from memory.
int curveIndex (const QString &curveTitle, Graph *g)
 Performs checks and returns the index of the source data curve if OK, -1 otherwise.
virtual bool isDataAcceptable ()
virtual QString logInfo ()
 Output string added to the log pannel of the application.
virtual void output ()
 Performs the data analysis and takes care of the output.
- Protected Attributes inherited from Filter
QwtPlotCurve * d_curve
 The curve to be analysed.
int d_curveColorIndex
 Color index of the result curve.
QString d_explanation
 String explaining the operation in the comment of the result table and in the project explorer.
double d_from
 Data interval.
Graphd_graph
 The graph where the result curve should be displayed.
bool d_init_err
 Error flag telling if something went wrong during the initialization phase.
int d_max_iterations
 Maximum number of iterations per fit.
int d_min_points
 Minimum number of data points necessary to perform the operation.
int d_n
 Size of the data arrays.
int d_points
 Number of result points to de calculated and displayed in the output curve.
int d_prec
 Precision (number of significant digits) used for the results output.
bool d_sort_data
 Specifies if the filter needs sorted data as input.
Tabled_table
 A table source of data.
double d_to
double d_tolerance
 GSL Tolerance, if ever needed...
double * d_x
 x data set to be analysed
double * d_y
 y data set to be analysed

Member Enumeration Documentation

Enumerator:
SavitzkyGolay 
FFT 
Average 

Constructor & Destructor Documentation

SmoothFilter::SmoothFilter ( ApplicationWindow parent,
Graph g,
const QString &  curveTitle,
int  m = 3 
)
SmoothFilter::SmoothFilter ( ApplicationWindow parent,
Graph g,
const QString &  curveTitle,
double  start,
double  end,
int  m = 3 
)

Member Function Documentation

void SmoothFilter::calculateOutputData ( double *  X,
double *  Y 
)
privatevirtual

Calculates the data for the output curve and store it in the X an Y vectors.

Reimplemented from Filter.

References Filter::d_explanation, d_method, Filter::d_points, d_right_points, Filter::d_x, Filter::d_y, smoothAverage(), smoothFFT(), and smoothSavGol().

void SmoothFilter::init ( int  m)
private
int SmoothFilter::method ( )
inline

References d_method.

int SmoothFilter::savitzkyGolayCoefficients ( int  points,
int  polynom_order,
gsl_matrix *  h 
)
staticprivate

Compute Savitzky-Golay coefficients and store them into #h.

This function follows GSL conventions in that it writes its result into a matrix allocated by the caller and returns a non-zero result on error.

The coefficient matrix is defined as the matrix H mapping a set of input values to the values of the polynomial of order #polynom_order which minimizes squared deviations from the input values. It is computed using the formula $H=V(V^TV)^(-1)V^T$, where $V$ is the Vandermonde matrix of the point indices.

For a short description of the mathematical background, see http://www.statistics4u.info/fundstat_eng/cc_filter_savgol_math.html

References Filter::error().

Referenced by smoothSavGol().

void SmoothFilter::setMethod ( int  m)

References Filter::d_init_err, and d_method.

Referenced by init().

void SmoothFilter::setMethod ( SmoothMethod  m)
inline

References setMethod().

Referenced by setMethod().

void SmoothFilter::setPolynomOrder ( int  order)

Sets the polynomial order in the Savitky-Golay algorithm.

References Filter::d_init_err, d_left_points, d_method, d_polynom_order, d_right_points, and SavitzkyGolay.

Referenced by SmoothCurveDialog::smooth().

void SmoothFilter::setSmoothPoints ( int  points,
int  left_points = 0 
)
void SmoothFilter::smoothAverage ( double *  x,
double *  y 
)
private

References Filter::d_n, and d_right_points.

Referenced by calculateOutputData().

void SmoothFilter::smoothFFT ( double *  x,
double *  y 
)
private

References Filter::d_n, d_right_points, and Filter::d_x.

Referenced by calculateOutputData().

void SmoothFilter::smoothModifiedSavGol ( double *  x_in,
double *  y_inout 
)
private

A variant of the Savitzky-Golay algorithm able to handle non-uniformly distributed data.

In comparison to smoothSavGol(), this method trades proper handling of the X coordinates for runtime efficiency by abandoning a central idea of Savitzky-Golay algorithm, namely that polynomial smoothing can be expressed as a convolution.

TODO: integrate this option into the GUI.

References d_left_points, Filter::d_n, d_polynom_order, d_right_points, and Filter::error().

void SmoothFilter::smoothSavGol ( double *  x,
double *  y_inout 
)
private

Savitzky-Golay smoothing of (uniformly distributed) data.

When the data is not uniformly distributed, Savitzky-Golay looses its interesting conservation properties. On the other hand, a central point of the algorithm is that for uniform data, the operation can be implemented as a convolution. This is considerably more efficient than a more generic method (see smoothModifiedSavGol()) able to handle non-uniform input data.

There are at least three possible approaches to handling edges of the data vector (cutting them off, zero padding and using the left-/rightmost smoothing polynomial for computing smoothed values near the edges). Zero-padding is a particularly bad choice for signals with a distinctly non-zero baseline and cutting off edges makes further computations on the original and smoothed signals more difficult; therefore, deviating from the user-specified number of left/right adjacent points (by smoothing over a fixed window at the edges) would be the least annoying alternative; if it were not for the fact that previous versions of SciDAVis had a different behaviour and such a subtle change to the behaviour would be even more annoying, especially between bugfix releases. TODO: reconsider issue for next minor release (also: would it help to add an "edge behaviour" option to the UI?)

References d_left_points, Filter::d_n, d_polynom_order, d_right_points, Filter::error(), and savitzkyGolayCoefficients().

Referenced by calculateOutputData().


Member Data Documentation

int SmoothFilter::d_left_points
private

The number of left adjacents points used by the Savitzky-Golay algorithm.

Referenced by init(), setPolynomOrder(), setSmoothPoints(), smoothModifiedSavGol(), and smoothSavGol().

SmoothMethod SmoothFilter::d_method
private

The smooth method.

Referenced by calculateOutputData(), method(), setMethod(), and setPolynomOrder().

int SmoothFilter::d_polynom_order
private

Polynomial order in the Savitzky-Golay algorithm.

Referenced by init(), setPolynomOrder(), setSmoothPoints(), smoothModifiedSavGol(), and smoothSavGol().

int SmoothFilter::d_right_points
private

The number of (right) adjacents points used to smooth the data set.

Referenced by calculateOutputData(), init(), setPolynomOrder(), setSmoothPoints(), smoothAverage(), smoothFFT(), smoothModifiedSavGol(), and smoothSavGol().


The documentation for this class was generated from the following files: