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.
28 #include <gr_sync_block.h>
31 typedef boost::shared_ptr<@NAME@> @SPTR_NAME@;
33 @SPTR_NAME@ gr_make_@BASE_NAME@ (float threshold_factor_rise = 0.25,
34 float threshold_factor_fall = 0.40,
39 * \brief Detect the peak of a signal
42 * If a peak is detected, this block outputs a 1,
45 * \param threshold_factor_rise The threshold factor determins when a peak
46 * has started. An average of the signal is calculated and when the
47 * value of the signal goes over threshold_factor_rise*average, we
48 * start looking for a peak.
49 * \param threshold_factor_fall The threshold factor determins when a peak
50 * has ended. An average of the signal is calculated and when the
51 * value of the signal goes bellow threshold_factor_fall*average, we
52 * stop looking for a peak.
53 * \param look_ahead The look-ahead value is used when the threshold is
54 * found to look if there another peak within this step range.
55 * If there is a larger value, we set that as the peak and look ahead
56 * again. This is continued until the highest point is found with
57 * This look-ahead range.
58 * \param alpha The gain value of a moving average filter
60 class @NAME@ : public gr_sync_block
62 friend @SPTR_NAME@ gr_make_@BASE_NAME@ (float threshold_factor_rise,
63 float threshold_factor_fall,
64 int look_ahead, float alpha);
66 @NAME@ (float threshold_factor_rise,
67 float threshold_factor_fall,
68 int look_ahead, float alpha);
71 float d_threshold_factor_rise;
72 float d_threshold_factor_fall;
76 unsigned char d_found;
80 /*! \brief Set the threshold factor value for the rise time
81 * \param thr new threshold factor
83 void set_threshold_factor_rise(float thr) { d_threshold_factor_rise = thr; }
85 /*! \brief Set the threshold factor value for the fall time
86 * \param thr new threshold factor
88 void set_threshold_factor_fall(float thr) { d_threshold_factor_fall = thr; }
90 /*! \brief Set the look-ahead factor
91 * \param look new look-ahead factor
93 void set_look_ahead(int look) { d_look_ahead = look; }
95 /*! \brief Set the running average alpha
96 * \param alpha new alpha for running average
98 void set_alpha(int alpha) { d_avg_alpha = alpha; }
100 /*! \brief Get the threshold factor value for the rise time
101 * \return threshold factor
103 float threshold_factor_rise() { return d_threshold_factor_rise; }
105 /*! \brief Get the threshold factor value for the fall time
106 * \return threshold factor
108 float threshold_factor_fall() { return d_threshold_factor_fall; }
110 /*! \brief Get the look-ahead factor value
111 * \return look-ahead factor
113 int look_ahead() { return d_look_ahead; }
115 /*! \brief Get the alpha value of the running average
118 float alpha() { return d_avg_alpha; }
120 int work (int noutput_items,
121 gr_vector_const_void_star &input_items,
122 gr_vector_void_star &output_items);