Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / lib / general / gr_peak_detector2_fb.h
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_sync_block.h>
27
28 class gr_peak_detector2_fb;
29 typedef boost::shared_ptr<gr_peak_detector2_fb> gr_peak_detector2_fb_sptr;
30
31 gr_peak_detector2_fb_sptr gr_make_peak_detector2_fb (float threshold_factor_rise = 7,
32                                                      int look_ahead = 1000,
33                                                      float alpha = 0.001);
34
35 /*!
36  * \brief Detect the peak of a signal
37  * \ingroup level_blk
38  *
39  * If a peak is detected, this block outputs a 1, 
40  * or it outputs 0's.  A separate debug output may be connected, to
41  * view the internal EWMA described below.
42  *
43  * \param threshold_factor_rise The threshold factor determins when a peak
44  *        is present. An EWMA average of the signal is calculated and when the 
45  *        value of the signal goes over threshold_factor_rise*average, we
46  *        call the peak.
47  * \param look_ahead The look-ahead value is used when the threshold is
48  *        found to locate the peak within this range.
49  * \param alpha The gain value of a single-pole moving average filter
50  */
51
52 class gr_peak_detector2_fb : public gr_sync_block
53 {
54   friend gr_peak_detector2_fb_sptr 
55   gr_make_peak_detector2_fb (float threshold_factor_rise, int look_ahead, float alpha);
56   
57   gr_peak_detector2_fb (float threshold_factor_rise, int look_ahead, float alpha);
58   
59 private:
60   float d_threshold_factor_rise;
61   int d_look_ahead;
62   int d_look_ahead_remaining;
63   int d_peak_ind;
64   float d_peak_val;
65   float d_alpha;
66   float d_avg;
67   bool d_found;
68   
69 public:
70   
71   /*! \brief Set the threshold factor value for the rise time
72    *  \param thr new threshold factor
73    */
74   void set_threshold_factor_rise(float thr) { d_threshold_factor_rise = thr; }
75   
76   /*! \brief Set the look-ahead factor
77    *  \param look new look-ahead factor
78    */
79   void set_look_ahead(int look) { d_look_ahead = look; }
80   
81   /*! \brief Set the running average alpha
82    *  \param alpha new alpha for running average
83    */
84   void set_alpha(int alpha) { d_alpha = alpha; }
85   
86   /*! \brief Get the threshold factor value for the rise time
87    *  \return threshold factor
88    */
89   float threshold_factor_rise() { return d_threshold_factor_rise; }
90   
91   /*! \brief Get the look-ahead factor value
92    *  \return look-ahead factor
93    */
94   int look_ahead() { return d_look_ahead; }
95   
96   /*! \brief Get the alpha value of the running average
97    *  \return alpha
98    */
99   float alpha() { return d_alpha; }
100   
101   int work (int noutput_items,
102             gr_vector_const_void_star &input_items,
103             gr_vector_void_star &output_items);
104 };
105
106 #endif
107
108