diff options
Diffstat (limited to 'gr-blocks/lib/peak_detector2_fb_impl.cc')
-rw-r--r-- | gr-blocks/lib/peak_detector2_fb_impl.cc | 30 |
1 files changed, 22 insertions, 8 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(); |