diff --git a/gr-jay/lib/peak_detect_impl.cc b/gr-jay/lib/peak_detect_impl.cc index b523439..87e9d22 100644 --- a/gr-jay/lib/peak_detect_impl.cc +++ b/gr-jay/lib/peak_detect_impl.cc @@ -74,9 +74,7 @@ namespace gr { std::stringstream str; str << name() << unique_id(); m_tag_id = pmt::string_to_symbol(str.str()); - - fprintf(stderr, "m_peakList.size = %u\n", m_peakHistory.size()); - fprintf(stderr, "m_peakList.max_size = %u\n", m_peakHistory.max_size()); + } /* @@ -331,7 +329,6 @@ namespace gr { continue; } - // Find intersection Peak peak = { .id = m_peak_id, @@ -340,29 +337,15 @@ namespace gr { .height_rel = m_pXd[pos], .height_abs = m_pX[pos], }; - int does_intersect = 0; - for (int j=0; j < m_peakList.size(); j++) - { - if (m_peakList[j].isInRange(peak)) - { - if (m_peakList[j].height_rel > peak.height_rel) - { - does_intersect = 1; - break; - } - } - } - - if (!does_intersect) - { - m_peakList.push_back(peak); - m_peak_id++; - } + + m_peakList.push_back(peak); + m_peak_id++; } // ----------------------------------------------------------------- // Peak management // ----------------------------------------------------------------- + temp.clear(); for (int i = 0; i < m_peakList.size(); i++) { Peak &peak = m_peakList[i]; @@ -372,7 +355,8 @@ namespace gr { { if (m_peakHistory[j].isInRange(peak)) { - m_peakHistory[j].update(peak); + Peak p = m_peakHistory[j].update(peak); + temp.push_back(p); found = true; break; } @@ -380,10 +364,11 @@ namespace gr { if (!found) { - m_peakHistory.push_back(peak); + temp.push_back(peak); } } - + m_peakHistory = temp; + // ----------------------------------------------------------------- // Create peak box data // ----------------------------------------------------------------- @@ -419,11 +404,8 @@ namespace gr { { // Create peak tags Peak &peak = m_peakHistory[i]; - pmt::pmt_t tag_key = pmt::string_to_symbol("id"); - pmt::pmt_t tag_value = pmt::from_long(peak.id); - add_item_tag(DATA, nitems_written(DATA) + peak.pos, tag_key, tag_value, m_tag_id); - tag_key = pmt::string_to_symbol("pos"); - tag_value = pmt::from_long(peak.pos); + 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); add_item_tag(DATA, nitems_written(DATA) + peak.pos, tag_key, tag_value, m_tag_id); } diff --git a/gr-jay/lib/peak_detect_impl.h b/gr-jay/lib/peak_detect_impl.h index e7f1ea6..0f7d5db 100644 --- a/gr-jay/lib/peak_detect_impl.h +++ b/gr-jay/lib/peak_detect_impl.h @@ -41,14 +41,16 @@ namespace jay { return (other.pos >= (pos - half_width)) and (other.pos <= (pos + half_width)); } - void update(const Peak &other) + const Peak& update(const Peak &other) { - float alpha = 0.5f; - float beta = 0.5f; + float beta = 0.1f; + float alpha = (1.f-beta); pos = alpha*pos + beta*other.pos; half_width = alpha*half_width + beta*other.half_width; - height_rel = alpha*height_rel + beta*other.height_rel; - height_abs = alpha*height_abs + beta*other.height_abs; + height_rel = std::max(height_rel, other.height_rel); + height_abs = std::max(height_abs, other.height_abs); + + return *this; } }; @@ -72,6 +74,7 @@ namespace jay { pmt::pmt_t m_tag_id; std::vector m_peakList; std::vector m_peakHistory; + std::vector temp; uint64_t m_peak_id; public: