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 | Public Attributes | Private Member Functions | Private Attributes | List of all members
leansdr::cnr_fft< T > Struct Template Reference

#include <sdr.h>

+ Inheritance diagram for leansdr::cnr_fft< T >:
+ Collaboration diagram for leansdr::cnr_fft< T >:

Public Member Functions

 cnr_fft (scheduler *sch, pipebuf< complex< T >> &_in, pipebuf< float > &_out, float _bandwidth, int nfft=4096)
 
void run ()
 
- Public Member Functions inherited from leansdr::runnable
 runnable (scheduler *_sch, const char *name)
 
- Public Member Functions inherited from leansdr::runnable_common
 runnable_common (const char *_name)
 
virtual ~runnable_common ()
 
virtual void shutdown ()
 

Public Attributes

float bandwidth
 
float * freq_tap
 
float tap_multiplier
 
int decimation
 
float kavg
 
- Public Attributes inherited from leansdr::runnable_common
const char * name
 

Private Member Functions

void do_cnr ()
 
float avgslots (int i0, int i1)
 

Private Attributes

pipereader< complex< T > > in
 
pipewriter< float > out
 
cfft_engine< T > fft
 
T * avgpower
 
int phase
 

Additional Inherited Members

- Protected Attributes inherited from leansdr::runnable
schedulersch
 

Detailed Description

template<typename T>
struct leansdr::cnr_fft< T >

Definition at line 1708 of file sdr.h.

Constructor & Destructor Documentation

◆ cnr_fft()

template<typename T>
leansdr::cnr_fft< T >::cnr_fft ( scheduler sch,
pipebuf< complex< T >> &  _in,
pipebuf< float > &  _out,
float  _bandwidth,
int  nfft = 4096 
)
inline

Definition at line 1710 of file sdr.h.

1713  : runnable(sch, "cnr_fft"),
1714  bandwidth(_bandwidth),
1715  freq_tap(NULL),
1716  tap_multiplier(1),
1717  decimation(1048576),
1718  kavg(0.1),
1719  in(_in),
1720  out(_out),
1721  fft(nfft),
1722  avgpower(NULL),
1723  phase(0)
1724  {
1725  if (bandwidth > 0.25)
1726  fail("CNR estimator requires Fsampling > 4x Fsignal");
1727  }
float kavg
Definition: sdr.h:1732
cfft_engine< T > fft
Definition: sdr.h:1806
runnable(scheduler *_sch, const char *name)
Definition: framework.h:193
void fail(const char *s)
Definition: framework.cpp:11
pipewriter< float > out
Definition: sdr.h:1805
float * freq_tap
Definition: sdr.h:1730
scheduler * sch
Definition: framework.h:199
float bandwidth
Definition: sdr.h:1729
pipereader< complex< T > > in
Definition: sdr.h:1804
T * avgpower
Definition: sdr.h:1807
float tap_multiplier
Definition: sdr.h:1730
int decimation
Definition: sdr.h:1731

Member Function Documentation

◆ avgslots()

template<typename T>
float leansdr::cnr_fft< T >::avgslots ( int  i0,
int  i1 
)
inlineprivate

Definition at line 1794 of file sdr.h.

1795  { // i0 <= i1
1796  T s = 0;
1797 
1798  for (int i = i0; i <= i1; ++i)
1799  s += avgpower[i & (fft.n - 1)];
1800 
1801  return s / (i1 - i0 + 1);
1802  }
cfft_engine< T > fft
Definition: sdr.h:1806
int32_t i
Definition: decimators.h:244
uint8_t i0
Definition: decimators.h:244
uint8_t i1
Definition: decimators.h:245
T * avgpower
Definition: sdr.h:1807

◆ do_cnr()

template<typename T>
void leansdr::cnr_fft< T >::do_cnr ( )
inlineprivate

Definition at line 1751 of file sdr.h.

1752  {
1753  float center_freq = freq_tap ? *freq_tap * tap_multiplier : 0;
1754  int icf = floor(center_freq * fft.n + 0.5);
1755  complex<T> *data = new complex<T>[fft.n];
1756  memcpy(data, in.rd(), fft.n * sizeof(data[0]));
1757  fft.inplace(data, true);
1758  T *power = new T[fft.n];
1759 
1760  for (int i = 0; i < fft.n; ++i)
1761  power[i] = data[i].re * data[i].re + data[i].im * data[i].im;
1762 
1763  if (!avgpower)
1764  {
1765  // Initialize with first spectrum
1766  avgpower = new T[fft.n];
1767  memcpy(avgpower, power, fft.n * sizeof(avgpower[0]));
1768  }
1769 
1770  // Accumulate and low-pass filter
1771  for (int i = 0; i < fft.n; ++i)
1772  avgpower[i] = avgpower[i] * (1 - kavg) + power[i] * kavg;
1773 
1774  int bwslots = (bandwidth / 4) * fft.n;
1775 
1776  if (!bwslots)
1777  {
1778  delete[] power;
1779  delete[] data;
1780  return;
1781  }
1782 
1783  // Measure carrier+noise in center band
1784  float c2plusn2 = avgslots(icf - bwslots, icf + bwslots);
1785  // Measure noise left and right of roll-off zones
1786  float n2 = (avgslots(icf - bwslots * 4, icf - bwslots * 3) + avgslots(icf + bwslots * 3, icf + bwslots * 4)) / 2;
1787  float c2 = c2plusn2 - n2;
1788  float cnr = (c2 > 0 && n2 > 0) ? 10 * logf(c2 / n2) / logf(10) : -50;
1789  out.write(cnr);
1790  delete[] power;
1791  delete[] data;
1792  }
float kavg
Definition: sdr.h:1732
cfft_engine< T > fft
Definition: sdr.h:1806
Fixed< IntType, IntBits > floor(Fixed< IntType, IntBits > const &x)
Definition: fixed.h:2301
int32_t i
Definition: decimators.h:244
pipewriter< float > out
Definition: sdr.h:1805
float avgslots(int i0, int i1)
Definition: sdr.h:1794
float * freq_tap
Definition: sdr.h:1730
void write(const T &e)
Definition: framework.h:319
float bandwidth
Definition: sdr.h:1729
pipereader< complex< T > > in
Definition: sdr.h:1804
T * avgpower
Definition: sdr.h:1807
float tap_multiplier
Definition: sdr.h:1730

◆ run()

template<typename T>
void leansdr::cnr_fft< T >::run ( )
inlinevirtual

Reimplemented from leansdr::runnable_common.

Definition at line 1734 of file sdr.h.

1735  {
1736  while (in.readable() >= fft.n && out.writable() >= 1)
1737  {
1738  phase += fft.n;
1739 
1740  if (phase >= decimation)
1741  {
1742  phase -= decimation;
1743  do_cnr();
1744  }
1745 
1746  in.read(fft.n);
1747  }
1748  }
cfft_engine< T > fft
Definition: sdr.h:1806
pipewriter< float > out
Definition: sdr.h:1805
void do_cnr()
Definition: sdr.h:1751
pipereader< complex< T > > in
Definition: sdr.h:1804
int decimation
Definition: sdr.h:1731

Member Data Documentation

◆ avgpower

template<typename T>
T* leansdr::cnr_fft< T >::avgpower
private

Definition at line 1807 of file sdr.h.

◆ bandwidth

template<typename T>
float leansdr::cnr_fft< T >::bandwidth

Definition at line 1729 of file sdr.h.

◆ decimation

template<typename T>
int leansdr::cnr_fft< T >::decimation

Definition at line 1731 of file sdr.h.

Referenced by DATVDemod::InitDATVFramework().

◆ fft

template<typename T>
cfft_engine<T> leansdr::cnr_fft< T >::fft
private

Definition at line 1806 of file sdr.h.

◆ freq_tap

template<typename T>
float* leansdr::cnr_fft< T >::freq_tap

Definition at line 1730 of file sdr.h.

◆ in

template<typename T>
pipereader<complex<T> > leansdr::cnr_fft< T >::in
private

Definition at line 1804 of file sdr.h.

◆ kavg

template<typename T>
float leansdr::cnr_fft< T >::kavg

Definition at line 1732 of file sdr.h.

◆ out

template<typename T>
pipewriter<float> leansdr::cnr_fft< T >::out
private

Definition at line 1805 of file sdr.h.

◆ phase

template<typename T>
int leansdr::cnr_fft< T >::phase
private

Definition at line 1808 of file sdr.h.

◆ tap_multiplier

template<typename T>
float leansdr::cnr_fft< T >::tap_multiplier

Definition at line 1730 of file sdr.h.


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