diff --git a/gr-jay/lib/peak_detect_impl.cc b/gr-jay/lib/peak_detect_impl.cc index 07aa674..7c4f7ff 100644 --- a/gr-jay/lib/peak_detect_impl.cc +++ b/gr-jay/lib/peak_detect_impl.cc @@ -341,10 +341,24 @@ namespace gr { .half_width = (float)pbh, .height_rel = m_pXd[pos], .height_abs = m_pX[pos], + .isConfirmed = true, }; - m_peakList.push_back(peak); - m_peak_id++; + // 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++; + } } // ----------------------------------------------------------------- @@ -354,14 +368,13 @@ namespace gr { for (int i = 0; i < m_peakList.size(); i++) { Peak &peak = m_peakList[i]; - + bool found = false; for (int j=0; j < m_peakHistory.size(); j++) { if (m_peakHistory[j].isInRange(peak)) { - Peak p = m_peakHistory[j].update(peak); - temp.push_back(p); + temp.push_back(m_peakHistory[j].update(peak)); found = true; break; } @@ -369,9 +382,21 @@ namespace gr { if (!found) { + peak.isConfirmed = 1; temp.push_back(peak); + 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.isConfirmed) + { + fprintf(stderr, "Lost Peak #%u at %d\n", (int)peak.id, (int)peak.pos); + } + } + m_peakHistory.clear(); m_peakHistory = temp; // ----------------------------------------------------------------- @@ -412,6 +437,7 @@ namespace gr { 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) + k, tag_key, tag_value, m_tag_id); + peak.isConfirmed = false; } m_frameCount++; diff --git a/gr-jay/lib/peak_detect_impl.h b/gr-jay/lib/peak_detect_impl.h index 5925733..1b57db8 100644 --- a/gr-jay/lib/peak_detect_impl.h +++ b/gr-jay/lib/peak_detect_impl.h @@ -35,6 +35,7 @@ namespace jay { float half_width; float height_rel; float height_abs; + bool isConfirmed; bool isInRange(const Peak &other) { @@ -49,7 +50,7 @@ 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; return *this; } };