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.
23 // WARNING: this file is machine generated. Edits will be over written
29 #include <gr_peak_detector_fb.h>
30 #include <gr_io_signature.h>
33 gr_peak_detector_fb_sptr
34 gr_make_peak_detector_fb (float threshold_factor_rise,
35 float threshold_factor_fall,
36 int look_ahead, float alpha)
38 return gr_peak_detector_fb_sptr (new gr_peak_detector_fb (threshold_factor_rise,
39 threshold_factor_fall,
43 gr_peak_detector_fb::gr_peak_detector_fb (float threshold_factor_rise,
44 float threshold_factor_fall,
45 int look_ahead, float alpha)
46 : gr_sync_block ("peak_detector_fb",
47 gr_make_io_signature (1, 1, sizeof (float)),
48 gr_make_io_signature (1, 1, sizeof (char))),
49 d_threshold_factor_rise(threshold_factor_rise),
50 d_threshold_factor_fall(threshold_factor_fall),
51 d_look_ahead(look_ahead), d_avg_alpha(alpha), d_avg(0), d_found(0)
56 gr_peak_detector_fb::work (int noutput_items,
57 gr_vector_const_void_star &input_items,
58 gr_vector_void_star &output_items)
60 float *iptr = (float *) input_items[0];
61 char *optr = (char *) output_items[0];
63 memset(optr, 0, noutput_items*sizeof(char));
65 float peak_val = -(float)INFINITY;
67 unsigned char state = 0;
70 //printf("noutput_items %d\n",noutput_items);
71 while(i < noutput_items) {
72 if(state == 0) { // below threshold
73 if(iptr[i] > d_avg*d_threshold_factor_rise) {
77 d_avg = (d_avg_alpha)*iptr[i] + (1-d_avg_alpha)*d_avg;
81 else if(state == 1) { // above threshold, have not found peak
82 //printf("Entered State 1: %f i: %d noutput_items: %d\n", iptr[i], i, noutput_items);
83 if(iptr[i] > peak_val) {
86 d_avg = (d_avg_alpha)*iptr[i] + (1-d_avg_alpha)*d_avg;
89 else if (iptr[i] > d_avg*d_threshold_factor_fall) {
90 d_avg = (d_avg_alpha)*iptr[i] + (1-d_avg_alpha)*d_avg;
96 peak_val = -(float)INFINITY;
97 //printf("Leaving State 1: Peak: %f Peak Ind: %d i: %d noutput_items: %d\n",
98 //peak_val, peak_ind, i, noutput_items);
104 //printf("Leave in State 0, produced %d\n",noutput_items);
105 return noutput_items;
107 else { // only return up to passing the threshold
108 //printf("Leave in State 1, only produced %d of %d\n",peak_ind,noutput_items);