gr-baz Package
gr_peak_detector2_fb.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2007 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
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)
10  * any later version.
11  *
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.
16  *
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.
21  */
22 
23 #ifndef INCLUDED_gr_peak_detector2_FB_H
24 #define INCLUDED_gr_peak_detector2_FB_H
25 
26 #include <gr_core_api.h>
27 #include <gr_sync_block.h>
28 
31 
33  int look_ahead = 1000,
34  float alpha = 0.001);
35 
36 /*!
37  * \brief Detect the peak of a signal
38  * \ingroup level_blk
39  *
40  * If a peak is detected, this block outputs a 1,
41  * or it outputs 0's. A separate debug output may be connected, to
42  * view the internal EWMA described below.
43  *
44  * \param threshold_factor_rise The threshold factor determins when a peak
45  * is present. An EWMA average of the signal is calculated and when the
46  * value of the signal goes over threshold_factor_rise*average, we
47  * call the peak.
48  * \param look_ahead The look-ahead value is used when the threshold is
49  * found to locate the peak within this range.
50  * \param alpha The gain value of a single-pole moving average filter
51  */
52 
54 {
56  gr_make_peak_detector2_fb (float threshold_factor_rise, int look_ahead, float alpha);
57 
58  gr_peak_detector2_fb (float threshold_factor_rise, int look_ahead, float alpha);
59 
60 private:
61  float d_threshold_factor_rise;
62  int d_look_ahead;
63  int d_look_ahead_remaining;
64  int d_peak_ind;
65  float d_peak_val;
66  float d_alpha;
67  float d_avg;
68  bool d_found;
69 
70 public:
71 
72  /*! \brief Set the threshold factor value for the rise time
73  * \param thr new threshold factor
74  */
75  void set_threshold_factor_rise(float thr) { d_threshold_factor_rise = thr; }
76 
77  /*! \brief Set the look-ahead factor
78  * \param look new look-ahead factor
79  */
80  void set_look_ahead(int look) { d_look_ahead = look; }
81 
82  /*! \brief Set the running average alpha
83  * \param alpha new alpha for running average
84  */
85  void set_alpha(int alpha) { d_alpha = alpha; }
86 
87  /*! \brief Get the threshold factor value for the rise time
88  * \return threshold factor
89  */
90  float threshold_factor_rise() { return d_threshold_factor_rise; }
91 
92  /*! \brief Get the look-ahead factor value
93  * \return look-ahead factor
94  */
95  int look_ahead() { return d_look_ahead; }
96 
97  /*! \brief Get the alpha value of the running average
98  * \return alpha
99  */
100  float alpha() { return d_alpha; }
101 
102  int work (int noutput_items,
103  gr_vector_const_void_star &input_items,
104  gr_vector_void_star &output_items);
105 };
106 
107 #endif
108 
109