QtiPlot  0.9.8.2
Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
SmoothFilter Class Reference

#include <SmoothFilter.h>

Inheritance diagram for SmoothFilter:
Filter

Public Types

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

Public Member Functions

int method ()
 
void setLowessParameter (double f, int iterations)
 
void setMethod (int m)
 
void setPolynomOrder (int order)
 Sets the polynomial order in the Savitky-Golay algorithm. More...
 
void setSmoothPoints (int points, int left_points=0)
 
 SmoothFilter (ApplicationWindow *parent, QwtPlotCurve *c, int m=3)
 
 SmoothFilter (ApplicationWindow *parent, QwtPlotCurve *c, double start, double end, int m=3)
 
 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)
 
 SmoothFilter (ApplicationWindow *parent, Table *t, const QString &xCol, const QString &yCol, int start=0, int end=-1, int m=3)
 
- Public Member Functions inherited from Filter
int dataSize ()
 Returns the size of the input data set. More...
 
virtual void enableGraphicsDisplay (bool on=true, Graph *g=0)
 
bool error ()
 
 Filter (ApplicationWindow *parent, Table *t=0, const QString &name=QString())
 
 Filter (ApplicationWindow *parent, Graph *g=0, const QString &name=QString())
 
 Filter (ApplicationWindow *parent, Matrix *m, const QString &name=QString())
 
 Filter (ApplicationWindow *parent, QwtPlotCurve *c)
 
virtual QString legendInfo ()
 Output string added to the plot as a new legend. More...
 
GraphoutputGraph ()
 Returns a pointer to the graph where the result curve should be displayed. More...
 
QwtPlotCurve * resultCurve ()
 Returns a pointer to the plot curve created to display the results. More...
 
TableresultTable ()
 Returns a pointer to the table created to display the results. More...
 
virtual bool run ()
 Actually does the job. Should be reimplemented in derived classes. More...
 
void setColor (int colorId)
 Obsolete: sets the color of the output fit curve. More...
 
void setColor (const QColor &color)
 Sets the color of the output fit curve. More...
 
void setColor (const QString &colorName)
 Sets the color of the output fit curve. Provided for convenience. To be used in scripts only! More...
 
virtual void setDataCurve (QwtPlotCurve *curve, double start, double end)
 
bool setDataFromCurve (QwtPlotCurve *c)
 
bool setDataFromCurve (QwtPlotCurve *c, double from, double to)
 
bool setDataFromCurve (const QString &curveTitle, Graph *g=0)
 
bool setDataFromCurve (const QString &curveTitle, double from, double to, Graph *g=0)
 
virtual bool setDataFromTable (Table *, const QString &, const QString &, int=1, int=-1, bool=false)
 
void setError (bool on=true)
 
void setInterval (double from, double to)
 Changes the data range if the source curve was already assigned. Provided for convenience. More...
 
void setMaximumIterations (int iter)
 Sets the maximum number of iterations to be performed during an iterative session. More...
 
void setOutputPoints (int points)
 Sets the number of points in the output curve. More...
 
void setOutputPrecision (int digits)
 Sets the precision used for the output. More...
 
void setSortData (bool on=true)
 
void setTolerance (double eps)
 Sets the tolerance used by the GSL routines. More...
 
void setUpdateOutputGraph (bool update=true)
 
virtual void showLegend ()
 Adds a new legend to the plot. Calls virtual legendInfo() More...
 
double * x ()
 Returns the x values of the input data set. More...
 
double * y ()
 Returns the y values of the input data set. More...
 
 ~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. More...
 
void init (int m)
 
void smoothAverage (double *x, double *y)
 
void smoothFFT (double *x, double *y)
 
void smoothLowess (double *x, double *y)
 
void smoothSavGol (double *x, double *y)
 Savitzky-Golay smoothing of (uniformly distributed) data. More...
 

Static Private Member Functions

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

Private Attributes

double d_f
 Parameter f for the Lowess algorithm. More...
 
int d_iterations
 Number of iterations for the Lowess algorithm. More...
 
SmoothMethod d_method
 The smooth method. More...
 
int d_polynom_order
 Polynomial order in the Savitky-Golay algorithm (see Numerical Receipes in C for details). More...
 
int d_sav_gol_points
 The number of left adjacents points used by the Savitky-Golay algorithm. More...
 
int d_smooth_points
 The number of adjacents points used to smooth the data set. More...
 

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. More...
 
MultiLayercreateOutputGraph ()
 
virtual int curveData (QwtPlotCurve *c, double start, double end, double **x, double **y)
 
int curveIndex (const QString &curveTitle, Graph *g)
 Performs checks and returns the index of the source data curve if OK, -1 otherwise. More...
 
int curveRange (QwtPlotCurve *c, double start, double end, int *iStart, int *iEnd)
 
virtual void freeMemory ()
 Frees the memory allocated for the X and Y data sets. More...
 
void init ()
 
virtual QString logInfo ()
 Output string added to the log pannel of the application. More...
 
void memoryErrorMessage ()
 
virtual void output ()
 Performs the data analysis and takes care of the output. More...
 
virtual int sortedCurveData (QwtPlotCurve *c, double start, double end, double **x, double **y)
 Same as curveData, but sorts the points by their x value. More...
 
- Protected Attributes inherited from Filter
QwtPlotCurve * d_curve
 The curve to be analysed. More...
 
QColor d_curveColor
 Color index of the result curve. More...
 
QString d_explanation
 String explaining the operation in the comment of the result table and in the project explorer. More...
 
double d_from
 Data interval. More...
 
Graphd_graph
 The source graph with the curve to be analyzed. More...
 
bool d_graphics_display
 Specifies if the filter should display a result curve. More...
 
bool d_init_err
 Error flag telling if something went wrong during the initialization phase. More...
 
Matrixd_matrix
 
int d_max_iterations
 Maximum number of iterations per fit. More...
 
int d_min_points
 Minimum number of data points necessary to perform the operation. More...
 
int d_n
 Size of the data arrays. More...
 
Graphd_output_graph
 The graph where the result curve should be displayed. More...
 
int d_points
 Number of result points to de calculated and displayed in the output curve. More...
 
int d_prec
 Precision (number of significant digits) used for the results output. More...
 
QwtPlotCurve * d_result_curve
 The resulting curve. More...
 
Tabled_result_table
 The table displaying the results of the filtering operation (not alvays valid!) More...
 
bool d_sort_data
 Specifies if the filter needs sorted data as input. More...
 
Tabled_table
 A table source of data. More...
 
double d_to
 
double d_tolerance
 GSL Tolerance, if ever needed... More...
 
bool d_update_output_graph
 Specifies if the filter should update the output graph. More...
 
double * d_x
 x data set to be analysed More...
 
double * d_y
 y data set to be analysed More...
 
QString d_y_col_name
 

Member Enumeration Documentation

◆ SmoothMethod

Enumerator
SavitzkyGolay 
FFT 
Average 
Lowess 

Constructor & Destructor Documentation

◆ SmoothFilter() [1/5]

SmoothFilter::SmoothFilter ( ApplicationWindow parent,
QwtPlotCurve *  c,
int  m = 3 
)

◆ SmoothFilter() [2/5]

SmoothFilter::SmoothFilter ( ApplicationWindow parent,
QwtPlotCurve *  c,
double  start,
double  end,
int  m = 3 
)

◆ SmoothFilter() [3/5]

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

◆ SmoothFilter() [4/5]

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

◆ SmoothFilter() [5/5]

SmoothFilter::SmoothFilter ( ApplicationWindow parent,
Table t,
const QString &  xCol,
const QString &  yCol,
int  start = 0,
int  end = -1,
int  m = 3 
)

Member Function Documentation

◆ calculateOutputData()

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_f, d_iterations, d_method, Filter::d_points, d_smooth_points, Filter::d_x, Filter::d_y, smoothAverage(), smoothFFT(), smoothLowess(), and smoothSavGol().

Referenced by method().

◆ init()

void SmoothFilter::init ( int  m)
private

◆ method()

int SmoothFilter::method ( )
inline

◆ savitzkyGolayCoefficients()

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 method(), and smoothSavGol().

◆ setLowessParameter()

void SmoothFilter::setLowessParameter ( double  f,
int  iterations 
)

◆ setMethod()

void SmoothFilter::setMethod ( int  m)

References Filter::d_init_err, and d_method.

Referenced by init(), and method().

◆ setPolynomOrder()

void SmoothFilter::setPolynomOrder ( int  order)

Sets the polynomial order in the Savitky-Golay algorithm.

References Filter::d_init_err, d_method, d_polynom_order, d_sav_gol_points, d_smooth_points, and SavitzkyGolay.

Referenced by method(), and SmoothCurveDialog::smooth().

◆ setSmoothPoints()

void SmoothFilter::setSmoothPoints ( int  points,
int  left_points = 0 
)

◆ smoothAverage()

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

References Filter::d_n, and d_smooth_points.

Referenced by calculateOutputData(), and method().

◆ smoothFFT()

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

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

Referenced by calculateOutputData(), and method().

◆ smoothLowess()

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

References clowess(), d_f, d_iterations, and Filter::d_n.

Referenced by calculateOutputData(), and method().

◆ smoothSavGol()

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.

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;

References Filter::d_init_err, Filter::d_n, d_polynom_order, d_sav_gol_points, d_smooth_points, Filter::error(), Filter::memoryErrorMessage(), and savitzkyGolayCoefficients().

Referenced by calculateOutputData(), and method().

Member Data Documentation

◆ d_f

double SmoothFilter::d_f
private

Parameter f for the Lowess algorithm.

Referenced by calculateOutputData(), setLowessParameter(), and smoothLowess().

◆ d_iterations

int SmoothFilter::d_iterations
private

Number of iterations for the Lowess algorithm.

Referenced by calculateOutputData(), setLowessParameter(), and smoothLowess().

◆ d_method

SmoothMethod SmoothFilter::d_method
private

◆ d_polynom_order

int SmoothFilter::d_polynom_order
private

Polynomial order in the Savitky-Golay algorithm (see Numerical Receipes in C for details).

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

◆ d_sav_gol_points

int SmoothFilter::d_sav_gol_points
private

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

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

◆ d_smooth_points

int SmoothFilter::d_smooth_points
private

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

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


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