GNU Radio Manual and C++ API Reference  3.10.9.1
The Free & Open Software Radio Ecosystem
peak_detector.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2007,2013,2018 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * SPDX-License-Identifier: GPL-3.0-or-later
8  *
9  */
10 
11 #ifndef PEAK_DETECTOR_H
12 #define PEAK_DETECTOR_H
13 
14 #include <gnuradio/blocks/api.h>
15 #include <gnuradio/sync_block.h>
16 #include <cstdint>
17 
18 namespace gr {
19 namespace blocks {
20 
21 /*!
22  * \brief Detect the peak of a signal
23  * \ingroup peak_detectors_blk
24  *
25  * \details
26  * If a peak is detected, this block outputs a 1,
27  * or it outputs 0's.
28  */
29 template <class T>
30 class BLOCKS_API peak_detector : virtual public sync_block
31 {
32 public:
33  typedef std::shared_ptr<peak_detector<T>> sptr;
34 
35  /*!
36  * Make a peak detector block.
37  *
38  * \param threshold_factor_rise The threshold factor determines
39  * when a peak has started. An average of the signal is
40  * calculated and when the value of the signal goes over
41  * threshold_factor_rise*average, we start looking for a
42  * peak.
43  * \param threshold_factor_fall The threshold factor determines
44  * when a peak has ended. An average of the signal is
45  * calculated and when the value of the signal goes
46  * below threshold_factor_fall*average, we stop looking
47  * for a peak.
48  * \param look_ahead The look-ahead value is used when the
49  * threshold is found to look if there another peak
50  * within this step range. If there is a larger value,
51  * we set that as the peak and look ahead again. This is
52  * continued until the highest point is found with This
53  * look-ahead range.
54  * \param alpha The gain value of a moving average filter
55  */
56  static sptr make(float threshold_factor_rise = 0.25,
57  float threshold_factor_fall = 0.40,
58  int look_ahead = 10,
59  float alpha = 0.001);
60 
61  /*! \brief Set the threshold factor value for the rise time
62  * \param thr new threshold factor
63  */
64  virtual void set_threshold_factor_rise(float thr) = 0;
65 
66  /*! \brief Set the threshold factor value for the fall time
67  * \param thr new threshold factor
68  */
69  virtual void set_threshold_factor_fall(float thr) = 0;
70 
71  /*! \brief Set the look-ahead factor
72  * \param look new look-ahead factor
73  */
74  virtual void set_look_ahead(int look) = 0;
75 
76  /*! \brief Set the running average alpha
77  * \param alpha new alpha for running average
78  */
79  virtual void set_alpha(float alpha) = 0;
80 
81  /*! \brief Get the threshold factor value for the rise time
82  * \return threshold factor
83  */
84  virtual float threshold_factor_rise() = 0;
85 
86  /*! \brief Get the threshold factor value for the fall time
87  * \return threshold factor
88  */
89  virtual float threshold_factor_fall() = 0;
90 
91  /*! \brief Get the look-ahead factor value
92  * \return look-ahead factor
93  */
94  virtual int look_ahead() = 0;
95 
96  /*! \brief Get the alpha value of the running average
97  * \return alpha
98  */
99  virtual float alpha() = 0;
100 };
101 
105 
106 } /* namespace blocks */
107 } /* namespace gr */
108 
109 #endif /* PEAK_DETECTOR_H */
Detect the peak of a signal.
Definition: peak_detector.h:31
std::shared_ptr< peak_detector< T > > sptr
Definition: peak_detector.h:33
virtual float threshold_factor_rise()=0
Get the threshold factor value for the rise time.
virtual void set_look_ahead(int look)=0
Set the look-ahead factor.
virtual void set_threshold_factor_fall(float thr)=0
Set the threshold factor value for the fall time.
virtual float alpha()=0
Get the alpha value of the running average.
static sptr make(float threshold_factor_rise=0.25, float threshold_factor_fall=0.40, int look_ahead=10, float alpha=0.001)
virtual void set_alpha(float alpha)=0
Set the running average alpha.
virtual int look_ahead()=0
Get the look-ahead factor value.
virtual float threshold_factor_fall()=0
Get the threshold factor value for the fall time.
virtual void set_threshold_factor_rise(float thr)=0
Set the threshold factor value for the rise time.
synchronous 1:1 input to output with history
Definition: sync_block.h:26
#define BLOCKS_API
Definition: gr-blocks/include/gnuradio/blocks/api.h:18
peak_detector< std::int32_t > peak_detector_ib
Definition: peak_detector.h:103
peak_detector< std::int16_t > peak_detector_sb
Definition: peak_detector.h:104
peak_detector< float > peak_detector_fb
Definition: peak_detector.h:102
GNU Radio logging wrapper.
Definition: basic_block.h:29