summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrear1019 <rear1019@posteo.de>2020-04-13 17:35:52 +0200
committerMartin Braun <martin@gnuradio.org>2021-01-11 08:57:22 -0800
commitca4a77e0e955ebe2b4285615289f3ab3634c9a11 (patch)
treeccd08d835394a37af146623ee968b21eba04017e
parentfc6d5cb82007dfe6f75984d33660b1bfa73e9150 (diff)
peak_detector2: (Hopefully) correct fix for #3345
-rw-r--r--gr-blocks/lib/peak_detector2_fb_impl.cc30
-rw-r--r--gr-blocks/lib/peak_detector2_fb_impl.h2
2 files changed, 22 insertions, 10 deletions
diff --git a/gr-blocks/lib/peak_detector2_fb_impl.cc b/gr-blocks/lib/peak_detector2_fb_impl.cc
index b95fdd381c..adfe7a806f 100644
--- a/gr-blocks/lib/peak_detector2_fb_impl.cc
+++ b/gr-blocks/lib/peak_detector2_fb_impl.cc
@@ -88,10 +88,17 @@ int peak_detector2_fb_impl::work(int noutput_items,
sigout[i] = d_avg;
if (iptr[i] > d_avg * (1.0f + d_threshold_factor_rise)) {
d_found = true;
- d_peak_val = iptr[i];
- d_peak_ind = i;
set_output_multiple(d_look_ahead);
- return i + 1;
+ /*
+ * Consume any samples filtered so far except the last one (which
+ * caused the threshold to be exceeded). As per documentation
+ * in peak_detector2_fb.h this sample is part of the window where
+ * the peak is to be searched. The next time work() is called
+ * execution of the code jumps to the else-if clause below. There,
+ * the first sample will be the last sample processed here (because
+ * not consumed here).
+ */
+ return i;
}
}
return noutput_items;
@@ -99,16 +106,23 @@ int peak_detector2_fb_impl::work(int noutput_items,
// can complete in this call
else if (noutput_items >= d_look_ahead) {
- for (int i = 0; i < d_look_ahead; i++) {
+ float peak_val = iptr[0];
+ int peak_ind = 0;
+ /*
+ * Loop starts at the second sample because the first one has already been
+ * filtered (see above). Result of the maximum search is correct due
+ * to initialisations above.
+ */
+ for (int i = 1; i < d_look_ahead; i++) {
d_avg = d_alpha * iptr[i] + (1.0f - d_alpha) * d_avg;
if (output_items.size() == 2)
sigout[i] = d_avg;
- if (iptr[i] > d_peak_val) {
- d_peak_val = iptr[i];
- d_peak_ind = i;
+ if (iptr[i] > peak_val) {
+ peak_val = iptr[i];
+ peak_ind = i;
}
}
- optr[d_peak_ind] = 1;
+ optr[peak_ind] = 1;
// restart the search
invalidate();
diff --git a/gr-blocks/lib/peak_detector2_fb_impl.h b/gr-blocks/lib/peak_detector2_fb_impl.h
index 8432d64eaa..405cc987d2 100644
--- a/gr-blocks/lib/peak_detector2_fb_impl.h
+++ b/gr-blocks/lib/peak_detector2_fb_impl.h
@@ -21,8 +21,6 @@ class peak_detector2_fb_impl : public peak_detector2_fb
private:
float d_threshold_factor_rise;
int d_look_ahead;
- int d_peak_ind;
- float d_peak_val;
float d_alpha;
float d_avg;
bool d_found;