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.
autocorrector.h
Go to the documentation of this file.
1 // Copyright (C) 2018 Edouard Griffiths, F4EXB //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #ifndef SDRBASE_DSP_AUTOCORRECTOR_H_
19 #define SDRBASE_DSP_AUTOCORRECTOR_H_
20 
21 #include "util/movingaverage.h"
22 
23 template<typename T>
25 {
26 public:
27  AutoCorrector(qint32 intBits);
28  void process(const T& inreal, const T& inimag, qint32& outreal, qint32& outimag);
29  void process(qint32& xreal, qint32& ximag);
30  void setIQCorrection(bool iqCorrection) { m_iqCorrection = iqCorrection; }
31 private:
33  float m_scalef;
42 };
43 
44 template<typename T>
46  m_iqCorrection(false),
47  m_scalef((float) (1<<(intBits-1)))
48 {
49 }
50 
51 template<typename T>
52 void AutoCorrector<T>::process(const T& inreal, const T& inimag, qint32& outreal, qint32& outimag)
53 {
54  outreal = inreal;
55  outimag = inimag;
56  process(outreal, outimag);
57 }
58 
59 template<typename T>
60 void AutoCorrector<T>::process(qint32& xreal, qint32& ximag)
61 {
62  m_iBeta(xreal);
63  m_qBeta(ximag);
64 
65  if (m_iqCorrection)
66  {
67  // DC correction and conversion
68  float xi = (xreal - (int32_t) m_iBeta) / m_scalef;
69  float xq = (ximag - (int32_t) m_qBeta) / m_scalef;
70 
71  // phase imbalance
72  m_avgII(xi*xi); // <I", I">
73  m_avgIQ(xi*xq); // <I", Q">
74 
75 
76  if (m_avgII.asDouble() != 0) {
78  }
79 
80  float yi = xi - m_avgPhi.asDouble()*xq;
81  float yq = xq;
82 
83  // amplitude I/Q imbalance
84  m_avgII2(yi*yi); // <I, I>
85  m_avgQQ2(yq*yq); // <Q, Q>
86 
87  if (m_avgQQ2.asDouble() != 0) {
89  }
90 
91  // final correction
92  float zi = yi;
93  float zq = m_avgAmp.asDouble() * yq;
94 
95  // convert and store
96  xreal = zi * m_scalef;
97  ximag = zq * m_scalef;
98  }
99  else
100  {
101  xreal -= (int32_t) m_iBeta;
102  ximag -= (int32_t) m_qBeta;
103  }
104 }
105 
106 #endif /* SDRBASE_DSP_AUTOCORRECTOR_H_ */
void setIQCorrection(bool iqCorrection)
Definition: autocorrector.h:30
MovingAverageUtil< float, double, 128 > m_avgQQ2
Definition: autocorrector.h:39
MovingAverageUtil< float, double, 128 > m_avgIQ
Definition: autocorrector.h:37
MovingAverageUtil< double, double, 128 > m_avgPhi
Definition: autocorrector.h:40
MovingAverageUtil< double, double, 128 > m_avgAmp
Definition: autocorrector.h:41
MovingAverageUtil< int32_t, int64_t, 1024 > m_iBeta
Definition: autocorrector.h:34
AutoCorrector(qint32 intBits)
Definition: autocorrector.h:45
MovingAverageUtil< float, double, 128 > m_avgII
Definition: autocorrector.h:36
int int32_t
Definition: rtptypes_win.h:45
Fixed< IntType, IntBits > sqrt(Fixed< IntType, IntBits > const &x)
Definition: fixed.h:2283
MovingAverageUtil< int32_t, int64_t, 1024 > m_qBeta
Definition: autocorrector.h:35
MovingAverageUtil< float, double, 128 > m_avgII2
Definition: autocorrector.h:38
double asDouble() const
Definition: movingaverage.h:57
void process(const T &inreal, const T &inimag, qint32 &outreal, qint32 &outimag)
Definition: autocorrector.h:52