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.
phaselock.h
Go to the documentation of this file.
1 // Copyright (C) 2015 F4EXB //
3 // written by Edouard Griffiths //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #include <vector>
20 #include "dsp/dsptypes.h"
21 #include "export.h"
22 
25 {
26 public:
27 
29  static const int pilot_frequency = 19000;
30 
32  struct PpsEvent
33  {
34  quint64 pps_index;
35  quint64 sample_index;
37  };
38 
47  PhaseLock(Real freq, Real bandwidth, Real minsignal);
48 
49  virtual ~PhaseLock()
50  {}
51 
60  void configure(Real freq, Real bandwidth, Real minsignal);
61 
67  void process(const std::vector<Real>& samples_in, std::vector<Real>& samples_out);
68 
76  void process(const Real& sample_in, Real *samples_out);
77  void process(const Real& real_in, const Real& imag_in, Real *samples_out);
78 
80  bool locked() const
81  {
82  return m_lock_cnt >= m_lock_delay;
83  }
84 
87  {
88  return 2 * m_pilot_level;
89  }
90 
91 protected:
99  virtual void processPhase(Real *samples_out) const { (void) samples_out; }
100 
101 private:
102  Real m_minfreq, m_maxfreq;
103  Real m_phasor_b0, m_phasor_a1, m_phasor_a2;
104  Real m_phasor_i1, m_phasor_i2, m_phasor_q1, m_phasor_q2;
105  Real m_loopfilter_b0, m_loopfilter_b1;
113  quint64 m_pps_cnt;
114  quint64 m_sample_cnt;
115  std::vector<PpsEvent> m_pps_events;
116 
117  void process_phasor(Real& phasor_i, Real& phasor_q);
118 };
119 
121 {
122 public:
123  SimplePhaseLock(Real freq, Real bandwidth, Real minsignal) :
124  PhaseLock(freq, bandwidth, minsignal)
125  {}
126 
128  {}
129 
130 protected:
131  virtual void processPhase(Real *samples_out) const
132  {
133  samples_out[0] = m_psin; // f Pilot
134  samples_out[1] = m_pcos; // f Pilot
135  }
136 };
137 
139 {
140 public:
141  StereoPhaseLock(Real freq, Real bandwidth, Real minsignal) :
142  PhaseLock(freq, bandwidth, minsignal)
143  {}
144 
146  {}
147 
148 protected:
149  virtual void processPhase(Real *samples_out) const
150  {
151  samples_out[0] = m_psin; // f Pilot
152  // Generate double-frequency output.
153  // sin(2*x) = 2 * sin(x) * cos(x)
154  samples_out[1] = 2.0 * m_psin * m_pcos; // 2f Pilot sin
155  // cos(2*x) = 2 * cos(x) * cos(x) - 1
156  samples_out[2] = (2.0 * m_pcos * m_pcos) - 1.0; // 2f Pilot cos
157  }
158 };
159 
160 
161 class RDSPhaseLock : public PhaseLock
162 {
163 public:
164  RDSPhaseLock(Real freq, Real bandwidth, Real minsignal) :
165  PhaseLock(freq, bandwidth, minsignal)
166  {}
167 
168  virtual ~RDSPhaseLock()
169  {}
170 
171 protected:
172  virtual void processPhase(Real *samples_out) const
173  {
174  samples_out[0] = m_psin; // Pilot signal (f)
175  // Generate double-frequency output.
176  // sin(2*x) = 2 * sin(x) * cos(x)
177  samples_out[1] = 2.0 * m_psin * m_pcos; // Pilot signal (2f)
178  // cos(2*x) = 2 * cos(x) * cos(x) - 1
179  samples_out[2] = (2.0 * m_pcos * m_pcos) - 1.0; // 2f Pilot cos
180  samples_out[3] = m_phase; // Pilot phase
181  }
182 };
virtual ~PhaseLock()
Definition: phaselock.h:49
bool locked() const
Definition: phaselock.h:80
virtual void processPhase(Real *samples_out) const
Definition: phaselock.h:149
SimplePhaseLock(Real freq, Real bandwidth, Real minsignal)
Definition: phaselock.h:123
Real m_phasor_b0
Definition: phaselock.h:103
std::vector< PpsEvent > m_pps_events
Definition: phaselock.h:115
double block_position
Definition: phaselock.h:36
virtual ~SimplePhaseLock()
Definition: phaselock.h:127
Real m_minsignal
Definition: phaselock.h:108
int m_lock_delay
Definition: phaselock.h:110
Real m_loopfilter_b1
Definition: phaselock.h:105
Real m_psin
Definition: phaselock.h:93
int m_pilot_periods
Definition: phaselock.h:112
Real get_pilot_level() const
Definition: phaselock.h:86
Real m_freq
Definition: phaselock.h:107
Real m_pcos
Definition: phaselock.h:94
Real m_phasor_q2
Definition: phaselock.h:104
virtual void processPhase(Real *samples_out) const
Definition: phaselock.h:99
quint64 m_pps_cnt
Definition: phaselock.h:113
virtual void processPhase(Real *samples_out) const
Definition: phaselock.h:172
quint64 sample_index
Definition: phaselock.h:35
RDSPhaseLock(Real freq, Real bandwidth, Real minsignal)
Definition: phaselock.h:164
int m_lock_cnt
Definition: phaselock.h:111
Real m_pilot_level
Definition: phaselock.h:109
Real m_phase
Definition: phaselock.h:92
Real m_minfreq
Definition: phaselock.h:102
virtual ~RDSPhaseLock()
Definition: phaselock.h:168
Real m_loopfilter_x1
Definition: phaselock.h:106
#define SDRBASE_API
Definition: export.h:40
quint64 m_sample_cnt
Definition: phaselock.h:114
virtual void processPhase(Real *samples_out) const
Definition: phaselock.h:131
float Real
Definition: dsptypes.h:42
virtual ~StereoPhaseLock()
Definition: phaselock.h:145
StereoPhaseLock(Real freq, Real bandwidth, Real minsignal)
Definition: phaselock.h:141