1 /***************************************************************************
2     File                 : SmoothFilter.h
3     Project              : QtiPlot
4     --------------------------------------------------------------------
5     Copyright            : (C) 2007 by Ion Vasilief
6     Email (use @ for *)  : ion_vasilief*yahoo.fr
7     Description          : Numerical smoothing of data sets
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  *                                                                         *
13  *  This program is free software; you can redistribute it and/or modify   *
14  *  it under the terms of the GNU General Public License as published by   *
15  *  the Free Software Foundation; either version 2 of the License, or      *
16  *  (at your option) any later version.                                    *
17  *                                                                         *
18  *  This program is distributed in the hope that it will be useful,        *
19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
21  *  GNU General Public License for more details.                           *
22  *                                                                         *
23  *   You should have received a copy of the GNU General Public License     *
24  *   along with this program; if not, write to the Free Software           *
25  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
26  *   Boston, MA  02110-1301  USA                                           *
27  *                                                                         *
28  ***************************************************************************/
29 #ifndef SMOOTHFILTER_H
30 #define SMOOTHFILTER_H
31 
32 #include "Filter.h"
33 #include <gsl/gsl_matrix_double.h>
34 
35 class SmoothFilter : public Filter
36 {
37 Q_OBJECT
38 
39 public:
40 	SmoothFilter(ApplicationWindow *parent, QwtPlotCurve *c, int m = 3);
41 	SmoothFilter(ApplicationWindow *parent, QwtPlotCurve *c, double start, double end, int m = 3);
42 	SmoothFilter(ApplicationWindow *parent, Graph *g, const QString& curveTitle, int m = 3);
43 	SmoothFilter(ApplicationWindow *parent, Graph *g, const QString& curveTitle, double start, double end, int m = 3);
44 	SmoothFilter(ApplicationWindow *parent, Table *t, const QString& xCol, const QString& yCol, int start = 0, int end = -1, int m = 3);
45 
46     enum SmoothMethod{SavitzkyGolay = 1, FFT = 2, Average = 3, Lowess = 4};
47 
method()48     int method(){return (int)d_method;};
49     void setMethod(int m);
50 
51     void setSmoothPoints(int points, int left_points = 0);
52     //! Sets the polynomial order in the Savitky-Golay algorithm.
53     void setPolynomOrder(int order);
54     void setLowessParameter(double f, int iterations);
55 
56 private:
57     void init(int m);
58     void calculateOutputData(double *x, double *y);
59     void smoothFFT(double *x, double *y);
60     void smoothAverage(double *x, double *y);
61     void smoothSavGol(double *x, double *y);
62     void smoothLowess(double *x, double *y);
63 	static int savitzkyGolayCoefficients(int points, int polynom_order, gsl_matrix *h);
64 
65     //! The smooth method.
66     SmoothMethod d_method;
67 
68     //! The number of adjacents points used to smooth the data set.
69     int d_smooth_points;
70 
71     //! The number of left adjacents points used by the Savitky-Golay algorithm.
72     int d_sav_gol_points;
73 
74     //! Polynomial order in the Savitky-Golay algorithm (see Numerical Receipes in C for details).
75     int d_polynom_order;
76 
77     //! Parameter f for the Lowess algorithm
78     double d_f;
79 
80     //! Number of iterations for the Lowess algorithm
81     int d_iterations;
82 };
83 
84 #endif
85