- refactored
git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@473 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -30,16 +30,31 @@ namespace jay {
|
||||
{
|
||||
struct Peak
|
||||
{
|
||||
Peak()
|
||||
: Peak(0, 0, 0, 0.0, 0.0)
|
||||
{
|
||||
|
||||
}
|
||||
Peak(uint64_t _id, int _pos, int _half_width, float _height_rel, float _height_abs)
|
||||
: id(_id)
|
||||
, pos(_pos)
|
||||
, half_width(_half_width)
|
||||
, height_rel(_height_rel)
|
||||
, height_abs(_height_abs)
|
||||
, isValid(true)
|
||||
{
|
||||
|
||||
}
|
||||
uint64_t id;
|
||||
float pos;
|
||||
float half_width;
|
||||
int pos;
|
||||
int half_width;
|
||||
float height_rel;
|
||||
float height_abs;
|
||||
bool isConfirmed;
|
||||
bool isValid;
|
||||
|
||||
bool isInRange(const Peak &other)
|
||||
{
|
||||
return (other.pos >= (pos - half_width)) and (other.pos <= (pos + half_width));
|
||||
return (other.pos >= left()) and (other.pos <= right());
|
||||
}
|
||||
|
||||
const Peak& update(const Peak &other)
|
||||
@@ -50,26 +65,61 @@ namespace jay {
|
||||
half_width = alpha*half_width + beta*other.half_width;
|
||||
height_rel = std::max(height_rel, other.height_rel);
|
||||
height_abs = std::max(height_abs, other.height_abs);
|
||||
isConfirmed = true;
|
||||
isValid = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
int left()
|
||||
{
|
||||
return pos - half_width;
|
||||
}
|
||||
|
||||
int right()
|
||||
{
|
||||
return pos + half_width;
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
Peak peakCheck(float const *pData, Peak const &peak, float thresh)
|
||||
{
|
||||
Peak result;
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool addToList(std::vector<int>&list, int pos)
|
||||
{
|
||||
bool found = false;
|
||||
for (std::vector<int>::iterator it = list.begin(); it != list.end(); it++)
|
||||
{
|
||||
if (*it == pos)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
list.push_back(pos);
|
||||
}
|
||||
return !found;
|
||||
}
|
||||
|
||||
float m_framerate;
|
||||
float m_peak_height_min;
|
||||
int m_peak_width_min;
|
||||
int m_peak_width_max;
|
||||
float m_alpha_s;
|
||||
float m_alpha_m;
|
||||
float *m_pPeakData;
|
||||
float *m_pX;
|
||||
float *m_pXs;
|
||||
float *m_pXm;
|
||||
float *m_pXd;
|
||||
float *m_pXds;
|
||||
int *m_pPeakPos;
|
||||
float *m_pPeakBox_rel;
|
||||
float *m_pPeakBox_abs;
|
||||
uint64_t m_frameCount;
|
||||
@@ -88,29 +138,36 @@ namespace jay {
|
||||
private:
|
||||
void fill(float *pDst, int length, float value);
|
||||
float mean(float *pSrc, int length);
|
||||
int threshold(float *pDst, float *pSrc, int length, float thresh);
|
||||
int findPeakPos(int *pDst, float *pSrc, int length);
|
||||
std::vector<int> findPeakPos(float* pSrc, int length, float thresh);
|
||||
|
||||
template <typename T>
|
||||
inline void sort(T const * const pData, int *pPos, int numPos)
|
||||
inline bool cmp(const T a, const T b)
|
||||
{
|
||||
int n = numPos;
|
||||
return (a < b);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void sort(T const * const pData, std::vector<int>&pos)
|
||||
{
|
||||
int n = pos.size();
|
||||
do
|
||||
{
|
||||
int newn = 1;
|
||||
for (int i=0; i < (n-1); i++)
|
||||
{
|
||||
if (pData[pPos[i]] < pData[pPos[i+1]])
|
||||
if (cmp(pData[pos[i]], pData[pos[i+1]]))
|
||||
{
|
||||
int temp = pPos[i+1];
|
||||
pPos[i+1] = pPos[i];
|
||||
pPos[i] = temp;
|
||||
int temp = pos[i+1];
|
||||
pos[i+1] = pos[i];
|
||||
pos[i] = temp;
|
||||
newn = i+1;
|
||||
} // ende if
|
||||
} // ende for
|
||||
n = newn;
|
||||
} while (n > 1);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
} // namespace jay
|
||||
|
||||
Reference in New Issue
Block a user