1 #ifndef __SDR_PSK31_HH__
2 #define __SDR_PSK31_HH__
6 #include "interpolate.hh"
16 template <
class Scalar>
40 double damping = std::sqrt(2)/2;
42 double tmp = 1. + 2*damping*bw + bw*bw;
48 for (
size_t i=0; i<16; i++) {
_dl[i] = 0; }
80 err <<
"Can not configure BPSK31: Invalid type " << src_cfg.
type()
81 <<
", expected " << Config::typeId< std::complex<Scalar> >();
89 err <<
"Can not configure BPSK31: Input sample rate too low! The BPSK31 node requires at "
90 <<
"least a sample rate of 2000Hz, got " << Fs <<
"Hz";
106 size_t bsize = 1 + int(Fs/31.25);
114 virtual void process(
const Buffer< std::complex<Scalar> > &buffer,
bool allow_overwrite) {
116 while (i<buffer.size()) {
118 while ( (
_mu > 1) && (i<buffer.size()) ) {
122 if (i<buffer.size()) {
173 return (value > 0) ? 1 : -1;
177 inline float _phaseError(
const std::complex<float> &value)
const {
178 float r2 = value.real()*value.real();
179 float i2 = value.imag()*value.imag();
181 if (0 == nrm2) {
return 0; }
182 return -value.real()*value.imag()/nrm2;
190 while (
_P>( 2*M_PI)) {
_P -= 2*M_PI; }
191 while (
_P<(-2*M_PI)) {
_P += 2*M_PI; }
203 while (
_P>( 2*M_PI)) {
_P -= 2*M_PI; }
204 while (
_P<(-2*M_PI)) {
_P += 2*M_PI; }
206 std::complex<float> fac = std::exp(std::complex<float>(0,
_P+
_theta));
208 std::complex<float> sample = fac * std::complex<float>(value.real(), value.imag());
224 float err = std::real(y-x);
225 if (err > 1.0) { err = 1.0; }
226 if (err < -1.0) { err = -1.0; }
324 #endif // __SDR_PSK31_HH__
float _theta
Constant phase shift between real axis and first constellation.
Definition: psk31.hh:260
A collection of configuration information that is send by a source to all connected sinks to properga...
Definition: node.hh:35
Buffer< float > _hist
The last _superSample phases.
Definition: psk31.hh:284
size_t _superSample
Holds the number of phase constellations per bit.
Definition: psk31.hh:238
std::complex< float > _c_2T
Constellation at T=-2 (samples).
Definition: psk31.hh:282
std::complex< float > _p_0T
Phase at T = 0 (samples).
Definition: psk31.hh:272
float _phaseError(const std::complex< float > &value) const
Computes the phase error.
Definition: psk31.hh:177
float _gain_mu
Gain factor of the sub-sampler.
Definition: psk31.hh:258
std::map< uint16_t, char > _code_table
The conversion table.
Definition: psk31.hh:317
std::complex< float > _c_0T
Constellation at T=0 (samples).
Definition: psk31.hh:278
int _currentContellation() const
Returns the current constellation.
Definition: psk31.hh:170
virtual void config(const Config &src_cfg)
Needs to be implemented by any sub-type to check and perform the configuration of the node...
Definition: psk31.hh:72
virtual void send(const RawBuffer &buffer, bool allow_overwrite=false)
Sends the given buffer to all connected sinks.
Definition: node.cc:67
Typed sink.
Definition: node.hh:192
std::complex< float > _p_1T
Phase at T=-1 (samples).
Definition: psk31.hh:274
Definition: autocast.hh:8
Definition: operators.hh:9
bool hasSampleRate() const
If true, the configuration has a sample rate.
Definition: node.hh:75
Generic source class.
Definition: node.hh:213
float _omega_rel
Relative error of the subsample rate.
Definition: psk31.hh:264
A simple BPSK31 "demodulator".
Definition: psk31.hh:17
float _omega
Current sub-sample rate.
Definition: psk31.hh:262
float _Fmax
Upper frequency limit of the carrier PLL.
Definition: psk31.hh:246
Buffer< uint8_t > _buffer
The output buffer.
Definition: psk31.hh:315
Buffer< std::complex< float > > _dl
The delay line for the interpolating sub-sampler.
Definition: psk31.hh:252
int _last_constellation
The last output constellation.
Definition: psk31.hh:288
void _updatePLL(const std::complex< float > &sample)
Updates the PLL (_F and _P).
Definition: psk31.hh:186
bool hasType() const
If true, the configuration has a type.
Definition: node.hh:69
float _Fmin
Lower frequency limit of the carrier PLL.
Definition: psk31.hh:244
float _max_omega
Maximum of the sub-sample rate.
Definition: psk31.hh:268
std::complex< float > _c_1T
Constellation at T=-1 (samples).
Definition: psk31.hh:280
virtual void setConfig(const Config &config)
Stores the configuration and propergates it if the configuration has been changed.
Definition: node.cc:98
virtual ~Varicode()
Destructor.
Definition: psk31.cc:47
virtual void config(const Config &src_cfg)
Configures the node.
Definition: psk31.cc:52
Buffer< uint8_t > _buffer
Output buffer.
Definition: psk31.hh:290
Buffer< T > head(size_t n) const
Returns a new view on this buffer.
Definition: buffer.hh:237
float _mu
Holds the fractional sub-sampling counter.
Definition: psk31.hh:256
virtual ~BPSK31()
Destructor.
Definition: psk31.hh:65
float _F
Frequency of the carrier PLL.
Definition: psk31.hh:242
float _min_omega
Minimum of the sub-sample rate.
Definition: psk31.hh:266
void _errorTracking(const std::complex< float > &sample)
Updates the PPL state (_mu and _omega).
Definition: psk31.hh:216
Type type() const
Returns the type.
Definition: node.hh:71
float _beta
Gain factor of the carrier PLL.
Definition: psk31.hh:250
uint16_t _value
The shift register of the last received bits.
Definition: psk31.hh:313
static Type typeId()
Returns the type-id of the template type.
void _updateSampler(const std::complex< Scalar > &value)
Updates the sub-sampler.
Definition: psk31.hh:197
float _alpha
Gain factor of the carrier PLL.
Definition: psk31.hh:248
Buffer< T > sub(size_t offset, size_t len) const
Returns a new view on this buffer.
Definition: buffer.hh:231
virtual void process(const Buffer< uint8_t > &buffer, bool allow_overwrite)
Converts the input bit stream to ASCII chars.
Definition: psk31.cc:69
The configuration error class.
Definition: exception.hh:24
size_t bufferSize() const
Returns the max.
Definition: node.hh:83
Simple varicode (Huffman code) decoder node.
Definition: psk31.hh:299
size_t _hist_idx
Current phase history index.
Definition: psk31.hh:286
bool _hasTransition() const
Returns true if there is a phase transition at the current sample.
Definition: psk31.hh:164
float _gain_omega
Gain of the sub-sample rate correction.
Definition: psk31.hh:270
float _P
Phase of the carrier PLL.
Definition: psk31.hh:240
std::complex< float > _p_2T
Phase at T=-2 (samples).
Definition: psk31.hh:276
void unref()
Dereferences the buffer.
Definition: buffer.cc:63
Forward declaration of type tratis template.
Definition: traits.hh:20
BPSK31(double dF=0.1)
Constructs a new BPSK31 demodulator.
Definition: psk31.hh:35
virtual void process(const Buffer< std::complex< Scalar > > &buffer, bool allow_overwrite)
Needs to be implemented by any sub-type to process the received data.
Definition: psk31.hh:114
Varicode()
Constructor.
Definition: psk31.cc:7
A typed buffer.
Definition: buffer.hh:111
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
size_t _dl_idx
The current index of the delay line.
Definition: psk31.hh:254