DigitalFilter.h
00001
00002
00003
00004
00005
00006
00007
00008 #ifndef DigitalFilter_H_
00009 #define DigitalFilter_H_
00010
00011 #include <list>
00012 #include <vector>
00013 #include <ostream>
00014 #include "PassiveTimer.h"
00015
00016 class DigitalFilter
00017 {
00018 public:
00019 DigitalFilter ( unsigned int bufsize=5, double T=0, double lsq=0.2,
00020 int iir_thr=10000, double iir_coeff_prev=0.5,
00021 double iir_coeff_new=0.5 );
00022 ~DigitalFilter ();
00023
00024
00025 void setSettings( unsigned int bufsize, double T, double lsq,
00026 int iir_thr, double iir_coeff_prev, double iir_coeff_new );
00027
00028
00029
00030
00031
00032 int filter1( int newValue );
00033
00034
00035 int filterRC( int newVal );
00036
00037
00038 int median( int newval );
00039
00040
00041 int leastsqr( int newval );
00042
00043
00044 int filterIIR( int newval );
00045
00046
00047 int current1();
00048 int currentRC();
00049 int currentMedian();
00050 int currentLS();
00051 int currentIIR();
00052
00053
00054 void add( int newValue );
00055
00056 void init( int val );
00057
00058
00059
00060 inline int size(){ return buf.size(); }
00061
00062 inline double middle(){ return M; }
00063 inline double sko(){ return S; }
00064
00065 friend std::ostream& operator<<(std::ostream& os, const DigitalFilter& d);
00066 friend std::ostream& operator<<(std::ostream& os, const DigitalFilter* d);
00067
00068 private:
00069
00070
00071 double firstLevel();
00072
00073 double secondLevel( double val );
00074
00075 double Ti;
00076 double val;
00077 double M;
00078 double S;
00079 PassiveTimer tmr;
00080
00081 typedef std::list<int> FIFOBuffer;
00082 FIFOBuffer buf;
00083 unsigned int maxsize;
00084
00085 typedef std::vector<int> MedianVector;
00086 MedianVector mvec;
00087
00088 typedef std::vector<double> Coeff;
00089 Coeff w;
00090
00091 double lsparam;
00092 double ls;
00093
00094 int thr;
00095 int prev;
00096
00097
00098 double coeff_prev;
00099 double coeff_new;
00100 };
00101
00102 #endif // DigitalFilter_H_
00103