SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
agc.h
Go to the documentation of this file.
1 /*
2  * kissagc.h
3  *
4  * Created on: May 12, 2015
5  * Author: f4exb
6  */
7 
8 #ifndef INCLUDE_GPL_DSP_AGC_H_
9 #define INCLUDE_GPL_DSP_AGC_H_
10 
11 #include "movingaverage.h"
12 #include "util/movingaverage.h"
13 #include "export.h"
14 
16 {
17 public:
18  AGC(int historySize, double R);
19  virtual ~AGC();
20 
21  void resize(int historySize, double R);
22  void setOrder(double R) { m_R = R; }
23  Real getValue();
24  Real getAverage();
25  virtual void feed(Complex& ci) = 0;
26 
27 protected:
28  double m_u0;
29  double m_R;
32  int m_count;
33 };
34 
35 
36 class SDRBASE_API MagAGC : public AGC
37 {
38 public:
39  MagAGC(int historySize, double R, double threshold);
40  virtual ~MagAGC();
41  void setSquared(bool squared) { m_squared = squared; }
42  void resize(int historySize, int stepLength, Real R);
43  void setOrder(double R);
44  virtual void feed(Complex& ci);
45  double feedAndGetValue(const Complex& ci);
46  double getMagSq() const { return m_magsq; }
47  void setThreshold(double threshold) { m_threshold = threshold; }
48  void setThresholdEnable(bool enable);
49  void setGate(int gate) { m_gate = gate; m_gateCounter = 0; m_count = 0; }
50  void setStepDownDelay(int stepDownDelay) { m_stepDownDelay = stepDownDelay; m_gateCounter = 0; m_count = 0; }
51  void setClamping(bool clamping) { m_clamping = clamping; }
52  void setClampMax(double clampMax) { m_clampMax = clampMax; }
53  int getStepDownDelay() const { return m_stepDownDelay; }
54  float getStepValue() const;
55  void setHardLimiting(bool hardLimiting) { m_hardLimiting = hardLimiting; }
56 
57 private:
58  bool m_squared;
59  double m_magsq;
60  double m_threshold;
62  int m_gate;
64  double m_stepDelta;
69  bool m_clamping;
70  double m_R2;
71  double m_clampMax;
73 
74  double hardLimiter(double multiplier, double magsq);
75 };
76 
77 template<uint32_t AvgSize>
78 class SimpleAGC
79 {
80 public:
81  SimpleAGC(Real initial, Real cutoff=0, Real clip=0) :
82  m_cutoff(cutoff),
83  m_clip(clip),
84  m_moving_average(AvgSize, initial)
85  {
86  }
87 
88  void resize(Real initial, Real cutoff=0, Real clip=0)
89  {
90  m_cutoff = cutoff;
91  m_clip = clip;
92  m_moving_average.resize(AvgSize, initial);
93  }
94 
95  void resizeNew(uint32_t newSize, Real initial, Real cutoff=0, Real clip=0)
96  {
97  m_cutoff = cutoff;
98  m_clip = clip;
99  m_moving_average.resize(newSize, initial);
100  }
101 
102  void fill(double value)
103  {
104  m_moving_average.fill(value);
105  }
106 
108  {
109  if ((Real) m_moving_average.average() > m_clip) {
110  return (Real) m_moving_average.average();
111  } else {
112  return m_clip;
113  }
114  }
115 
116  void feed(Real value)
117  {
118  if (value > m_cutoff) {
119  m_moving_average.feed(value);
120  }
121  }
122 
123 private:
124  Real m_cutoff; // consider samples only above this level
125  Real m_clip; // never go below this level
126  MovingAverage<double> m_moving_average; // Averaging engine. The stack length conditions the smoothness of AGC.
127  //MovingAverageUtil<Real, double, AvgSize> m_moving_average;
128 };
129 
130 #endif /* INCLUDE_GPL_DSP_AGC_H_ */
int m_gate
power threshold gate in number of samples
Definition: agc.h:62
int m_stepDownCounter
step down transition samples counter
Definition: agc.h:66
void setSquared(bool squared)
Definition: agc.h:41
void setHardLimiting(bool hardLimiting)
Definition: agc.h:55
double m_u0
AGC factor.
Definition: agc.h:28
double m_threshold
squelch on magsq average
Definition: agc.h:60
int m_historySize
Averaging length (attack)
Definition: agc.h:31
Definition: agc.h:36
virtual void feed(Complex &ci)=0
void resize(Real initial, Real cutoff=0, Real clip=0)
Definition: agc.h:88
int m_count
Samples counter.
Definition: agc.h:32
Real getValue()
Definition: agc.h:107
double m_R2
square of ordered magnitude
Definition: agc.h:70
unsigned int uint32_t
Definition: rtptypes_win.h:46
Real m_cutoff
Definition: agc.h:124
void feed(Real value)
Definition: agc.h:116
double m_clampMax
maximum to clamp to as power value
Definition: agc.h:71
SimpleAGC(Real initial, Real cutoff=0, Real clip=0)
Definition: agc.h:81
void resize(int historySize, double R)
Definition: agc.cpp:24
bool m_clamping
clamping active
Definition: agc.h:69
MovingAverage< double > m_moving_average
Definition: agc.h:126
void setClampMax(double clampMax)
Definition: agc.h:52
MovingAverage< double > m_moving_average
Averaging engine. The stack length conditions the smoothness of AGC.
Definition: agc.h:30
Definition: agc.h:78
double m_R
ordered magnitude
Definition: agc.h:29
int m_gateCounter
threshold gate samples counter
Definition: agc.h:67
int m_stepLength
transition step length in number of samples
Definition: agc.h:63
bool m_squared
use squared magnitude (power) to compute AGC value
Definition: agc.h:58
double m_magsq
current squared magnitude (power)
Definition: agc.h:59
int getStepDownDelay() const
Definition: agc.h:53
Definition: agc.h:15
double m_stepDelta
transition step unit by sample
Definition: agc.h:64
void setOrder(double R)
Definition: agc.h:22
void resizeNew(uint32_t newSize, Real initial, Real cutoff=0, Real clip=0)
Definition: agc.h:95
double getMagSq() const
Definition: agc.h:46
void setClamping(bool clamping)
Definition: agc.h:51
void setThreshold(double threshold)
Definition: agc.h:47
int m_stepDownDelay
delay in samples before cutoff (release)
Definition: agc.h:68
void setStepDownDelay(int stepDownDelay)
Definition: agc.h:50
void setGate(int gate)
Definition: agc.h:49
int m_stepUpCounter
step up transition samples counter
Definition: agc.h:65
#define SDRBASE_API
Definition: export.h:40
std::complex< Real > Complex
Definition: dsptypes.h:43
void fill(double value)
Definition: agc.h:102
float Real
Definition: dsptypes.h:42
bool m_thresholdEnable
enable squelch on power threshold
Definition: agc.h:61
bool m_hardLimiting
hard limit multiplier so that resulting sample magnitude does not exceed 1.0
Definition: agc.h:72
Real m_clip
Definition: agc.h:125