- improved Peak class
- added makeBox in Peak class - sort on Peaks git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@474 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -202,7 +202,7 @@ namespace gr {
|
|||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
// Search true maximum peak using hill climbing
|
// Search true maximum peak using hill climbing
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
std::vector<int> newPeakPos;
|
std::vector<Peak> newPeakPos;
|
||||||
int numPeaksLast = 0;
|
int numPeaksLast = 0;
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
@@ -225,7 +225,9 @@ namespace gr {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
addToList(newPeakPos, pos);
|
Peak peak(m_peak_id++, pos);
|
||||||
|
peak.height_abs = m_pXds[pos];
|
||||||
|
addToListByPos(newPeakPos, peak);
|
||||||
numPeaksClimbed++;
|
numPeaksClimbed++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -237,99 +239,38 @@ namespace gr {
|
|||||||
}
|
}
|
||||||
numPeaksLast = numPeaksClimbed;
|
numPeaksLast = numPeaksClimbed;
|
||||||
}
|
}
|
||||||
peakPos = newPeakPos;
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
// Sort peaks
|
// Sort peaks
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
sort<float>(m_pXds, peakPos);
|
sort(newPeakPos);
|
||||||
|
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
// Find peak boxes
|
// Find peak boxes
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
m_peakList.clear();
|
m_peakList.clear();
|
||||||
for (int i = 0; i < peakPos.size(); i++)
|
for (int i = 0; i < newPeakPos.size(); i++)
|
||||||
{
|
{
|
||||||
int pbh = 0;
|
Peak &peak = newPeakPos[i];
|
||||||
int pos = peakPos[i];
|
bool success = peak.makeBox(m_peak_width_min, m_peak_width_max, m_pXds, nitems_per_block);
|
||||||
int left = pos;
|
if (success)
|
||||||
int right = pos;
|
|
||||||
float nom = 10;
|
|
||||||
int left_found = 0;
|
|
||||||
int right_found = 0;
|
|
||||||
while(!(left_found & right_found))
|
|
||||||
{
|
{
|
||||||
// Determine peak width left from center (pos)
|
// Intersection check
|
||||||
if (m_pXds[left] > nom)
|
bool intersection = false;
|
||||||
|
for (int i = 0; i < m_peakList.size(); i++)
|
||||||
{
|
{
|
||||||
if (left > 0)
|
if (m_peakList[i].isInRange(peak))
|
||||||
{
|
{
|
||||||
left--;
|
intersection = true;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (!intersection)
|
||||||
{
|
{
|
||||||
left_found = 1;
|
peak.height_rel = m_pXds[peak.pos];
|
||||||
|
peak.height_abs = m_pXs[peak.pos];
|
||||||
|
m_peakList.push_back(peak);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine peak width right from center (pos)
|
|
||||||
if (m_pXds[right] > nom)
|
|
||||||
{
|
|
||||||
if (right < (nitems_per_block-1))
|
|
||||||
{
|
|
||||||
right++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
right_found = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int pbh_left = pos - left;
|
|
||||||
int pbh_right = right - pos;
|
|
||||||
|
|
||||||
// Take larger peak width
|
|
||||||
pbh = std::max(pbh_left, pbh_right);
|
|
||||||
|
|
||||||
// Ensure peak box is at least pb_min
|
|
||||||
pbh = std::max(pbh, m_peak_width_min);
|
|
||||||
|
|
||||||
if (pbh > m_peak_width_max)
|
|
||||||
{
|
|
||||||
pbh = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pbh == 0)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Peak peak(m_peak_id, pos, pbh, m_pXds[pos], m_pXs[pos]);
|
|
||||||
|
|
||||||
// Intersection check
|
|
||||||
bool intersection = false;
|
|
||||||
for (int i = 0; i < m_peakList.size(); i++)
|
|
||||||
{
|
|
||||||
if (m_peakList[i].isInRange(peak))
|
|
||||||
{
|
|
||||||
intersection = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!intersection)
|
|
||||||
{
|
|
||||||
m_peakList.push_back(peak);
|
|
||||||
m_peak_id++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,10 +35,15 @@ namespace jay {
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
Peak(uint64_t _id, int _pos, int _half_width, float _height_rel, float _height_abs)
|
Peak(uint64_t _id, int _pos)
|
||||||
|
: Peak(_id, _pos, 0, 0.0, 0.0)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
Peak(uint64_t _id, int _pos, int _pbh, float _height_rel, float _height_abs)
|
||||||
: id(_id)
|
: id(_id)
|
||||||
, pos(_pos)
|
, pos(_pos)
|
||||||
, half_width(_half_width)
|
, pbh(_pbh)
|
||||||
, height_rel(_height_rel)
|
, height_rel(_height_rel)
|
||||||
, height_abs(_height_abs)
|
, height_abs(_height_abs)
|
||||||
, isValid(true)
|
, isValid(true)
|
||||||
@@ -47,7 +52,7 @@ namespace jay {
|
|||||||
}
|
}
|
||||||
uint64_t id;
|
uint64_t id;
|
||||||
int pos;
|
int pos;
|
||||||
int half_width;
|
int pbh;
|
||||||
float height_rel;
|
float height_rel;
|
||||||
float height_abs;
|
float height_abs;
|
||||||
bool isValid;
|
bool isValid;
|
||||||
@@ -57,12 +62,74 @@ namespace jay {
|
|||||||
return (other.pos >= left()) and (other.pos <= right());
|
return (other.pos >= left()) and (other.pos <= right());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool makeBox(int pbh_min, int pbh_max, float const *pData, int length)
|
||||||
|
{
|
||||||
|
pbh = 0;
|
||||||
|
int left = pos;
|
||||||
|
int right = pos;
|
||||||
|
float nom = 10;
|
||||||
|
int left_found = 0;
|
||||||
|
int right_found = 0;
|
||||||
|
while(!(left_found & right_found))
|
||||||
|
{
|
||||||
|
// Determine peak width left from center (pos)
|
||||||
|
if (pData[left] > nom)
|
||||||
|
{
|
||||||
|
if (left > 0)
|
||||||
|
{
|
||||||
|
left--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
left_found = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine peak width right from center (pos)
|
||||||
|
if (pData[right] > nom)
|
||||||
|
{
|
||||||
|
if (right < (length-1))
|
||||||
|
{
|
||||||
|
right++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
right_found = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pbh_left = pos - left;
|
||||||
|
int pbh_right = right - pos;
|
||||||
|
|
||||||
|
// Take larger peak width
|
||||||
|
pbh = std::max(pbh_left, pbh_right);
|
||||||
|
|
||||||
|
// Ensure peak box is at least pb_min
|
||||||
|
pbh = std::max(pbh, pbh_min);
|
||||||
|
|
||||||
|
if (pbh > pbh_max)
|
||||||
|
{
|
||||||
|
pbh = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pbh > 0;
|
||||||
|
}
|
||||||
|
|
||||||
const Peak& update(const Peak &other)
|
const Peak& update(const Peak &other)
|
||||||
{
|
{
|
||||||
float beta = 0.1f;
|
float beta = 0.1f;
|
||||||
float alpha = (1.f-beta);
|
float alpha = (1.f-beta);
|
||||||
pos = alpha*pos + beta*other.pos;
|
pos = alpha*pos + beta*other.pos;
|
||||||
half_width = alpha*half_width + beta*other.half_width;
|
pbh = alpha*pbh + beta*other.pbh;
|
||||||
height_rel = std::max(height_rel, other.height_rel);
|
height_rel = std::max(height_rel, other.height_rel);
|
||||||
height_abs = std::max(height_abs, other.height_abs);
|
height_abs = std::max(height_abs, other.height_abs);
|
||||||
isValid = true;
|
isValid = true;
|
||||||
@@ -71,12 +138,12 @@ namespace jay {
|
|||||||
|
|
||||||
int left()
|
int left()
|
||||||
{
|
{
|
||||||
return pos - half_width;
|
return pos - pbh;
|
||||||
}
|
}
|
||||||
|
|
||||||
int right()
|
int right()
|
||||||
{
|
{
|
||||||
return pos + half_width;
|
return pos + pbh;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -90,12 +157,12 @@ namespace jay {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool addToList(std::vector<int>&list, int pos)
|
bool addToListByPos(std::vector<Peak>&list, Peak peak)
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (std::vector<int>::iterator it = list.begin(); it != list.end(); it++)
|
for (std::vector<Peak>::iterator it = list.begin(); it != list.end(); it++)
|
||||||
{
|
{
|
||||||
if (*it == pos)
|
if (it->pos == peak.pos)
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
@@ -104,7 +171,7 @@ namespace jay {
|
|||||||
|
|
||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
list.push_back(pos);
|
list.push_back(peak);
|
||||||
}
|
}
|
||||||
return !found;
|
return !found;
|
||||||
}
|
}
|
||||||
@@ -140,26 +207,19 @@ namespace jay {
|
|||||||
float mean(float *pSrc, int length);
|
float mean(float *pSrc, int length);
|
||||||
std::vector<int> findPeakPos(float* pSrc, int length, float thresh);
|
std::vector<int> findPeakPos(float* pSrc, int length, float thresh);
|
||||||
|
|
||||||
template <typename T>
|
void sort(std::vector<Peak>&peaks)
|
||||||
inline bool cmp(const T a, const T b)
|
|
||||||
{
|
{
|
||||||
return (a < b);
|
int n = peaks.size();
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void sort(T const * const pData, std::vector<int>&pos)
|
|
||||||
{
|
|
||||||
int n = pos.size();
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
int newn = 1;
|
int newn = 1;
|
||||||
for (int i=0; i < (n-1); i++)
|
for (int i=0; i < (n-1); i++)
|
||||||
{
|
{
|
||||||
if (cmp(pData[pos[i]], pData[pos[i+1]]))
|
if (peaks[i].height_abs < peaks[i+1].height_abs)
|
||||||
{
|
{
|
||||||
int temp = pos[i+1];
|
Peak temp = peaks[i+1];
|
||||||
pos[i+1] = pos[i];
|
peaks[i+1] = peaks[i];
|
||||||
pos[i] = temp;
|
peaks[i] = temp;
|
||||||
newn = i+1;
|
newn = i+1;
|
||||||
} // ende if
|
} // ende if
|
||||||
} // ende for
|
} // ende for
|
||||||
|
|||||||
Reference in New Issue
Block a user