Statistics
| Branch: | Tag: | Revision:

root / gnuradio-core / src / lib / gengen / gr_peak_detector_XX.h.t @ 01b6697b

History | View | Annotate | Download (3.9 kB)

1 43819f0f jcorgan
/* -*- c++ -*- */
2 43819f0f jcorgan
/*
3 43819f0f jcorgan
 * Copyright 2007 Free Software Foundation, Inc.
4 43819f0f jcorgan
 * 
5 43819f0f jcorgan
 * This file is part of GNU Radio
6 43819f0f jcorgan
 * 
7 43819f0f jcorgan
 * GNU Radio is free software; you can redistribute it and/or modify
8 43819f0f jcorgan
 * it under the terms of the GNU General Public License as published by
9 937b719d eb
 * the Free Software Foundation; either version 3, or (at your option)
10 43819f0f jcorgan
 * any later version.
11 43819f0f jcorgan
 * 
12 43819f0f jcorgan
 * GNU Radio is distributed in the hope that it will be useful,
13 43819f0f jcorgan
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 43819f0f jcorgan
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 43819f0f jcorgan
 * GNU General Public License for more details.
16 43819f0f jcorgan
 * 
17 43819f0f jcorgan
 * You should have received a copy of the GNU General Public License
18 43819f0f jcorgan
 * along with GNU Radio; see the file COPYING.  If not, write to
19 43819f0f jcorgan
 * the Free Software Foundation, Inc., 51 Franklin Street,
20 43819f0f jcorgan
 * Boston, MA 02110-1301, USA.
21 43819f0f jcorgan
 */
22 43819f0f jcorgan
23 43819f0f jcorgan
// @WARNING@
24 43819f0f jcorgan
25 43819f0f jcorgan
#ifndef @GUARD_NAME@
26 43819f0f jcorgan
#define @GUARD_NAME@
27 43819f0f jcorgan
28 43819f0f jcorgan
#include <gr_sync_block.h>
29 43819f0f jcorgan
30 43819f0f jcorgan
class @NAME@;
31 43819f0f jcorgan
typedef boost::shared_ptr<@NAME@> @SPTR_NAME@;
32 43819f0f jcorgan
33 43819f0f jcorgan
@SPTR_NAME@ gr_make_@BASE_NAME@ (float threshold_factor_rise = 0.25,
34 43819f0f jcorgan
				 float threshold_factor_fall = 0.40,
35 43819f0f jcorgan
				 int look_ahead = 10,
36 43819f0f jcorgan
				 float alpha = 0.001);
37 43819f0f jcorgan
38 43819f0f jcorgan
/*!
39 43819f0f jcorgan
 * \brief Detect the peak of a signal
40 cda71d95 eb
 * \ingroup level
41 43819f0f jcorgan
 *
42 43819f0f jcorgan
 * If a peak is detected, this block outputs a 1, 
43 43819f0f jcorgan
 * or it outputs 0's.
44 43819f0f jcorgan
 *
45 43819f0f jcorgan
 * \param threshold_factor_rise The threshold factor determins when a peak
46 43819f0f jcorgan
 *        has started. An average of the signal is calculated and when the 
47 43819f0f jcorgan
 *        value of the signal goes over threshold_factor_rise*average, we
48 43819f0f jcorgan
 *        start looking for a peak.
49 43819f0f jcorgan
 * \param threshold_factor_fall The threshold factor determins when a peak
50 43819f0f jcorgan
 *        has ended. An average of the signal is calculated and when the 
51 43819f0f jcorgan
 *        value of the signal goes bellow threshold_factor_fall*average, we 
52 43819f0f jcorgan
 *        stop looking for a peak.
53 43819f0f jcorgan
 * \param look_ahead The look-ahead value is used when the threshold is
54 43819f0f jcorgan
 *        found to look if there another peak within this step range.
55 43819f0f jcorgan
 *        If there is a larger value, we set that as the peak and look ahead
56 43819f0f jcorgan
 *        again. This is continued until the highest point is found with
57 43819f0f jcorgan
 *        This look-ahead range.
58 43819f0f jcorgan
 * \param alpha The gain value of a moving average filter
59 43819f0f jcorgan
 */
60 43819f0f jcorgan
class @NAME@ : public gr_sync_block
61 43819f0f jcorgan
{
62 43819f0f jcorgan
  friend @SPTR_NAME@ gr_make_@BASE_NAME@ (float threshold_factor_rise,
63 43819f0f jcorgan
					  float threshold_factor_fall,
64 43819f0f jcorgan
					  int look_ahead, float alpha);
65 43819f0f jcorgan
66 43819f0f jcorgan
  @NAME@ (float threshold_factor_rise, 
67 43819f0f jcorgan
	  float threshold_factor_fall,
68 43819f0f jcorgan
	  int look_ahead, float alpha);
69 43819f0f jcorgan
70 43819f0f jcorgan
 private:
71 43819f0f jcorgan
  float d_threshold_factor_rise;
72 43819f0f jcorgan
  float d_threshold_factor_fall;
73 43819f0f jcorgan
  int d_look_ahead;
74 43819f0f jcorgan
  float d_avg_alpha;
75 43819f0f jcorgan
  float d_avg;
76 43819f0f jcorgan
  unsigned char d_found;
77 43819f0f jcorgan
78 43819f0f jcorgan
 public:
79 43819f0f jcorgan
80 43819f0f jcorgan
  /*! \brief Set the threshold factor value for the rise time
81 43819f0f jcorgan
   *  \param thr new threshold factor
82 43819f0f jcorgan
   */
83 43819f0f jcorgan
  void set_threshold_factor_rise(float thr) { d_threshold_factor_rise = thr; }
84 43819f0f jcorgan
85 43819f0f jcorgan
  /*! \brief Set the threshold factor value for the fall time
86 43819f0f jcorgan
   *  \param thr new threshold factor
87 43819f0f jcorgan
   */
88 43819f0f jcorgan
  void set_threshold_factor_fall(float thr) { d_threshold_factor_fall = thr; }
89 43819f0f jcorgan
90 43819f0f jcorgan
  /*! \brief Set the look-ahead factor
91 43819f0f jcorgan
   *  \param look new look-ahead factor
92 43819f0f jcorgan
   */
93 43819f0f jcorgan
  void set_look_ahead(int look) { d_look_ahead = look; }
94 43819f0f jcorgan
95 43819f0f jcorgan
  /*! \brief Set the running average alpha
96 43819f0f jcorgan
   *  \param alpha new alpha for running average
97 43819f0f jcorgan
   */
98 43819f0f jcorgan
  void set_alpha(int alpha) { d_avg_alpha = alpha; }
99 43819f0f jcorgan
100 43819f0f jcorgan
  /*! \brief Get the threshold factor value for the rise time
101 43819f0f jcorgan
   *  \return threshold factor
102 43819f0f jcorgan
   */
103 43819f0f jcorgan
  float threshold_factor_rise() { return d_threshold_factor_rise; }
104 43819f0f jcorgan
105 43819f0f jcorgan
  /*! \brief Get the threshold factor value for the fall time
106 43819f0f jcorgan
   *  \return threshold factor
107 43819f0f jcorgan
   */
108 43819f0f jcorgan
  float threshold_factor_fall() { return d_threshold_factor_fall; }
109 43819f0f jcorgan
110 43819f0f jcorgan
  /*! \brief Get the look-ahead factor value
111 43819f0f jcorgan
   *  \return look-ahead factor
112 43819f0f jcorgan
   */
113 43819f0f jcorgan
  int look_ahead() { return d_look_ahead; }
114 43819f0f jcorgan
115 43819f0f jcorgan
  /*! \brief Get the alpha value of the running average
116 43819f0f jcorgan
   *  \return alpha
117 43819f0f jcorgan
   */
118 43819f0f jcorgan
  float alpha() { return d_avg_alpha; }
119 43819f0f jcorgan
120 43819f0f jcorgan
  int work (int noutput_items,
121 43819f0f jcorgan
	    gr_vector_const_void_star &input_items,
122 43819f0f jcorgan
	    gr_vector_void_star &output_items);
123 43819f0f jcorgan
};
124 43819f0f jcorgan
125 43819f0f jcorgan
#endif