- improved peak manager: less noisy peak new/lost
git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@475 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<Peak> newPeakPos;
|
std::vector<Peak> peaks;
|
||||||
int numPeaksLast = 0;
|
int numPeaksLast = 0;
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
@@ -226,8 +226,8 @@ namespace gr {
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Peak peak(m_peak_id++, pos);
|
Peak peak(m_peak_id++, pos);
|
||||||
peak.height_abs = m_pXds[pos];
|
peak.heightUpdate_rel(m_pXds, nitems_per_block);
|
||||||
addToListByPos(newPeakPos, peak);
|
addToListByPos(peaks, peak);
|
||||||
numPeaksClimbed++;
|
numPeaksClimbed++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -243,15 +243,15 @@ namespace gr {
|
|||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
// Sort peaks
|
// Sort peaks
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
sort(newPeakPos);
|
sort(peaks);
|
||||||
|
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
// Find peak boxes
|
// Find peak boxes
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
m_peakList.clear();
|
m_peakList.clear();
|
||||||
for (int i = 0; i < newPeakPos.size(); i++)
|
for (int i = 0; i < peaks.size(); i++)
|
||||||
{
|
{
|
||||||
Peak &peak = newPeakPos[i];
|
Peak &peak = peaks[i];
|
||||||
bool success = peak.makeBox(m_peak_width_min, m_peak_width_max, m_pXds, nitems_per_block);
|
bool success = peak.makeBox(m_peak_width_min, m_peak_width_max, m_pXds, nitems_per_block);
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
@@ -259,9 +259,10 @@ namespace gr {
|
|||||||
bool intersection = false;
|
bool intersection = false;
|
||||||
for (int i = 0; i < m_peakList.size(); i++)
|
for (int i = 0; i < m_peakList.size(); i++)
|
||||||
{
|
{
|
||||||
if (m_peakList[i].isInRange(peak))
|
if (m_peakList[i].isIntersect(peak))
|
||||||
{
|
{
|
||||||
intersection = true;
|
intersection = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,16 +279,31 @@ namespace gr {
|
|||||||
// Peak management
|
// Peak management
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
temp.clear();
|
temp.clear();
|
||||||
|
for (int j=0; j < m_peakHistory.size(); j++)
|
||||||
|
{
|
||||||
|
Peak &peak = m_peakHistory[j];
|
||||||
|
peak.heightUpdate_rel(m_pXds, nitems_per_block);
|
||||||
|
|
||||||
|
if (peak.height_rel >= (m_peak_height_min-6.f))
|
||||||
|
{
|
||||||
|
temp.push_back(peak);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Lost Peak #%u at %d\n", (int)peak.id, (int)peak.pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < m_peakList.size(); i++)
|
for (int i = 0; i < m_peakList.size(); i++)
|
||||||
{
|
{
|
||||||
Peak &peak = m_peakList[i];
|
Peak &peak = m_peakList[i];
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (int j=0; j < m_peakHistory.size(); j++)
|
for (int j=0; j < temp.size(); j++)
|
||||||
{
|
{
|
||||||
if (m_peakHistory[j].isInRange(peak))
|
if (temp[j].isInRange(peak))
|
||||||
{
|
{
|
||||||
temp.push_back(m_peakHistory[j].update(peak));
|
temp[j].merge(peak);
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -295,20 +311,11 @@ namespace gr {
|
|||||||
|
|
||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
peak.isValid = 1;
|
|
||||||
temp.push_back(peak);
|
temp.push_back(peak);
|
||||||
fprintf(stderr, "New Peak #%u at %d\n", (int)peak.id, (int)peak.pos);
|
fprintf(stderr, "New Peak #%u at %d\n", (int)peak.id, (int)peak.pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j=0; j < m_peakHistory.size(); j++)
|
|
||||||
{
|
|
||||||
Peak &peak = m_peakHistory[j];
|
|
||||||
if (!peak.isValid)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Lost Peak #%u at %d\n", (int)peak.id, (int)peak.pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_peakHistory.clear();
|
m_peakHistory.clear();
|
||||||
m_peakHistory = temp;
|
m_peakHistory = temp;
|
||||||
|
|
||||||
@@ -350,7 +357,6 @@ namespace gr {
|
|||||||
pmt::pmt_t tag_key = pmt::string_to_symbol(std::string("pos_id_") + std::to_string(peak.id));
|
pmt::pmt_t tag_key = pmt::string_to_symbol(std::string("pos_id_") + std::to_string(peak.id));
|
||||||
pmt::pmt_t tag_value = pmt::from_long(peak.pos);
|
pmt::pmt_t tag_value = pmt::from_long(peak.pos);
|
||||||
add_item_tag(DATA, nitems_written(DATA) + k, tag_key, tag_value, m_tag_id);
|
add_item_tag(DATA, nitems_written(DATA) + k, tag_key, tag_value, m_tag_id);
|
||||||
peak.isValid = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_frameCount++;
|
m_frameCount++;
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ namespace jay {
|
|||||||
, pbh(_pbh)
|
, pbh(_pbh)
|
||||||
, height_rel(_height_rel)
|
, height_rel(_height_rel)
|
||||||
, height_abs(_height_abs)
|
, height_abs(_height_abs)
|
||||||
, isValid(true)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -55,13 +54,37 @@ namespace jay {
|
|||||||
int pbh;
|
int pbh;
|
||||||
float height_rel;
|
float height_rel;
|
||||||
float height_abs;
|
float height_abs;
|
||||||
bool isValid;
|
|
||||||
|
|
||||||
bool isInRange(const Peak &other)
|
bool isInRange(const Peak &other) const
|
||||||
{
|
{
|
||||||
return (other.pos >= left()) and (other.pos <= right());
|
return (other.pos >= left()) and (other.pos <= right());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isIntersect(const Peak &other) const
|
||||||
|
{
|
||||||
|
return (right() >= other.left()) and (other.right() >= left());
|
||||||
|
}
|
||||||
|
|
||||||
|
void heightUpdate_rel(float const *pData, int length)
|
||||||
|
{
|
||||||
|
float newHeight = -100.f;
|
||||||
|
for (int i=left(); i <= right(); i++)
|
||||||
|
{
|
||||||
|
newHeight = std::max(newHeight, pData[i]);
|
||||||
|
}
|
||||||
|
height_rel = newHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
void heightUpdate_abs(float const *pData, int length)
|
||||||
|
{
|
||||||
|
float newHeight = -100.f;
|
||||||
|
for (int i=left(); i <= right(); i++)
|
||||||
|
{
|
||||||
|
newHeight = std::max(newHeight, pData[i]);
|
||||||
|
}
|
||||||
|
height_abs = newHeight;
|
||||||
|
}
|
||||||
|
|
||||||
bool makeBox(int pbh_min, int pbh_max, float const *pData, int length)
|
bool makeBox(int pbh_min, int pbh_max, float const *pData, int length)
|
||||||
{
|
{
|
||||||
pbh = 0;
|
pbh = 0;
|
||||||
@@ -124,7 +147,7 @@ namespace jay {
|
|||||||
return pbh > 0;
|
return pbh > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Peak& update(const Peak &other)
|
const Peak& merge(const Peak &other)
|
||||||
{
|
{
|
||||||
float beta = 0.1f;
|
float beta = 0.1f;
|
||||||
float alpha = (1.f-beta);
|
float alpha = (1.f-beta);
|
||||||
@@ -132,16 +155,15 @@ namespace jay {
|
|||||||
pbh = alpha*pbh + beta*other.pbh;
|
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;
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
int left()
|
int left() const
|
||||||
{
|
{
|
||||||
return pos - pbh;
|
return pos - pbh;
|
||||||
}
|
}
|
||||||
|
|
||||||
int right()
|
int right() const
|
||||||
{
|
{
|
||||||
return pos + pbh;
|
return pos + pbh;
|
||||||
}
|
}
|
||||||
@@ -215,7 +237,7 @@ namespace jay {
|
|||||||
int newn = 1;
|
int newn = 1;
|
||||||
for (int i=0; i < (n-1); i++)
|
for (int i=0; i < (n-1); i++)
|
||||||
{
|
{
|
||||||
if (peaks[i].height_abs < peaks[i+1].height_abs)
|
if (peaks[i].height_rel < peaks[i+1].height_rel)
|
||||||
{
|
{
|
||||||
Peak temp = peaks[i+1];
|
Peak temp = peaks[i+1];
|
||||||
peaks[i+1] = peaks[i];
|
peaks[i+1] = peaks[i];
|
||||||
|
|||||||
Reference in New Issue
Block a user