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.
Public Member Functions | Private Member Functions | Private Attributes | List of all members
PhaseDiscriminators Class Reference

#include <phasediscri.h>

Public Member Functions

void reset ()
 
void setFMScaling (Real fmScaling)
 
Real phaseDiscriminator (const Complex &sample)
 
Real phaseDiscriminatorDelta (const Complex &sample, double &magsq, Real &fmDev)
 
Real phaseDiscriminator2 (const Complex &sample)
 
Real phaseDiscriminator3 (const Complex &sample, long double &magsq, Real &fltVal)
 

Private Member Functions

float atan2_approximation1 (float y, float x)
 
float atan2_approximation2 (float y, float x)
 

Private Attributes

Complex m_m1Sample
 
Complex m_m2Sample
 
Real m_fmScaling
 
Real m_fltPreviousI
 
Real m_fltPreviousQ
 
Real m_fltPreviousI2
 
Real m_fltPreviousQ2
 
Real m_prevArg
 

Detailed Description

Definition at line 27 of file phasediscri.h.

Member Function Documentation

◆ atan2_approximation1()

float PhaseDiscriminators::atan2_approximation1 ( float  y,
float  x 
)
inlineprivate

Definition at line 142 of file phasediscri.h.

References M_PI.

143  {
144  //http://pubs.opengroup.org/onlinepubs/009695399/functions/atan2.html
145  //Volkan SALMA
146 
147  const float ONEQTR_PI = M_PI / 4.0;
148  const float THRQTR_PI = 3.0 * M_PI / 4.0;
149  float r, angle;
150  float abs_y = std::fabs(y) + 1e-10f; // kludge to prevent 0/0 condition
151  if ( x < 0.0f )
152  {
153  r = (x + abs_y) / (abs_y - x);
154  angle = THRQTR_PI;
155  }
156  else
157  {
158  r = (x - abs_y) / (x + abs_y);
159  angle = ONEQTR_PI;
160  }
161  angle += (0.1963f * r * r - 0.9817f) * r;
162  if ( y < 0.0f )
163  return( -angle ); // negate if in quad III or IV
164  else
165  return( angle );
166 
167 
168  }
#define M_PI
Definition: phasediscri.h:25

◆ atan2_approximation2()

float PhaseDiscriminators::atan2_approximation2 ( float  y,
float  x 
)
inlineprivate

Definition at line 173 of file phasediscri.h.

References PI_FLOAT, and PIBY2_FLOAT.

Referenced by phaseDiscriminatorDelta().

174  {
175  if ( x == 0.0f )
176  {
177  if ( y > 0.0f ) return PIBY2_FLOAT;
178  if ( y == 0.0f ) return 0.0f;
179  return -PIBY2_FLOAT;
180  }
181  float atan;
182  float z = y/x;
183  if ( std::fabs( z ) < 1.0f )
184  {
185  atan = z/(1.0f + 0.28f*z*z);
186  if ( x < 0.0f )
187  {
188  if ( y < 0.0f ) return atan - PI_FLOAT;
189  return atan + PI_FLOAT;
190  }
191  }
192  else
193  {
194  atan = PIBY2_FLOAT - z/(z*z + 0.28f);
195  if ( y < 0.0f ) return atan - PI_FLOAT;
196  }
197  return atan;
198  }
#define PI_FLOAT
Definition: phasediscri.h:170
#define PIBY2_FLOAT
Definition: phasediscri.h:171
+ Here is the caller graph for this function:

◆ phaseDiscriminator()

Real PhaseDiscriminators::phaseDiscriminator ( const Complex sample)
inline

Standard discriminator using atan2. On modern processors this is as efficient as the non atan2 one. This is better for high fidelity.

Definition at line 51 of file phasediscri.h.

References m_fmScaling, m_m1Sample, and M_PI.

Referenced by DSDDemod::feed(), UDPSink::feed(), and BFMDemod::feed().

52  {
53  Complex d(std::conj(m_m1Sample) * sample);
54  m_m1Sample = sample;
55  return (std::atan2(d.imag(), d.real()) / M_PI) * m_fmScaling;
56  }
#define M_PI
Definition: phasediscri.h:25
std::complex< Real > Complex
Definition: dsptypes.h:43
+ Here is the caller graph for this function:

◆ phaseDiscriminator2()

Real PhaseDiscriminators::phaseDiscriminator2 ( const Complex sample)
inline

Alternative without atan at the expense of a slight distorsion on very wideband signals http://www.embedded.com/design/configurable-systems/4212086/DSP-Tricks&ndash;Frequency-demodulation-algorithms- in addition it needs scaling by instantaneous magnitude squared and volume (0..10) adjustment factor

Definition at line 86 of file phasediscri.h.

References m_fmScaling, m_m1Sample, and m_m2Sample.

87  {
88  Real ip = sample.real() - m_m2Sample.real();
89  Real qp = sample.imag() - m_m2Sample.imag();
90  Real h1 = m_m1Sample.real() * qp;
91  Real h2 = m_m1Sample.imag() * ip;
92 
94  m_m1Sample = sample;
95 
96  //return ((h1 - h2) / M_PI_2) * m_fmScaling;
97  return (h1 - h2) * m_fmScaling;
98  }
float Real
Definition: dsptypes.h:42

◆ phaseDiscriminator3()

Real PhaseDiscriminators::phaseDiscriminator3 ( const Complex sample,
long double &  magsq,
Real fltVal 
)
inline

Second alternative

Definition at line 103 of file phasediscri.h.

References m_fltPreviousI, m_fltPreviousI2, m_fltPreviousQ, m_fltPreviousQ2, m_fmScaling, and sqrt().

104  {
105  Real fltI = sample.real();
106  Real fltQ = sample.imag();
107  double fltNorm;
108  Real fltNormI;
109  Real fltNormQ;
110  //Real fltVal;
111 
112  magsq = fltI*fltI + fltQ*fltQ;
113  fltNorm = std::sqrt(magsq);
114 
115  fltNormI= fltI/fltNorm;
116  fltNormQ= fltQ/fltNorm;
117 
118  fltVal = m_fltPreviousI*(fltNormQ - m_fltPreviousQ2);
119  fltVal -= m_fltPreviousQ*(fltNormI - m_fltPreviousI2);
120  fltVal += 2.0f;
121  fltVal /= 4.0f; // normally it is /4
122 
125 
126  m_fltPreviousQ = fltNormQ;
127  m_fltPreviousI = fltNormI;
128 
129  return fltVal * m_fmScaling;
130  }
Fixed< IntType, IntBits > sqrt(Fixed< IntType, IntBits > const &x)
Definition: fixed.h:2283
float Real
Definition: dsptypes.h:42
+ Here is the call graph for this function:

◆ phaseDiscriminatorDelta()

Real PhaseDiscriminators::phaseDiscriminatorDelta ( const Complex sample,
double &  magsq,
Real fmDev 
)
inline

Discriminator with phase detection using atan2 and frequency by derivation. This yields a precise deviation to sample rate ratio: Sample rate => +/-1.0

Definition at line 62 of file phasediscri.h.

References atan2_approximation2(), m_fmScaling, M_PI, and m_prevArg.

Referenced by ATVDemod::demod(), WFMDemod::feed(), and NFMDemod::processOneSample().

63  {
64  Real fltI = sample.real();
65  Real fltQ = sample.imag();
66  magsq = fltI*fltI + fltQ*fltQ;
67 
68  Real curArg = atan2_approximation2((float) fltQ, (float) fltI);
69  fmDev = (curArg - m_prevArg) / M_PI;
70  m_prevArg = curArg;
71 
72  if (fmDev < -1.0f) {
73  fmDev += 2.0f;
74  } else if (fmDev > 1.0f) {
75  fmDev -= 2.0f;
76  }
77 
78  return fmDev * m_fmScaling;
79  }
#define M_PI
Definition: phasediscri.h:25
float atan2_approximation2(float y, float x)
Definition: phasediscri.h:173
float Real
Definition: dsptypes.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset()

void PhaseDiscriminators::reset ( )
inline

Reset stored values

Definition at line 33 of file phasediscri.h.

References m_m1Sample, and m_m2Sample.

Referenced by WFMDemod::start(), DSDDemod::start(), UDPSink::start(), NFMDemod::start(), and BFMDemod::start().

34  {
35  m_m1Sample = 0;
36  m_m2Sample = 0;
37  }
+ Here is the caller graph for this function:

◆ setFMScaling()

void PhaseDiscriminators::setFMScaling ( Real  fmScaling)
inline

Member Data Documentation

◆ m_fltPreviousI

Real PhaseDiscriminators::m_fltPreviousI
private

Definition at line 136 of file phasediscri.h.

Referenced by phaseDiscriminator3().

◆ m_fltPreviousI2

Real PhaseDiscriminators::m_fltPreviousI2
private

Definition at line 138 of file phasediscri.h.

Referenced by phaseDiscriminator3().

◆ m_fltPreviousQ

Real PhaseDiscriminators::m_fltPreviousQ
private

Definition at line 137 of file phasediscri.h.

Referenced by phaseDiscriminator3().

◆ m_fltPreviousQ2

Real PhaseDiscriminators::m_fltPreviousQ2
private

Definition at line 139 of file phasediscri.h.

Referenced by phaseDiscriminator3().

◆ m_fmScaling

Real PhaseDiscriminators::m_fmScaling
private

◆ m_m1Sample

Complex PhaseDiscriminators::m_m1Sample
private

Definition at line 133 of file phasediscri.h.

Referenced by phaseDiscriminator(), phaseDiscriminator2(), and reset().

◆ m_m2Sample

Complex PhaseDiscriminators::m_m2Sample
private

Definition at line 134 of file phasediscri.h.

Referenced by phaseDiscriminator2(), and reset().

◆ m_prevArg

Real PhaseDiscriminators::m_prevArg
private

Definition at line 140 of file phasediscri.h.

Referenced by phaseDiscriminatorDelta().


The documentation for this class was generated from the following file: