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 Types | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
NCO Class Reference

#include <nco.h>

Public Member Functions

 NCO ()
 
void setFreq (Real freq, Real sampleRate)
 
void setPhase (int phase)
 
void nextPhase ()
 
Real next ()
 Return next real sample. More...
 
Complex nextIQ ()
 Return next complex sample. More...
 
Complex nextQI ()
 Return next complex sample (reversed) More...
 
void nextIQMul (Real &i, Real &q)
 multiply I,Q separately with next sample More...
 
Real get ()
 Return current real sample (no phase increment) More...
 
Complex getIQ ()
 Return current complex sample (no phase increment) More...
 
void getIQ (Complex &c)
 Sets to the current complex sample (no phase increment) More...
 
Complex getQI ()
 Return current complex sample (no phase increment, reversed) More...
 
void getQI (Complex &c)
 Sets to the current complex sample (no phase increment, reversed) More...
 

Private Types

enum  { TableSize = (1 << 12) }
 

Static Private Member Functions

static void initTable ()
 

Private Attributes

int m_phaseIncrement
 
int m_phase
 

Static Private Attributes

static Real m_table [TableSize]
 
static bool m_tableInitialized = false
 

Detailed Description

Definition at line 25 of file nco.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
TableSize 

Definition at line 27 of file nco.h.

27  {
28  TableSize = (1 << 12),
29  };

Constructor & Destructor Documentation

◆ NCO()

NCO::NCO ( )

Definition at line 42 of file nco.cpp.

References initTable(), m_phase, and m_phaseIncrement.

43 {
44  initTable();
45  m_phase = 0;
46  m_phaseIncrement = 0;
47 }
static void initTable()
Definition: nco.cpp:31
int m_phase
Definition: nco.h:36
int m_phaseIncrement
Definition: nco.h:35
+ Here is the call graph for this function:

Member Function Documentation

◆ get()

float NCO::get ( )

Return current real sample (no phase increment)

Definition at line 84 of file nco.cpp.

References m_phase, and m_table.

85 {
86  return m_table[m_phase];
87 }
int m_phase
Definition: nco.h:36
static Real m_table[TableSize]
Definition: nco.h:30

◆ getIQ() [1/2]

Complex NCO::getIQ ( )

Return current complex sample (no phase increment)

Definition at line 89 of file nco.cpp.

References m_phase, m_table, and TableSize.

90 {
91  return Complex(m_table[m_phase], -m_table[(m_phase + TableSize / 4) % TableSize]);
92 }
int m_phase
Definition: nco.h:36
static Real m_table[TableSize]
Definition: nco.h:30
std::complex< Real > Complex
Definition: dsptypes.h:43

◆ getIQ() [2/2]

void NCO::getIQ ( Complex c)

Sets to the current complex sample (no phase increment)

Definition at line 94 of file nco.cpp.

References m_phase, m_table, and TableSize.

95 {
96  c.real(m_table[m_phase]);
97  c.imag(-m_table[(m_phase + TableSize / 4) % TableSize]);
98 }
int m_phase
Definition: nco.h:36
static Real m_table[TableSize]
Definition: nco.h:30

◆ getQI() [1/2]

Complex NCO::getQI ( )

Return current complex sample (no phase increment, reversed)

Definition at line 100 of file nco.cpp.

References m_phase, m_table, and TableSize.

101 {
102  return Complex(-m_table[(m_phase + TableSize / 4) % TableSize], m_table[m_phase]);
103 }
int m_phase
Definition: nco.h:36
static Real m_table[TableSize]
Definition: nco.h:30
std::complex< Real > Complex
Definition: dsptypes.h:43

◆ getQI() [2/2]

void NCO::getQI ( Complex c)

Sets to the current complex sample (no phase increment, reversed)

Definition at line 105 of file nco.cpp.

References m_phase, m_table, and TableSize.

106 {
107  c.imag(m_table[m_phase]);
108  c.real(-m_table[(m_phase + TableSize / 4) % TableSize]);
109 }
int m_phase
Definition: nco.h:36
static Real m_table[TableSize]
Definition: nco.h:30

◆ initTable()

void NCO::initTable ( )
staticprivate

Definition at line 31 of file nco.cpp.

References cos(), i, M_PI, m_table, m_tableInitialized, and TableSize.

Referenced by NCO().

32 {
34  return;
35 
36  for(int i = 0; i < TableSize; i++)
37  m_table[i] = cos((2.0 * M_PI * i) / TableSize);
38 
39  m_tableInitialized = true;
40 }
Fixed< IntType, IntBits > cos(Fixed< IntType, IntBits > const &x)
Definition: fixed.h:2271
static bool m_tableInitialized
Definition: nco.h:31
int32_t i
Definition: decimators.h:244
static Real m_table[TableSize]
Definition: nco.h:30
#define M_PI
Definition: nco.cpp:26
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ next()

float NCO::next ( )

Return next real sample.

Definition at line 55 of file nco.cpp.

References m_phase, m_table, and nextPhase().

56 {
57  nextPhase();
58  return m_table[m_phase];
59 }
void nextPhase()
Definition: nco.h:44
int m_phase
Definition: nco.h:36
static Real m_table[TableSize]
Definition: nco.h:30
+ Here is the call graph for this function:

◆ nextIQ()

Complex NCO::nextIQ ( )

Return next complex sample.

Definition at line 61 of file nco.cpp.

References m_phase, m_table, nextPhase(), and TableSize.

Referenced by LoRaDemod::feed(), WFMDemod::feed(), AMDemod::feed(), DSDDemod::feed(), UDPSink::feed(), NFMDemod::feed(), BFMDemod::feed(), DATVDemod::feed(), ATVDemod::feed(), UDPSource::pull(), AMMod::pull(), WFMMod::pull(), NFMMod::pull(), and ATVMod::pullFinalize().

62 {
63  nextPhase();
64  return Complex(m_table[m_phase], -m_table[(m_phase + TableSize / 4) % TableSize]);
65 }
void nextPhase()
Definition: nco.h:44
int m_phase
Definition: nco.h:36
static Real m_table[TableSize]
Definition: nco.h:30
std::complex< Real > Complex
Definition: dsptypes.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nextIQMul()

void NCO::nextIQMul ( Real i,
Real q 
)

multiply I,Q separately with next sample

Definition at line 73 of file nco.cpp.

References i, m_phase, m_table, nextPhase(), and TableSize.

74 {
75  nextPhase();
76  Real x = i;
77  Real y = q;
78  const Real& u = m_table[m_phase];
79  const Real& v = -m_table[(m_phase + TableSize / 4) % TableSize];
80  i = x*u - y*v;
81  q = x*v + y*u;
82 }
void nextPhase()
Definition: nco.h:44
int m_phase
Definition: nco.h:36
int32_t i
Definition: decimators.h:244
static Real m_table[TableSize]
Definition: nco.h:30
float Real
Definition: dsptypes.h:42
+ Here is the call graph for this function:

◆ nextPhase()

void NCO::nextPhase ( )
inline

Definition at line 44 of file nco.h.

References i.

Referenced by next(), nextIQ(), nextIQMul(), and nextQI().

45  {
47  while(m_phase >= TableSize)
48  m_phase -= TableSize;
49  while(m_phase < 0)
50  m_phase += TableSize;
51  }
int m_phase
Definition: nco.h:36
int m_phaseIncrement
Definition: nco.h:35
+ Here is the caller graph for this function:

◆ nextQI()

Complex NCO::nextQI ( )

Return next complex sample (reversed)

Definition at line 67 of file nco.cpp.

References m_phase, m_table, nextPhase(), and TableSize.

68 {
69  nextPhase();
71 }
void nextPhase()
Definition: nco.h:44
int m_phase
Definition: nco.h:36
static Real m_table[TableSize]
Definition: nco.h:30
std::complex< Real > Complex
Definition: dsptypes.h:43
+ Here is the call graph for this function:

◆ setFreq()

void NCO::setFreq ( Real  freq,
Real  sampleRate 
)

◆ setPhase()

void NCO::setPhase ( int  phase)
inline

Definition at line 42 of file nco.h.

42 { m_phase = phase; }
int m_phase
Definition: nco.h:36

Member Data Documentation

◆ m_phase

int NCO::m_phase
private

Definition at line 36 of file nco.h.

Referenced by get(), getIQ(), getQI(), NCO(), next(), nextIQ(), nextIQMul(), and nextQI().

◆ m_phaseIncrement

int NCO::m_phaseIncrement
private

Definition at line 35 of file nco.h.

Referenced by NCO(), and setFreq().

◆ m_table

Real NCO::m_table
staticprivate

Definition at line 30 of file nco.h.

Referenced by get(), getIQ(), getQI(), initTable(), next(), nextIQ(), nextIQMul(), and nextQI().

◆ m_tableInitialized

bool NCO::m_tableInitialized = false
staticprivate

Definition at line 31 of file nco.h.

Referenced by initTable().


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