1 #ifndef __SDR_BASEBAND_HH__ 
    2 #define __SDR_BASEBAND_HH__ 
    8 #include "operators.hh" 
    9 #include "freqshift.hh" 
   21 template <
class Scalar>
 
   35   IQBaseBand(
double Fc, 
double width, 
size_t order, 
size_t sub_sample, 
double oFs=0.0)
 
   47   IQBaseBand(
double Fc, 
double Ff, 
double width, 
size_t order, 
size_t sub_sample, 
double oFs=0.0)
 
  120     if (Config::typeId<CScalar>() != src_cfg.
type()) {
 
  122       err << 
"Can not configure IQBaseBand: Invalid type " << src_cfg.
type()
 
  123           << 
", expected " << Config::typeId<CScalar>();
 
  136   virtual void process(
const Buffer< std::complex<Scalar> > &buffer, 
bool allow_overwrite)
 
  138     if (allow_overwrite) {
 
  147       msg << 
"IQBaseBand: Drop buffer: Output buffer still in use.";
 
  180     msg << 
"Configured IQBaseBand node:" << std::endl
 
  182         << 
" sample-rate " << 
_Fs << 
"Hz" << std::endl
 
  183         << 
" center freq " << 
_Fc << 
"Hz" << std::endl
 
  184         << 
" width " << 
_width << 
"Hz" << std::endl
 
  185         << 
" kernel " << 
_kernel << std::endl
 
  186         << 
" in buffer size " << 
_sourceBs << std::endl
 
  187         << 
" sub-sample by " << _sub_sample << std::endl
 
  188         << 
" out buffer size " << buffer_size;
 
  193                            _Fs/_sub_sample, buffer_size, 1));
 
  230     if (
_order == idx) { idx = 0; }
 
  231     for (
size_t i=0; i<
_order; i++, idx++) {
 
  232       if (_order == idx) { idx = 0; }
 
  243     double M = double(
_order)/2.;
 
  247     for (
size_t i=0; i<
_order; i++) {
 
  248       if (_order == 2*i) { alpha[i] = 4*(w/M_PI); }
 
  249       else { alpha[i] = std::sin(w*(i-M))/(w*(i-M)); }
 
  252       alpha[i] *= std::exp(std::complex<double>(0.0, (-2*M_PI*
_Ff*i)/
_Fs));
 
  254       alpha[i] *= (0.42 - 0.5*cos((2*M_PI*i)/_order) + 0.08*cos((4*M_PI*i)/_order));
 
  256       norm += std::abs(alpha[i]);
 
  259     for (
size_t i=0; i<
_order; i++) {
 
  260       _kernel[i] = (double(1<<14) * alpha[i]) / norm;
 
  304 template <
class Scalar>
 
  322   BaseBand(
double Fc, 
double width, 
size_t order, 
size_t sub_sample)
 
  340   BaseBand(
double Fc, 
double Ff, 
double width, 
size_t order, 
size_t sub_sample)
 
  364     if (Config::typeId<Scalar>() != src_cfg.
type()) {
 
  366       err << 
"Can not configure BaseBand: Invalid type " << src_cfg.
type()
 
  367           << 
", expected " << Config::typeId<Scalar>();
 
  384     msg << 
"Configured BaseBand node:" << std::endl
 
  388         << 
" width " << 
_width << 
"Hz" << std::endl
 
  389         << 
" kernel " << 
_kernel << std::endl
 
  390         << 
" in buffer size " << src_cfg.
bufferSize() << std::endl
 
  392         << 
" out buffer size " << buffer_size;
 
  414       msg << 
"BaseBand: Drop buffer: Output buffer still in use.";
 
  427     for (; i<in.
size(); i++) {
 
  454     if (
_order == idx) { idx = 0; }
 
  455     for (
size_t i=0; i<
_order; i++, idx++) {
 
  456       if (_order == idx) { idx = 0; }
 
  468     double M = double(
_order)/2;
 
  470     for (
size_t i=0; i<
_order; i++) {
 
  471       if (_order == (2*i)) { alpha[i] = 1; }
 
  472       else { alpha[i] = std::sin(w*(i-M))/(w*(i-M)); }
 
  476     for (
size_t i=0; i<
_order; i++) {
 
  480       alpha[i] *= (0.42 - 0.5*cos((2*M_PI*(i+1))/(_order+2)) +
 
  481                    0.08*cos((4*M_PI*(i+1))/(_order+2)));
 
  483       norm += std::abs(alpha[i]);
 
  486     for (
size_t i=0; i<
_order; i++) {
 
  533 #endif // __SDR_BASEBAND_HH__ 
FreqShiftBase< Scalar >::CSScalar CSScalar
The complex super scalar. 
Definition: baseband.hh:313
 
virtual ~BaseBand()
Destructor. 
Definition: baseband.hh:352
 
A collection of configuration information that is send by a source to all connected sinks to properga...
Definition: node.hh:35
 
double frequencyShift() const 
Returns the frequency shift. 
Definition: freqshift.hh:51
 
size_t subSample() const 
Returns the sub sampling. 
Definition: baseband.hh:103
 
size_t _ring_offset
The current index of the ring buffer. 
Definition: baseband.hh:280
 
int32_t _width
The filter width. 
Definition: baseband.hh:272
 
std::complex< SScalar > CSScalar
Complex SScalar type. 
Definition: baseband.hh:31
 
size_t _sample_count
The current number of averages. 
Definition: baseband.hh:506
 
double filterFrequency() const 
Returns the filter frequency. 
Definition: baseband.hh:89
 
FreqShiftBase< Scalar >::CScalar CScalar
The complex input scalar. 
Definition: baseband.hh:309
 
void setOrder(size_t o)
(Re-) Sets the filter order. 
Definition: baseband.hh:69
 
virtual void setSampleRate(double Fs)
Sets the sample rate and updates the LUT. 
Definition: freqshift.hh:46
 
virtual void send(const RawBuffer &buffer, bool allow_overwrite=false)
Sends the given buffer to all connected sinks. 
Definition: node.cc:67
 
size_t _sub_sample
The number of sample averages for the sub sampling. 
Definition: baseband.hh:276
 
This class performs several operations on the complex (integral) input stream, it first filters out s...
Definition: baseband.hh:22
 
IQBaseBand(double Fc, double width, size_t order, size_t sub_sample, double oFs=0.0)
Constructor, the filter center frequency Ff equals the given center frequency Fc. ...
Definition: baseband.hh:35
 
void _process(const Buffer< Scalar > &in, const Buffer< CScalar > &out)
Performs the actual procssing. 
Definition: baseband.hh:425
 
Typed sink. 
Definition: node.hh:192
 
Definition: autocast.hh:8
 
double centerFrequency() const 
Returns the center frequency. 
Definition: baseband.hh:82
 
bool isEmpty() const 
Returns true if the buffer is invalid/empty. 
Definition: buffer.hh:77
 
Definition: operators.hh:9
 
void setCenterFrequency(double Fc)
Resets the center frequency. 
Definition: baseband.hh:84
 
virtual void setFrequencyShift(double F)
Sets the frequency shift and updates the LUT. 
Definition: freqshift.hh:53
 
bool hasSampleRate() const 
If true, the configuration has a sample rate. 
Definition: node.hh:75
 
size_t order() const 
Returns the order of the band-pass filter. 
Definition: baseband.hh:67
 
CSScalar _filter_ring()
Applies the filter on the data stored in the ring buffer. 
Definition: baseband.hh:450
 
void _reconfigure()
Reconfigures the node. 
Definition: baseband.hh:156
 
Generic source class. 
Definition: node.hh:213
 
bool _shift_freq
If true, Fc!=0. 
Definition: baseband.hh:511
 
double sampleRate() const 
Returns the sample rate. 
Definition: freqshift.hh:44
 
void setOutputSampleRate(double Fs)
Resets the output sample rate. 
Definition: baseband.hh:110
 
std::complex< SScalar > CSScalar
The complex compute (super) scalar of the input type. 
Definition: freqshift.hh:22
 
size_t size() const 
Returns the number of elements of type T in this buffer. 
Definition: buffer.hh:166
 
bool hasType() const 
If true, the configuration has a type. 
Definition: node.hh:69
 
size_t _sourceBs
Buffer size of the source. 
Definition: baseband.hh:286
 
int32_t _Fs
The input sample rate. 
Definition: baseband.hh:270
 
size_t _ring_offset
The current index of the ring buffer. 
Definition: baseband.hh:503
 
int32_t SScalar
The (real) computation scalar type (super scalar), the computations are performed with this scalar ty...
Definition: baseband.hh:29
 
virtual void setSampleRate(double Fs)
Sets the sample rate and updates the LUT. 
Definition: baseband.hh:400
 
void _update_filter_kernel()
Updates the band-pass filter kernel. 
Definition: baseband.hh:239
 
virtual void setConfig(const Config &config)
Stores the configuration and propergates it if the configuration has been changed. 
Definition: node.cc:98
 
double _oFs
Holds the desired output sample rate, _sub_sample will be adjusted accordingly. 
Definition: baseband.hh:278
 
size_t _order
The order of the filter. 
Definition: baseband.hh:274
 
BaseBand(double Fc, double width, size_t order, size_t sub_sample)
Constructs a new BaseBand instance. 
Definition: baseband.hh:322
 
CSScalar _last
The current sum of the last _sample_count samples. 
Definition: baseband.hh:508
 
Buffer< CScalar > _buffer
The output buffer. 
Definition: baseband.hh:293
 
IQBaseBand(double Fc, double Ff, double width, size_t order, size_t sub_sample, double oFs=0.0)
Constructor. 
Definition: baseband.hh:47
 
Buffer< T > head(size_t n) const 
Returns a new view on this buffer. 
Definition: buffer.hh:237
 
void _process(const Buffer< CScalar > &in, const Buffer< CScalar > &out)
Performs the base-band selection, frequency shift and sub-sampling. 
Definition: baseband.hh:198
 
std::complex< Scalar > CScalar
The complex input signal. 
Definition: freqshift.hh:18
 
virtual ~IQBaseBand()
Destructor. 
Definition: baseband.hh:59
 
int32_t _Ff
The center frequency of the base band. 
Definition: baseband.hh:268
 
void _update_filter_kernel()
Calculates or updates the filter kernel. 
Definition: baseband.hh:463
 
void log(const LogMessage &message)
Logs a message. 
Definition: logger.cc:100
 
void setFilterFrequency(double Ff)
(Re-) Sets the filter frequency. 
Definition: baseband.hh:91
 
Type type() const 
Returns the type. 
Definition: node.hh:71
 
Buffer< CSScalar > _ring
A ring buffer of past values. 
Definition: baseband.hh:291
 
virtual void process(const Buffer< Scalar > &buffer, bool allow_overwrite)
Processes the input buffer. 
Definition: baseband.hh:407
 
Traits< Scalar >::SScalar SScalar
The compute (super) scalar of the input type. 
Definition: freqshift.hh:20
 
static Logger & get()
Returns the singleton instance of the logger. 
Definition: logger.cc:89
 
size_t _sample_count
Holds the current number of samples averaged. 
Definition: baseband.hh:282
 
Buffer< CScalar > _buffer
The output buffer. 
Definition: baseband.hh:524
 
A performant implementation of a frequency-shift operation on integer signals. 
Definition: freqshift.hh:14
 
int32_t _Fc
The frequency shift of the base band. 
Definition: baseband.hh:266
 
virtual void config(const Config &src_cfg)
Configures the BaseBand node. 
Definition: baseband.hh:115
 
size_t _order
The order of the band pass filter. 
Definition: baseband.hh:499
 
The configuration error class. 
Definition: exception.hh:24
 
Buffer< CSScalar > _lut
 look-up table 
Definition: baseband.hh:513
 
A log message. 
Definition: logger.hh:22
 
size_t bufferSize() const 
Returns the max. 
Definition: node.hh:83
 
std::complex< Scalar > CScalar
The complex type of the input stream. 
Definition: baseband.hh:26
 
void setSubsample(size_t sub_sample)
Resets the sub sampling. 
Definition: baseband.hh:105
 
size_t _lut_count
The current LUT index times (1<<4). 
Definition: baseband.hh:517
 
static const size_t _lut_size
Size of the look-up table. 
Definition: baseband.hh:528
 
FreqShiftBase< Scalar >::SScalar SScalar
The real super scalar. 
Definition: baseband.hh:311
 
This class performs several operations on the real input stream, It first filters out some part of th...
Definition: baseband.hh:305
 
CSScalar applyFrequencyShift(CSScalar value)
Performs the frequency shift on a single sample. 
Definition: freqshift.hh:58
 
size_t _sub_sample
The number of averages taken for subsampling. 
Definition: baseband.hh:501
 
double _Ff
The center frequency of the band pass filter. 
Definition: baseband.hh:495
 
void unref()
Dereferences the buffer. 
Definition: buffer.cc:63
 
bool isUnused() const 
We assume here that buffers are owned by one object: A buffer is therefore "unused" if the owner hold...
Definition: buffer.hh:87
 
BaseBand(double Fc, double Ff, double width, size_t order, size_t sub_sample)
Constructs a new BaseBand instance. 
Definition: baseband.hh:340
 
Forward declaration of type tratis template. 
Definition: traits.hh:20
 
Buffer< CSScalar > _kernel
The filter kernel of order _order. 
Definition: baseband.hh:289
 
virtual void process(const Buffer< std::complex< Scalar > > &buffer, bool allow_overwrite)
Processes the given buffer. 
Definition: baseband.hh:136
 
CSScalar _last
Holds the current sum of the last _sample_count samples. 
Definition: baseband.hh:284
 
double filterWidth() const 
Returns the filter width. 
Definition: baseband.hh:96
 
double _width
The width of the band pass filter. 
Definition: baseband.hh:497
 
size_t _lut_inc
The LUT index increment per (1<<4) samples. 
Definition: baseband.hh:515
 
Buffer< CSScalar > _kernel
The filter kernel of order _order. 
Definition: baseband.hh:520
 
CSScalar _filter_ring() const 
Applies the filter on the data stored in the ring buffer. 
Definition: baseband.hh:226
 
Buffer< SScalar > _ring
A ring buffer of past values. 
Definition: baseband.hh:522
 
bool hasBufferSize() const 
If true, the configuration has a buffer size. 
Definition: node.hh:81
 
double sampleRate() const 
Returns the sample rate. 
Definition: node.hh:77
 
void setFilterWidth(double width)
Sets the filter width. 
Definition: baseband.hh:98
 
virtual void config(const Config &src_cfg)
Configures the base band node. 
Definition: baseband.hh:360