CircularPeakPicking.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 CircularPeakPicking_hxx
00023 #define CircularPeakPicking_hxx
00024 #include <list>
00025 #include <vector>
00026
00027 namespace Simac
00028 {
00029
00045 class CircularPeakPicking
00046 {
00047 public:
00048 typedef std::vector<std::pair<double, double> > PeakList;
00049 private:
00050 PeakList _output;
00051 unsigned int _maxSize;
00052 double _binSize;
00053 double _offset;
00054 public:
00055 CircularPeakPicking(unsigned chromagramSize, double binSize=1.0, double offset=0.0)
00056 : _maxSize(chromagramSize), _binSize(binSize), _offset(offset)
00057 {
00058 _output.reserve(chromagramSize);
00059 }
00070 std::pair<double,double> interpolate(double y0, double y1, double y2)
00071 {
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 double a = y0/2 - y1 + y2/2;
00093 double b = y1 -y0 -a;
00094 double c = y0;
00095
00096
00097 double xmax = -b/(a*2);
00098
00099
00100
00101
00102 double ymax = b*xmax/2 + y0;
00103
00104 return std::make_pair(xmax, ymax);
00105 }
00106 void doIt(const std::vector<double> & chromagram)
00107 {
00108 _output.resize(0);
00109 unsigned i0=_maxSize-2;
00110 unsigned i1=_maxSize-1;
00111 for (unsigned i=0; i<_maxSize; i0=i1, i1=i, i++)
00112 {
00113
00114 if (chromagram[i0] > chromagram[i1]) continue;
00115 if (chromagram[i ] >= chromagram[i1]) continue;
00116
00117 std::pair<double,double> interpoled=
00118 interpolate(chromagram[i0],chromagram[i1],chromagram[i]);
00119
00120 interpoled.first+=i0;
00121
00122 while (interpoled.first<0) interpoled.first +=_maxSize;
00123 while (interpoled.first>=_maxSize) interpoled.first -=_maxSize;
00124
00125 interpoled.first*=_binSize;
00126
00127 interpoled.first+=_offset;
00128
00129 _output.push_back(interpoled);
00130 }
00131 }
00132 const PeakList & output() const
00133 {
00134 return _output;
00135 }
00136 };
00137
00138 }
00139
00140 #endif// CircularPeakPicking_hxx
00141