1 #ifndef __SDR_FILTERNODE_HH__
2 #define __SDR_FILTERNODE_HH__
10 #include "buffernode.hh"
17 template <
class Scalar>
18 inline std::complex<Scalar> sinc_flt_kernel(
int i,
int N,
double Fc,
double bw,
double Fs) {
19 std::complex<Scalar> v;
21 if ( (N/2) == i) { v = M_PI*(bw/Fs); }
22 else { v = std::sin(M_PI*(bw/Fs)*(i-N/2))/(i-N/2); }
24 v *= std::exp(std::complex<Scalar>(0.0, (2*M_PI*Fc*i)/Fs));
26 v *= (0.42 - 0.5*cos((2*M_PI*i)/N) + 0.08*cos((4*M_PI*i)/N));
33 template <
class Scalar>
64 err <<
"Can not configure filter-sink: Invalid type " << src_cfg.
type()
65 <<
", expected " << Config::typeId< std::complex<Scalar> >();
71 err <<
"Can not configure filter-sink: Invalid buffer size " << src_cfg.
bufferSize()
81 virtual void process(
const Buffer< std::complex<Scalar> > &buffer,
bool allow_overwrite) {
104 template <
class Scalar>
138 err <<
"Can not configure FilterSource, block-size (=" <<
_block_size
139 <<
") != buffer-size (=" << src_cfg.
bufferSize() <<
")!";
151 msg <<
"Configured FFT Filter: " << std::endl
152 <<
" range: [" << fmin <<
", " << fmax <<
"]" << std::endl
154 <<
" Fc/BW: " << fmin+(fmax-fmin)/2 <<
" / " << (fmax-fmin) << std::endl
164 virtual void process(
const Buffer<std::complex<Scalar> > &buffer,
bool allow_overwrite) {
189 double fmin = std::max(
_fmin, -Fs/2);
190 double fmax = std::min(
_fmax, Fs/2);
191 double bw = fmax-fmin;
192 double Fc = fmin + bw/2;
231 template <
class Scalar>
250 typename std::list< FilterSource<Scalar> *>::iterator item=
_filters.begin();
251 for (; item!=
_filters.end(); item++) {
264 if (fmax < fmin) { std::swap(fmin, fmax); }
287 #endif // __SDR_FILTERNODE_HH__
double _sample_rate
The current sample rate.
Definition: filternode.hh:276
A collection of configuration information that is send by a source to all connected sinks to properga...
Definition: node.hh:35
FFTPlan< Scalar > _plan
The FFT plan for the FFT back-transform.
Definition: filternode.hh:225
void _updateFilter()
Updates the sink-filter.
Definition: filternode.hh:186
FilterSink(size_t block_size)
Constructor, best performance with block-size being a power of 2.
Definition: filternode.hh:38
Performs the overlap-add FFT filtering and back-transform.
Definition: filternode.hh:105
virtual void send(const RawBuffer &buffer, bool allow_overwrite=false)
Sends the given buffer to all connected sinks.
Definition: node.cc:67
Sink< std::complex< Scalar > > * sink() const
The filter sink.
Definition: filternode.hh:257
Typed sink.
Definition: node.hh:192
Definition: autocast.hh:8
size_t numBuffers() const
Returns the max.
Definition: node.hh:89
size_t _block_size
The block size of the filters.
Definition: filternode.hh:274
Definition: operators.hh:9
Performs the FFT forward transform.
Definition: filternode.hh:34
void setFreq(double fmin, double fmax)
Set the frequency range.
Definition: filternode.hh:128
Generic source class.
Definition: node.hh:213
virtual void process(const Buffer< std::complex< Scalar > > &buffer, bool allow_overwrite)
Performs the FFT forward transform.
Definition: filternode.hh:81
A set of buffers, that tracks their usage.
Definition: buffer.hh:288
A simple buffering node, that ensures a fixed buffer size.
Definition: buffernode.hh:18
BufferSet< std::complex< Scalar > > _buffers
The output buffers.
Definition: filternode.hh:219
virtual void setConfig(const Config &config)
Stores the configuration and propergates it if the configuration has been changed.
Definition: node.cc:98
Buffer< std::complex< Scalar > > _out_buffer
The output buffer (transformed).
Definition: filternode.hh:96
Buffer< std::complex< Scalar > > _last_trafo
Holds a copy of the second-half of the last output signal.
Definition: filternode.hh:215
double norm2() const
Returns the norm of the buffer.
Definition: buffer.hh:182
void connect(SinkBase *sink, bool direct=false)
Connect this source to a sink.
Definition: node.cc:87
FFTPlan< Scalar > _plan
The plan for the FFT forward transform.
Definition: filternode.hh:98
Trivial FFT implementation for buffer sizes of N=2**K.
Definition: fftplan.hh:11
double _fmin
The lower frequency range.
Definition: filternode.hh:221
FilterSink< Scalar > * _fft_fwd
The filter sink (forward FFT).
Definition: filternode.hh:280
virtual void process(const Buffer< std::complex< Scalar > > &buffer, bool allow_overwrite)
Performs the FFT filtering and back-transform.
Definition: filternode.hh:164
Buffer< std::complex< Scalar > > _kern
Holds the current filter kernel.
Definition: filternode.hh:217
double _sample_rate
The current sample-rate.
Definition: filternode.hh:209
void log(const LogMessage &message)
Logs a message.
Definition: logger.cc:100
virtual void config(const Config &src_cfg)
Configures the node.
Definition: filternode.hh:56
Type type() const
Returns the type.
Definition: node.hh:71
Buffer< std::complex< Scalar > > _in_buffer
An input buffer.
Definition: filternode.hh:211
static void exec(const Buffer< std::complex< Scalar > > &in, const Buffer< std::complex< Scalar > > &out, FFT::Direction dir)
Performs a FFT transform.
Definition: fftplan.hh:23
static Type typeId()
Returns the type-id of the template type.
void resize(size_t numBuffers)
Resize the buffer set.
Definition: buffer.hh:332
static Logger & get()
Returns the singleton instance of the logger.
Definition: logger.cc:89
std::list< FilterSource< Scalar > * > _filters
The filter bank.
Definition: filternode.hh:282
virtual ~FilterSink()
Destructor.
Definition: filternode.hh:50
Buffer< std::complex< Scalar > > _in_buffer
The input buffer.
Definition: filternode.hh:94
The configuration error class.
Definition: exception.hh:24
A log message.
Definition: logger.hh:22
size_t bufferSize() const
Returns the max.
Definition: node.hh:83
FilterSource< Scalar > * addFilter(double fmin, double fmax)
Adds a filter to the filter bank.
Definition: filternode.hh:262
double _fmax
The upper frequency range.
Definition: filternode.hh:223
virtual ~FilterSource()
Destructor.
Definition: filternode.hh:123
virtual ~FilterNode()
Destructor.
Definition: filternode.hh:248
FilterSource(size_t block_size, double fmin, double fmax)
Constructor.
Definition: filternode.hh:109
void unref()
Dereferences the buffer.
Definition: buffer.cc:63
Buffer< std::complex< Scalar > > _trafo_buffer
A compute buffer.
Definition: filternode.hh:213
size_t _block_size
The block size.
Definition: filternode.hh:92
Buffer< Scalar > getBuffer()
Obtains a free buffer.
Definition: buffer.hh:318
FFT module class, provides static methods to perfrom a FFT directly.
Definition: fftplan.hh:14
BufferNode< std::complex< Scalar > > * _buffer
The input buffer (to ensure buffers of _block_size size.
Definition: filternode.hh:278
virtual void config(const Config &src_cfg)
Configures the filter node.
Definition: filternode.hh:133
A typed buffer.
Definition: buffer.hh:111
FilterNode(size_t block_size=1024)
Constructor.
Definition: filternode.hh:236
double sampleRate() const
Returns the sample rate.
Definition: node.hh:77
A FFT filter bank node wich consists of several filters.
Definition: filternode.hh:232
size_t _block_size
Holds the block size of the filter.
Definition: filternode.hh:207