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::spectrum< T, NFFT > Struct Template Reference

#include <sdr.h>

+ Inheritance diagram for leansdr::spectrum< T, NFFT >:
+ Collaboration diagram for leansdr::spectrum< T, NFFT >:

Public Member Functions

 spectrum (scheduler *sch, pipebuf< complex< T >> &_in, pipebuf< float[NFFT]> &_out)
 
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

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

Private Member Functions

void do_spectrum ()
 

Private Attributes

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

Additional Inherited Members

- Protected Attributes inherited from leansdr::runnable
schedulersch
 

Detailed Description

template<typename T, int NFFT>
struct leansdr::spectrum< T, NFFT >

Definition at line 1813 of file sdr.h.

Constructor & Destructor Documentation

◆ spectrum()

template<typename T , int NFFT>
leansdr::spectrum< T, NFFT >::spectrum ( scheduler sch,
pipebuf< complex< T >> &  _in,
pipebuf< float[NFFT]> &  _out 
)
inline

Definition at line 1815 of file sdr.h.

1817  : runnable(sch, "spectrum"),
1818  decimation(1048576),
1819  kavg(0.1),
1820  decim(1), in(_in),
1821  out(_out),
1822  fft(NFFT),
1823  avgpower(NULL),
1824  phase(0)
1825  {
1826  }
runnable(scheduler *_sch, const char *name)
Definition: framework.h:193
float kavg
Definition: sdr.h:1829
cfft_engine< T > fft
Definition: sdr.h:1895
pipewriter< float[NFFT]> out
Definition: sdr.h:1894
int decimation
Definition: sdr.h:1828
pipereader< complex< T > > in
Definition: sdr.h:1893
scheduler * sch
Definition: framework.h:199

Member Function Documentation

◆ do_spectrum()

template<typename T , int NFFT>
void leansdr::spectrum< T, NFFT >::do_spectrum ( )
inlineprivate

Definition at line 1849 of file sdr.h.

References leansdr::auto_notch< T >::fft, leansdr::auto_notch< T >::slot::i, leansdr::auto_notch< T >::in, leansdr::cfft_engine< T >::inplace(), leansdr::cfft_engine< T >::n, leansdr::auto_notch< T >::out, and leansdr::complex< T >::re.

1850  {
1851  complex<T> data[fft.n];
1852 
1853  if (decim == 1)
1854  {
1855  memcpy(data, in.rd(), fft.n * sizeof(data[0]));
1856  }
1857  else
1858  {
1859  complex<T> *pin = in.rd();
1860 
1861  for (int i = 0; i < fft.n; ++i, pin += decim)
1862  data[i] = *pin;
1863  }
1864 
1865  fft.inplace(data, true);
1866  float power[NFFT];
1867 
1868  for (int i = 0; i < fft.n; ++i)
1869  power[i] = (float)data[i].re * data[i].re + (float)data[i].im * data[i].im;
1870 
1871  if (!avgpower)
1872  {
1873  // Initialize with first spectrum
1874  avgpower = new float[fft.n];
1875  memcpy(avgpower, power, fft.n * sizeof(avgpower[0]));
1876  }
1877 
1878  // Accumulate and low-pass filter
1879  for (int i = 0; i < fft.n; ++i)
1880  avgpower[i] = avgpower[i] * (1 - kavg) + power[i] * kavg;
1881 
1882  // Reuse power[]
1883  for (int i = 0; i < fft.n / 2; ++i)
1884  {
1885  power[i] = 10 * log10f(avgpower[NFFT / 2 + i]);
1886  power[NFFT / 2 + i] = 10 * log10f(avgpower[i]);
1887  }
1888 
1889  memcpy(out.wr(), power, sizeof(power[0]) * NFFT);
1890  out.written(1);
1891  }
float kavg
Definition: sdr.h:1829
cfft_engine< T > fft
Definition: sdr.h:1895
pipewriter< float[NFFT]> out
Definition: sdr.h:1894
int32_t i
Definition: decimators.h:244
pipereader< complex< T > > in
Definition: sdr.h:1893
void written(unsigned long n)
Definition: framework.h:308
+ Here is the call graph for this function:

◆ run()

template<typename T , int NFFT>
void leansdr::spectrum< T, NFFT >::run ( )
inlinevirtual

Reimplemented from leansdr::runnable_common.

Definition at line 1832 of file sdr.h.

References leansdr::auto_notch< T >::decimation, leansdr::auto_notch< T >::fft, leansdr::auto_notch< T >::in, leansdr::cfft_engine< T >::n, leansdr::auto_notch< T >::out, and leansdr::auto_notch< T >::phase.

1833  {
1834  while (in.readable() >= fft.n * decim && out.writable() >= 1)
1835  {
1836  phase += fft.n * decim;
1837 
1838  if (phase >= decimation)
1839  {
1840  phase -= decimation;
1841  do_spectrum();
1842  }
1843 
1844  in.read(fft.n * decim);
1845  }
1846  }
cfft_engine< T > fft
Definition: sdr.h:1895
void do_spectrum()
Definition: sdr.h:1849
pipewriter< float[NFFT]> out
Definition: sdr.h:1894
int decimation
Definition: sdr.h:1828
pipereader< complex< T > > in
Definition: sdr.h:1893

Member Data Documentation

◆ avgpower

template<typename T , int NFFT>
T* leansdr::spectrum< T, NFFT >::avgpower
private

Definition at line 1896 of file sdr.h.

◆ decim

template<typename T , int NFFT>
int leansdr::spectrum< T, NFFT >::decim

Definition at line 1830 of file sdr.h.

◆ decimation

template<typename T , int NFFT>
int leansdr::spectrum< T, NFFT >::decimation

Definition at line 1828 of file sdr.h.

◆ fft

template<typename T , int NFFT>
cfft_engine<T> leansdr::spectrum< T, NFFT >::fft
private

Definition at line 1895 of file sdr.h.

◆ in

template<typename T , int NFFT>
pipereader<complex<T> > leansdr::spectrum< T, NFFT >::in
private

Definition at line 1893 of file sdr.h.

◆ kavg

template<typename T , int NFFT>
float leansdr::spectrum< T, NFFT >::kavg

Definition at line 1829 of file sdr.h.

◆ out

template<typename T , int NFFT>
pipewriter<float[NFFT]> leansdr::spectrum< T, NFFT >::out
private

Definition at line 1894 of file sdr.h.

◆ phase

template<typename T , int NFFT>
int leansdr::spectrum< T, NFFT >::phase
private

Definition at line 1897 of file sdr.h.


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