1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #include <fpa/Common/PeakDetector.h>
8 // -------------------------------------------------------------------------
9 fpa::Common::PeakDetector::
17 // -------------------------------------------------------------------------
18 fpa::Common::PeakDetector::
23 // -------------------------------------------------------------------------
24 unsigned long fpa::Common::PeakDetector::
25 GetKernelSize( ) const
30 // -------------------------------------------------------------------------
31 double fpa::Common::PeakDetector::
37 // -------------------------------------------------------------------------
38 double fpa::Common::PeakDetector::
44 // -------------------------------------------------------------------------
45 void fpa::Common::PeakDetector::
46 SetKernelSize( unsigned long k )
52 // -------------------------------------------------------------------------
53 void fpa::Common::PeakDetector::
54 SetThreshold( double t )
60 // -------------------------------------------------------------------------
61 void fpa::Common::PeakDetector::
62 SetInfluence( double i )
68 // -------------------------------------------------------------------------
69 void fpa::Common::PeakDetector::
77 this->m_Peaks.clear( );
78 this->m_MeanAndVar.Clear( );
81 // -------------------------------------------------------------------------
82 const std::vector< double >& fpa::Common::PeakDetector::
88 // -------------------------------------------------------------------------
89 const std::vector< double >& fpa::Common::PeakDetector::
95 // -------------------------------------------------------------------------
96 const std::vector< double >& fpa::Common::PeakDetector::
97 GetFilteredYValues( ) const
102 // -------------------------------------------------------------------------
103 const std::vector< double >& fpa::Common::PeakDetector::
106 return( this->m_Avg );
109 // -------------------------------------------------------------------------
110 const std::vector< double >& fpa::Common::PeakDetector::
111 GetDeviations( ) const
113 return( this->m_STD );
116 // -------------------------------------------------------------------------
117 const std::vector< fpa::Common::PeakDetector::TPeak >& fpa::Common::
118 PeakDetector::GetPeaks( ) const
120 return( this->m_Peaks );
123 // -------------------------------------------------------------------------
124 unsigned long fpa::Common::PeakDetector::
125 GetNumberOfSamples( ) const
127 return( this->m_X.size( ) );
130 // -------------------------------------------------------------------------
131 fpa::Common::PeakDetector::
132 TPeak fpa::Common::PeakDetector::
133 AddValue( double x, double y )
135 this->m_X.push_back( x );
136 this->m_Y.push_back( y );
138 if( this->m_YF.size( ) < this->m_K )
140 this->m_YF.push_back( y );
141 this->m_Avg.push_back( double( 0 ) );
142 this->m_STD.push_back( double( 0 ) );
143 this->m_Peaks.push_back( Self::NoPeak );
145 this->m_MeanAndVar.AddValue( y );
146 if( this->m_YF.size( ) == this->m_K )
148 this->m_Avg.push_back( this->m_MeanAndVar.GetMean( ) );
149 this->m_STD.push_back( this->m_MeanAndVar.GetDeviation( ) );
155 unsigned long i = this->m_X.size( ) - 1;
157 ( std::fabs( y - this->m_Avg[ i - 1 ] ) ) >
158 ( this->m_T * this->m_STD[ i - 1 ] )
161 this->m_Peaks.push_back(
162 ( y > this->m_Avg[ i - 1 ] )? Self::PosPeak: Self::NegPeak
164 this->m_YF.push_back(
166 ( ( double( 1 ) - this->m_I ) * this->m_YF[ i - 1 ] )
171 this->m_Peaks.push_back( Self::NoPeak );
172 this->m_YF.push_back( y );
176 this->m_MeanAndVar.Clear( );
178 for( unsigned long j = i - this->m_K; j <= i; ++j, ++k )
179 this->m_MeanAndVar.AddValue( this->m_YF[ j ] );
180 this->m_Avg.push_back( this->m_MeanAndVar.GetMean( ) );
181 this->m_STD.push_back( this->m_MeanAndVar.GetDeviation( ) );
184 return( this->m_Peaks.back( ) );