InstantTunningEstimator.hxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef InstantTunningEstimator_hxx
00023 #define InstantTunningEstimator_hxx
00024 #include <list>
00025 #include <vector>
00026 #include <cmath>
00027
00028 namespace Simac
00029 {
00030
00040 class InstantTunningEstimator
00041 {
00042 public:
00043 typedef std::vector<std::pair<double, double> > PeakList;
00044 private:
00045 double _fasorX;
00046 double _fasorY;
00047 double _instantX;
00048 double _instantY;
00049 double _inertia;
00050 public:
00051 InstantTunningEstimator(double inertia=0.0)
00052 : _inertia(inertia)
00053 {
00054 _fasorX=1.0;
00055 _fasorY=0.0;
00056 }
00057 ~InstantTunningEstimator()
00058 {
00059 }
00060 void setInertia(double inertia)
00061 {
00062 _inertia=inertia;
00063 }
00064
00065 void doIt(const std::vector<std::pair<double, double> >& peaks)
00066 {
00067 _fasorX*=_inertia;
00068 _fasorY*=_inertia;
00069 _instantX=0;
00070 _instantY=0;
00071 for (unsigned int peak=0; peak<peaks.size(); peak++)
00072 {
00073 double radiantTunning=peaks[peak].first*2*M_PI;
00074 _instantX+=cos(radiantTunning)*peaks[peak].second;
00075 _instantY+=sin(radiantTunning)*peaks[peak].second;
00076 }
00077 _fasorX += _instantX;
00078 _fasorY += _instantY;
00079 }
00080 std::pair<double,double> output() const
00081 {
00082 double tunning=std::atan2(_fasorY,_fasorX)/2/M_PI;
00083 double strength=std::sqrt(_fasorY*_fasorY+_fasorX*_fasorX);
00084 return std::make_pair(tunning, strength);
00085 }
00086 std::pair<double,double> instantTunning() const
00087 {
00088 double tunning=std::atan2(_instantY,_instantX)/2/M_PI;
00089 double strength=std::sqrt(_instantY*_instantY+_instantX*_instantX);
00090 return std::make_pair(tunning, strength);
00091 }
00092 };
00093
00094 }
00095
00096 #endif// InstantTunningEstimator_hxx
00097