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.
phaselockcomplex.h
Go to the documentation of this file.
1 // Copyright (C) 2018 F4EXB //
3 // written by Edouard Griffiths //
4 // //
5 // See: http://liquidsdr.org/blog/pll-howto/ //
6 // Fixed filter registers saturation //
7 // Added order for PSK locking. This brilliant idea actually comes from this //
8 // post: https://www.dsprelated.com/showthread/comp.dsp/36356-1.php //
9 // //
10 // This program is free software; you can redistribute it and/or modify //
11 // it under the terms of the GNU General Public License as published by //
12 // the Free Software Foundation as version 3 of the License, or //
13 // (at your option) any later version. //
14 // //
15 // This program is distributed in the hope that it will be useful, //
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
18 // GNU General Public License V3 for more details. //
19 // //
20 // You should have received a copy of the GNU General Public License //
21 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
23 
24 #ifndef SDRBASE_DSP_PHASELOCKCOMPLEX_H_
25 #define SDRBASE_DSP_PHASELOCKCOMPLEX_H_
26 
27 #include "dsp/dsptypes.h"
28 #include "export.h"
29 
32 {
33 public:
40  void computeCoefficients(Real wn, Real zeta, Real K);
44  void setPskOrder(unsigned int order);
46  void setSampleRate(unsigned int sampleRate);
47  void reset();
49  void feed(float re, float im);
50  const std::complex<float>& getComplex() const { return m_y; }
51  float getReal() const { return m_yRe; }
52  float getImag() const { return m_yIm; }
53  bool locked() const { return m_pskOrder > 1 ? m_lockCount > 10 : m_lockCount > m_lockTime-2; }
54  float getFreq() const { return m_freq; }
55  float getDeltaPhi() const { return m_deltaPhi; }
56  float getPhiHat() const { return m_phiHat; }
57 
58 private:
59  class ExpAvg
60  {
61  public:
62  ExpAvg() : m_a0(0.999), m_a1(0.001), m_y1(0.0f)
63  {}
64  void setAlpha(const float& alpha)
65  {
66  m_a0 = alpha;
67  m_a1 = 1.0 - alpha;
68  }
69  float feed(const float& x)
70  {
71  float y = m_a1*x + m_a0*m_y1;
72  m_y1 = y;
73  return y;
74  }
75  private:
76  float m_a0;
77  float m_a1;
78  float m_y1;
79  };
80 
82  static float normalizeAngle(float angle);
83 
84  // a0 = 1 is implied
85  float m_a1;
86  float m_a2;
87  float m_b0;
88  float m_b1;
89  float m_b2;
90  float m_v0;
91  float m_v1;
92  float m_v2;
93  float m_deltaPhi;
94  float m_phiHat;
95  float m_phiHatPrev;
96  std::complex<float> m_y;
97  std::complex<float> m_p;
98  float m_yRe;
99  float m_yIm;
100  float m_freq;
101  float m_freqPrev;
102  float m_freqTest;
104  float m_lockFreq;
105  unsigned int m_pskOrder;
109 };
110 
111 #endif /* SDRBASE_DSP_PHASELOCKCOMPLEX_H_ */
float getDeltaPhi() const
float getPhiHat() const
float getFreq() const
std::complex< float > m_y
unsigned int m_pskOrder
const std::complex< float > & getComplex() const
void setAlpha(const float &alpha)
std::complex< float > m_p
bool locked() const
float feed(const float &x)
#define SDRBASE_API
Definition: export.h:40
float getImag() const
float Real
Definition: dsptypes.h:42
float getReal() const