fsk.hh
#ifndef __SDR_FSK_HH__
#define __SDR_FSK_HH__
#include "node.hh"
#include "traits.hh"
#include "logger.hh"
namespace sdr {
class FSKDetector: public Sink<int16_t>, public Source
{
public:
FSKDetector(float baud, float Fmark, float Fspace);
void config(const Config &src_cfg);
void process(const Buffer<int16_t> &buffer, bool allow_overwrite);
protected:
uint8_t _process(int16_t sample);
protected:
float _baud;
size_t _corrLen;
size_t _lutIdx;
float _Fmark;
float _Fspace;
Buffer< std::complex<float> > _markLUT;
Buffer< std::complex<float> > _spaceLUT;
Buffer< std::complex<float> > _markHist;
Buffer< std::complex<float> > _spaceHist;
Buffer<int8_t> _buffer;
};
template <class Scalar>
class ASKDetector: public Sink<Scalar>, public Source
{
public:
ASKDetector(bool invert=false)
: Sink<Scalar>(), Source(), _invert(invert)
{
// pass...
}
void config(const Config &src_cfg) {
// Check if config is complete
if (!src_cfg.hasType() || !src_cfg.hasSampleRate()) { return; }
// Check if buffer type matches
if (Config::typeId<int16_t>() != src_cfg.type()) {
ConfigError err;
err << "Can not configure ASKDetector: Invalid type " << src_cfg.type()
<< ", expected " << Config::typeId<int16_t>();
throw err;
}
// Allocate output buffer
_buffer = Buffer<uint8_t>(src_cfg.bufferSize());
LogMessage msg(LOG_DEBUG);
msg << "Config ASKDetector node: " << std::endl
<< " threshold: " << 0 << std::endl
<< " invert: " << ( _invert ? "yes" : "no" ) << std::endl
<< " symbol rate: " << src_cfg.sampleRate() << " Hz";
Logger::get().log(msg);
// Forward config.
this->setConfig(Config(Traits<uint8_t>::scalarId, src_cfg.sampleRate(), _buffer.size(), 1));
}
void process(const Buffer<Scalar> &buffer, bool allow_overwrite) {
for (size_t i=0; i<buffer.size(); i++) {
_buffer[i] = ((buffer[i]>0)^_invert);
}
this->send(_buffer.head(buffer.size()), false);
}
protected:
bool _invert;
Buffer<uint8_t> _buffer;
};
class BitStream: public Sink<uint8_t>, public Source
{
public:
typedef enum {
NORMAL,
TRANSITION
} Mode;
public:
BitStream(float baud, Mode mode = TRANSITION);
void config(const Config &src_cfg);
void process(const Buffer<uint8_t> &buffer, bool allow_overwrite);
protected:
float _baud;
Mode _mode;
size_t _corrLen;
Buffer<int8_t> _symbols;
size_t _symIdx;
int32_t _symSum;
int32_t _lastSymSum;
float _phase;
float _omega;
float _omegaMin;
float _omegaMax;
float _pllGain;
uint8_t _lastBits;
Buffer<uint8_t> _buffer;
};
class BitDump : public Sink<uint8_t>
{
public:
BitDump(std::ostream &stream);
void config(const Config &src_cfg);
void process(const Buffer<uint8_t> &buffer, bool allow_overwrite);
protected:
std::ostream &_stream;
};
}
#endif // __SDR_FSK_HH__
sdr::FSKDetector::_markHist
Buffer< std::complex< float > > _markHist
FIR filter buffer.
Definition: fsk.hh:51
sdr::FSKDetector::_spaceHist
Buffer< std::complex< float > > _spaceHist
FIR filter buffer.
Definition: fsk.hh:53
sdr::Config
A collection of configuration information that is send by a source to all connected sinks to properga...
Definition: node.hh:35
sdr::BitStream::_omega
float _omega
Phase velocity.
Definition: fsk.hh:160
sdr::ASKDetector::ASKDetector
ASKDetector(bool invert=false)
Constructor.
Definition: fsk.hh:74
sdr::BitStream::_pllGain
float _pllGain
PLL gain.
Definition: fsk.hh:166
sdr::BitStream::_symIdx
size_t _symIdx
Insertion index for the next symbol.
Definition: fsk.hh:152
sdr::BitStream::_phase
float _phase
Current bit "phase".
Definition: fsk.hh:158
sdr::BitDump::_stream
std::ostream & _stream
The output stream.
Definition: fsk.hh:188
sdr::ASKDetector::_buffer
Buffer< uint8_t > _buffer
The output buffer.
Definition: fsk.hh:117
sdr::BitStream::BitStream
BitStream(float baud, Mode mode=TRANSITION)
Constructor.
Definition: fsk.cc:102
sdr::Source::send
virtual void send(const RawBuffer &buffer, bool allow_overwrite=false)
Sends the given buffer to all connected sinks.
Definition: node.cc:67
sdr::Sink
Typed sink.
Definition: node.hh:192
sdr::FSKDetector::_baud
float _baud
Baudrate of the transmission.
Definition: fsk.hh:37
sdr
Definition: autocast.hh:8
sdr::FSKDetector::process
void process(const Buffer< int16_t > &buffer, bool allow_overwrite)
Needs to be implemented by any sub-type to process the received data.
Definition: fsk.cc:90
sdr::ASKDetector::config
void config(const Config &src_cfg)
Needs to be implemented by any sub-type to check and perform the configuration of the node...
Definition: fsk.hh:80
sdr::Config::hasSampleRate
bool hasSampleRate() const
If true, the configuration has a sample rate.
Definition: node.hh:75
sdr::BitStream::config
void config(const Config &src_cfg)
Needs to be implemented by any sub-type to check and perform the configuration of the node...
Definition: fsk.cc:109
sdr::Source
Generic source class.
Definition: node.hh:213
sdr::BitStream::_mode
Mode _mode
The bit detection mode.
Definition: fsk.hh:146
sdr::BitStream::TRANSITION
Transition mode (i.e. transition -> 0, no transition -> 1).
Definition: fsk.hh:130
sdr::BitStream::_buffer
Buffer< uint8_t > _buffer
Output buffer.
Definition: fsk.hh:170
sdr::BitStream::_symSum
int32_t _symSum
Sum over all received symbol (encoded as -1 & 1).
Definition: fsk.hh:154
sdr::FSKDetector::_Fspace
float _Fspace
Space "tone" frequency.
Definition: fsk.hh:45
sdr::Buffer::size
size_t size() const
Returns the number of elements of type T in this buffer.
Definition: buffer.hh:166
sdr::Config::hasType
bool hasType() const
If true, the configuration has a type.
Definition: node.hh:69
sdr::ASKDetector::_invert
bool _invert
If true the symbol logic is inverted.
Definition: fsk.hh:115
sdr::FSKDetector::_spaceLUT
Buffer< std::complex< float > > _spaceLUT
Space frequency FIR filter LUT.
Definition: fsk.hh:49
sdr::BitStream::_lastBits
uint8_t _lastBits
The last decoded bits (needed for transition mode).
Definition: fsk.hh:168
sdr::FSKDetector::_buffer
Buffer< int8_t > _buffer
Output buffer.
Definition: fsk.hh:55
sdr::FSKDetector::FSKDetector
FSKDetector(float baud, float Fmark, float Fspace)
Constructor.
Definition: fsk.cc:12
sdr::Source::setConfig
virtual void setConfig(const Config &config)
Stores the configuration and propergates it if the configuration has been changed.
Definition: node.cc:98
sdr::BitStream::_baud
float _baud
The baud rate.
Definition: fsk.hh:144
sdr::Buffer::head
Buffer< T > head(size_t n) const
Returns a new view on this buffer.
Definition: buffer.hh:237
sdr::BitStream::_symbols
Buffer< int8_t > _symbols
Last received symbols.
Definition: fsk.hh:150
sdr::Logger::log
void log(const LogMessage &message)
Logs a message.
Definition: logger.cc:100
sdr::Config::type
Type type() const
Returns the type.
Definition: node.hh:71
sdr::BitStream::_omegaMax
float _omegaMax
Maximum phase velocity.
Definition: fsk.hh:164
sdr::BitDump
Trivial node to dump a bit-stream to a std::ostream.
Definition: fsk.hh:176
sdr::Logger::get
static Logger & get()
Returns the singleton instance of the logger.
Definition: logger.cc:89
sdr::BitDump::BitDump
BitDump(std::ostream &stream)
Constructor.
Definition: fsk.cc:208
sdr::ConfigError
The configuration error class.
Definition: exception.hh:24
sdr::LogMessage
A log message.
Definition: logger.hh:22
sdr::Config::bufferSize
size_t bufferSize() const
Returns the max.
Definition: node.hh:83
sdr::ASKDetector::process
void process(const Buffer< Scalar > &buffer, bool allow_overwrite)
Needs to be implemented by any sub-type to process the received data.
Definition: fsk.hh:106
sdr::FSKDetector
Implements the basic FSK/AFSK symbol detection.
Definition: fsk.hh:18
sdr::FSKDetector::_lutIdx
size_t _lutIdx
The current FIR filter LUT index.
Definition: fsk.hh:41
sdr::BitStream::Mode
Mode
Possible bit decoding modes.
Definition: fsk.hh:128
sdr::FSKDetector::config
void config(const Config &src_cfg)
Needs to be implemented by any sub-type to check and perform the configuration of the node...
Definition: fsk.cc:19
sdr::ASKDetector
Rather trivial node to detect mark/space symbols by the amplitude.
Definition: fsk.hh:70
sdr::FSKDetector::_corrLen
size_t _corrLen
The filter lenght.
Definition: fsk.hh:39
sdr::BitStream::NORMAL
Normal mode (i.e. mark -> 1, space -> 0).
Definition: fsk.hh:129
sdr::BitDump::config
void config(const Config &src_cfg)
Needs to be implemented by any sub-type to check and perform the configuration of the node...
Definition: fsk.cc:215
sdr::BitDump::process
void process(const Buffer< uint8_t > &buffer, bool allow_overwrite)
Needs to be implemented by any sub-type to process the received data.
Definition: fsk.cc:229
sdr::FSKDetector::_markLUT
Buffer< std::complex< float > > _markLUT
Mark frequency FIR filter LUT.
Definition: fsk.hh:47
sdr::BitStream::_corrLen
size_t _corrLen
The approximative bit length in samples.
Definition: fsk.hh:148
sdr::Traits
Forward declaration of type tratis template.
Definition: traits.hh:20
sdr::BitStream::_lastSymSum
int32_t _lastSymSum
Last sum over all received symbol (encoded as -1 & 1).
Definition: fsk.hh:156
sdr::BitStream::_omegaMin
float _omegaMin
Minimum phase velocity.
Definition: fsk.hh:162
sdr::BitStream
Decodes a bitstream with the desired baud rate.
Definition: fsk.hh:124
sdr::FSKDetector::_process
uint8_t _process(int16_t sample)
Updates the mark/space FIR filter and returns the sampled symbol.
Definition: fsk.cc:69
sdr::Buffer
A typed buffer.
Definition: buffer.hh:111
sdr::Config::sampleRate
double sampleRate() const
Returns the sample rate.
Definition: node.hh:77
sdr::FSKDetector::_Fmark
float _Fmark
Mark "tone" frequency.
Definition: fsk.hh:43
sdr::BitStream::process
void process(const Buffer< uint8_t > &buffer, bool allow_overwrite)
Needs to be implemented by any sub-type to process the received data.
Definition: fsk.cc:158