3
* Copyright 2007 Free Software Foundation, Inc.
5
* This file is part of GNU Radio
7
* GNU Radio is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 3, or (at your option)
12
* GNU Radio is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with GNU Radio; see the file COPYING. If not, write to
19
* the Free Software Foundation, Inc., 51 Franklin Street,
20
* Boston, MA 02110-1301, USA.
27
#include <gr_peak_detector2_fb.h>
28
#include <gr_io_signature.h>
31
gr_peak_detector2_fb_sptr
32
gr_make_peak_detector2_fb (float threshold_factor_rise,
33
int look_ahead, float alpha)
35
return gr_peak_detector2_fb_sptr (new gr_peak_detector2_fb (threshold_factor_rise,
39
gr_peak_detector2_fb::gr_peak_detector2_fb (float threshold_factor_rise,
40
int look_ahead, float alpha)
41
: gr_sync_block ("peak_detector2_fb",
42
gr_make_io_signature (1, 1, sizeof(float)),
43
gr_make_io_signature2 (1, 2, sizeof(char), sizeof(float))),
44
d_threshold_factor_rise(threshold_factor_rise),
45
d_look_ahead(look_ahead), d_alpha(alpha), d_avg(0.0f), d_found(false)
50
gr_peak_detector2_fb::work (int noutput_items,
51
gr_vector_const_void_star &input_items,
52
gr_vector_void_star &output_items) {
53
float *iptr = (float *) input_items[0];
54
char *optr = (char *) output_items[0];
56
assert(noutput_items >= 2);
58
memset(optr, 0, noutput_items*sizeof(char));
60
for (int i = 0; i < noutput_items; i++) {
63
// Have not yet detected presence of peak
64
if (iptr[i] > d_avg * (1.0f + d_threshold_factor_rise)) {
66
d_look_ahead_remaining = d_look_ahead;
67
d_peak_val = -(float)INFINITY;
70
d_avg = d_alpha*iptr[i] + (1.0f - d_alpha)*d_avg;
74
// Detected presence of peak
75
if (iptr[i] > d_peak_val) {
79
else if (d_look_ahead_remaining <= 0) {
85
// Have not yet located peak, loop and keep searching.
86
d_look_ahead_remaining--;
89
// Every iteration of the loop, write debugging signal out if
91
if (output_items.size() == 2) {
92
float *sigout = (float *) output_items[1];
100
// else if detected presence, keep searching during the next call to work.
101
int tmp = d_peak_ind;