2020-06-10 04:13:56 +02:00
|
|
|
#pragma once
|
2020-11-02 03:57:44 +01:00
|
|
|
#include <dsp/block.h>
|
2020-11-12 00:53:38 +01:00
|
|
|
#include <volk/volk.h>
|
2021-02-20 15:27:43 +01:00
|
|
|
#include <dsp/filter.h>
|
|
|
|
#include <dsp/processing.h>
|
2021-03-20 21:53:44 +01:00
|
|
|
#include <dsp/routing.h>
|
2020-11-02 21:13:28 +01:00
|
|
|
#include <spdlog/spdlog.h>
|
2021-03-29 21:53:43 +02:00
|
|
|
#include <dsp/pll.h>
|
|
|
|
#include <dsp/clock_recovery.h>
|
2021-04-16 19:53:47 +02:00
|
|
|
#include <dsp/math.h>
|
2020-11-02 21:13:28 +01:00
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
#define FAST_ATAN2_COEF1 FL_M_PI / 4.0f
|
|
|
|
#define FAST_ATAN2_COEF2 3.0f * FAST_ATAN2_COEF1
|
2020-06-15 15:53:45 +02:00
|
|
|
|
2020-06-22 16:45:57 +02:00
|
|
|
inline float fast_arctan2(float y, float x) {
|
2020-11-02 03:57:44 +01:00
|
|
|
float abs_y = fabsf(y);
|
|
|
|
float r, angle;
|
|
|
|
if (x == 0.0f && y == 0.0f) { return 0.0f; }
|
|
|
|
if (x>=0.0f) {
|
|
|
|
r = (x - abs_y) / (x + abs_y);
|
|
|
|
angle = FAST_ATAN2_COEF1 - FAST_ATAN2_COEF1 * r;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = (x + abs_y) / (abs_y - x);
|
|
|
|
angle = FAST_ATAN2_COEF2 - FAST_ATAN2_COEF1 * r;
|
|
|
|
}
|
|
|
|
if (y < 0.0f) {
|
|
|
|
return -angle;
|
|
|
|
}
|
2021-04-01 16:54:16 +02:00
|
|
|
return angle;
|
2020-06-15 15:53:45 +02:00
|
|
|
}
|
2020-06-10 04:13:56 +02:00
|
|
|
|
2020-06-22 16:45:57 +02:00
|
|
|
namespace dsp {
|
2021-02-20 15:27:43 +01:00
|
|
|
class FloatFMDemod : public generic_block<FloatFMDemod> {
|
|
|
|
public:
|
|
|
|
FloatFMDemod() {}
|
|
|
|
|
|
|
|
FloatFMDemod(stream<complex_t>* in, float sampleRate, float deviation) { init(in, sampleRate, deviation); }
|
|
|
|
|
|
|
|
void init(stream<complex_t>* in, float sampleRate, float deviation) {
|
|
|
|
_in = in;
|
|
|
|
_sampleRate = sampleRate;
|
|
|
|
_deviation = deviation;
|
|
|
|
phasorSpeed = (2 * FL_M_PI) / (_sampleRate / _deviation);
|
|
|
|
generic_block<FloatFMDemod>::registerInput(_in);
|
|
|
|
generic_block<FloatFMDemod>::registerOutput(&out);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setInput(stream<complex_t>* in) {
|
|
|
|
std::lock_guard<std::mutex> lck(generic_block<FloatFMDemod>::ctrlMtx);
|
|
|
|
generic_block<FloatFMDemod>::tempStop();
|
|
|
|
generic_block<FloatFMDemod>::unregisterInput(_in);
|
|
|
|
_in = in;
|
|
|
|
generic_block<FloatFMDemod>::registerInput(_in);
|
|
|
|
generic_block<FloatFMDemod>::tempStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setSampleRate(float sampleRate) {
|
|
|
|
std::lock_guard<std::mutex> lck(generic_block<FloatFMDemod>::ctrlMtx);
|
|
|
|
generic_block<FloatFMDemod>::tempStop();
|
|
|
|
_sampleRate = sampleRate;
|
|
|
|
phasorSpeed = (2 * FL_M_PI) / (_sampleRate / _deviation);
|
|
|
|
generic_block<FloatFMDemod>::tempStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
float getSampleRate() {
|
|
|
|
return _sampleRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setDeviation(float deviation) {
|
|
|
|
std::lock_guard<std::mutex> lck(generic_block<FloatFMDemod>::ctrlMtx);
|
|
|
|
generic_block<FloatFMDemod>::tempStop();
|
|
|
|
_deviation = deviation;
|
|
|
|
phasorSpeed = (2 * FL_M_PI) / (_sampleRate / _deviation);
|
|
|
|
generic_block<FloatFMDemod>::tempStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
float getDeviation() {
|
|
|
|
return _deviation;
|
|
|
|
}
|
|
|
|
|
|
|
|
int run() {
|
2021-03-29 21:53:43 +02:00
|
|
|
int count = _in->read();
|
2021-02-20 15:27:43 +01:00
|
|
|
if (count < 0) { return -1; }
|
|
|
|
|
|
|
|
// This is somehow faster than volk...
|
|
|
|
float diff, currentPhase;
|
|
|
|
for (int i = 0; i < count; i++) {
|
2021-03-29 21:53:43 +02:00
|
|
|
currentPhase = fast_arctan2(_in->readBuf[i].im, _in->readBuf[i].re);
|
2021-02-20 15:27:43 +01:00
|
|
|
diff = currentPhase - phase;
|
|
|
|
if (diff > 3.1415926535f) { diff -= 2 * 3.1415926535f; }
|
|
|
|
else if (diff <= -3.1415926535f) { diff += 2 * 3.1415926535f; }
|
|
|
|
out.writeBuf[i] = diff / phasorSpeed;
|
|
|
|
phase = currentPhase;
|
|
|
|
}
|
|
|
|
|
|
|
|
_in->flush();
|
|
|
|
if (!out.swap(count)) { return -1; }
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream<float> out;
|
|
|
|
|
|
|
|
private:
|
2021-03-29 21:53:43 +02:00
|
|
|
float phase = 0;
|
|
|
|
float phasorSpeed, _sampleRate, _deviation;
|
2021-02-20 15:27:43 +01:00
|
|
|
stream<complex_t>* _in;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
class FMDemod : public generic_block<FMDemod> {
|
2020-06-10 04:13:56 +02:00
|
|
|
public:
|
2020-11-02 03:57:44 +01:00
|
|
|
FMDemod() {}
|
2020-06-10 18:52:07 +02:00
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
FMDemod(stream<complex_t>* in, float sampleRate, float deviation) { init(in, sampleRate, deviation); }
|
2020-06-10 04:13:56 +02:00
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
void init(stream<complex_t>* in, float sampleRate, float deviation) {
|
|
|
|
_in = in;
|
|
|
|
_sampleRate = sampleRate;
|
|
|
|
_deviation = deviation;
|
2020-11-04 00:42:39 +01:00
|
|
|
phasorSpeed = (2 * FL_M_PI) / (_sampleRate / _deviation);
|
2020-11-02 03:57:44 +01:00
|
|
|
generic_block<FMDemod>::registerInput(_in);
|
|
|
|
generic_block<FMDemod>::registerOutput(&out);
|
2020-06-15 15:53:45 +02:00
|
|
|
}
|
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
void setInput(stream<complex_t>* in) {
|
|
|
|
std::lock_guard<std::mutex> lck(generic_block<FMDemod>::ctrlMtx);
|
|
|
|
generic_block<FMDemod>::tempStop();
|
2020-11-02 17:48:17 +01:00
|
|
|
generic_block<FMDemod>::unregisterInput(_in);
|
2020-11-02 03:57:44 +01:00
|
|
|
_in = in;
|
2020-11-02 17:48:17 +01:00
|
|
|
generic_block<FMDemod>::registerInput(_in);
|
2020-11-02 03:57:44 +01:00
|
|
|
generic_block<FMDemod>::tempStart();
|
2020-06-22 16:45:57 +02:00
|
|
|
}
|
|
|
|
|
2020-07-19 15:59:44 +02:00
|
|
|
void setSampleRate(float sampleRate) {
|
2020-11-02 03:57:44 +01:00
|
|
|
std::lock_guard<std::mutex> lck(generic_block<FMDemod>::ctrlMtx);
|
|
|
|
generic_block<FMDemod>::tempStop();
|
2020-07-19 15:59:44 +02:00
|
|
|
_sampleRate = sampleRate;
|
2020-11-04 00:42:39 +01:00
|
|
|
phasorSpeed = (2 * FL_M_PI) / (_sampleRate / _deviation);
|
2020-11-02 03:57:44 +01:00
|
|
|
generic_block<FMDemod>::tempStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
float getSampleRate() {
|
|
|
|
return _sampleRate;
|
2020-07-19 15:59:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void setDeviation(float deviation) {
|
|
|
|
_deviation = deviation;
|
2020-11-04 00:42:39 +01:00
|
|
|
phasorSpeed = (2 * FL_M_PI) / (_sampleRate / _deviation);
|
2020-11-02 03:57:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
float getDeviation() {
|
|
|
|
return _deviation;
|
2020-07-19 15:59:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
int run() {
|
2021-03-29 21:53:43 +02:00
|
|
|
int count = _in->read();
|
2020-11-02 03:57:44 +01:00
|
|
|
if (count < 0) { return -1; }
|
2020-06-10 04:13:56 +02:00
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
// This is somehow faster than volk...
|
|
|
|
|
|
|
|
float diff, currentPhase;
|
|
|
|
for (int i = 0; i < count; i++) {
|
2021-03-29 21:53:43 +02:00
|
|
|
currentPhase = fast_arctan2(_in->readBuf[i].im, _in->readBuf[i].re);
|
2020-11-02 03:57:44 +01:00
|
|
|
diff = currentPhase - phase;
|
2020-11-04 00:42:39 +01:00
|
|
|
if (diff > 3.1415926535f) { diff -= 2 * 3.1415926535f; }
|
|
|
|
else if (diff <= -3.1415926535f) { diff += 2 * 3.1415926535f; }
|
2021-02-20 15:27:43 +01:00
|
|
|
out.writeBuf[i].l = diff / phasorSpeed;
|
|
|
|
out.writeBuf[i].r = diff / phasorSpeed;
|
2020-11-02 03:57:44 +01:00
|
|
|
phase = currentPhase;
|
2020-06-10 04:13:56 +02:00
|
|
|
}
|
2020-11-02 03:57:44 +01:00
|
|
|
|
|
|
|
_in->flush();
|
2020-12-25 16:58:07 +01:00
|
|
|
if (!out.swap(count)) { return -1; }
|
2020-11-02 03:57:44 +01:00
|
|
|
return count;
|
2020-06-10 04:13:56 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 15:27:43 +01:00
|
|
|
stream<stereo_t> out;
|
2020-06-15 15:53:45 +02:00
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
private:
|
2021-03-29 21:53:43 +02:00
|
|
|
float phase = 0;
|
|
|
|
float phasorSpeed, _sampleRate, _deviation;
|
2020-11-02 03:57:44 +01:00
|
|
|
stream<complex_t>* _in;
|
2020-06-15 15:53:45 +02:00
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class AMDemod : public generic_block<AMDemod> {
|
2020-06-15 15:53:45 +02:00
|
|
|
public:
|
2020-11-02 03:57:44 +01:00
|
|
|
AMDemod() {}
|
2020-06-15 15:53:45 +02:00
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
AMDemod(stream<complex_t>* in) { init(in); }
|
2020-06-15 15:53:45 +02:00
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
void init(stream<complex_t>* in) {
|
|
|
|
_in = in;
|
|
|
|
generic_block<AMDemod>::registerInput(_in);
|
|
|
|
generic_block<AMDemod>::registerOutput(&out);
|
2020-06-15 15:53:45 +02:00
|
|
|
}
|
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
void setInput(stream<complex_t>* in) {
|
|
|
|
std::lock_guard<std::mutex> lck(generic_block<AMDemod>::ctrlMtx);
|
|
|
|
generic_block<AMDemod>::tempStop();
|
2020-11-02 17:48:17 +01:00
|
|
|
generic_block<AMDemod>::unregisterInput(_in);
|
2020-11-02 03:57:44 +01:00
|
|
|
_in = in;
|
2020-11-02 17:48:17 +01:00
|
|
|
generic_block<AMDemod>::registerInput(_in);
|
2020-11-02 03:57:44 +01:00
|
|
|
generic_block<AMDemod>::tempStart();
|
2020-06-15 15:53:45 +02:00
|
|
|
}
|
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
int run() {
|
2021-03-29 21:53:43 +02:00
|
|
|
int count = _in->read();
|
2020-11-02 03:57:44 +01:00
|
|
|
if (count < 0) { return -1; }
|
|
|
|
|
2020-12-25 16:58:07 +01:00
|
|
|
volk_32fc_magnitude_32f(out.writeBuf, (lv_32fc_t*)_in->readBuf, count);
|
2020-11-02 03:57:44 +01:00
|
|
|
|
|
|
|
_in->flush();
|
2020-11-12 00:53:38 +01:00
|
|
|
|
2021-03-29 21:53:43 +02:00
|
|
|
float avg;
|
2020-12-25 16:58:07 +01:00
|
|
|
volk_32f_accumulator_s32f(&avg, out.writeBuf, count);
|
2020-11-12 00:53:38 +01:00
|
|
|
avg /= (float)count;
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
2020-12-25 16:58:07 +01:00
|
|
|
out.writeBuf[i] -= avg;
|
2020-11-12 00:53:38 +01:00
|
|
|
}
|
|
|
|
|
2020-12-25 16:58:07 +01:00
|
|
|
if (!out.swap(count)) { return -1; }
|
2020-11-02 03:57:44 +01:00
|
|
|
return count;
|
2020-06-22 16:45:57 +02:00
|
|
|
}
|
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
stream<float> out;
|
2020-06-15 15:53:45 +02:00
|
|
|
|
|
|
|
private:
|
2020-11-02 03:57:44 +01:00
|
|
|
stream<complex_t>* _in;
|
2020-06-15 15:53:45 +02:00
|
|
|
|
|
|
|
};
|
2020-07-19 15:59:44 +02:00
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
class SSBDemod : public generic_block<SSBDemod> {
|
2020-07-19 15:59:44 +02:00
|
|
|
public:
|
2020-11-02 03:57:44 +01:00
|
|
|
SSBDemod() {}
|
2020-07-19 15:59:44 +02:00
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
SSBDemod(stream<complex_t>* in, float sampleRate, float bandWidth, int mode) { init(in, sampleRate, bandWidth, mode); }
|
2020-07-19 15:59:44 +02:00
|
|
|
|
2020-12-06 19:51:56 +01:00
|
|
|
~SSBDemod() {
|
|
|
|
generic_block<SSBDemod>::stop();
|
|
|
|
delete[] buffer;
|
|
|
|
}
|
2020-11-02 03:57:44 +01:00
|
|
|
|
|
|
|
enum {
|
|
|
|
MODE_USB,
|
|
|
|
MODE_LSB,
|
|
|
|
MODE_DSB
|
|
|
|
};
|
|
|
|
|
|
|
|
void init(stream<complex_t>* in, float sampleRate, float bandWidth, int mode) {
|
|
|
|
_in = in;
|
|
|
|
_sampleRate = sampleRate;
|
2020-07-19 15:59:44 +02:00
|
|
|
_bandWidth = bandWidth;
|
2020-11-02 03:57:44 +01:00
|
|
|
_mode = mode;
|
|
|
|
phase = lv_cmake(1.0f, 0.0f);
|
|
|
|
switch (_mode) {
|
|
|
|
case MODE_USB:
|
|
|
|
phaseDelta = lv_cmake(std::cos((_bandWidth / _sampleRate) * FL_M_PI), std::sin((_bandWidth / _sampleRate) * FL_M_PI));
|
|
|
|
break;
|
|
|
|
case MODE_LSB:
|
|
|
|
phaseDelta = lv_cmake(std::cos(-(_bandWidth / _sampleRate) * FL_M_PI), std::sin(-(_bandWidth / _sampleRate) * FL_M_PI));
|
|
|
|
break;
|
|
|
|
case MODE_DSB:
|
|
|
|
phaseDelta = lv_cmake(1.0f, 0.0f);
|
|
|
|
break;
|
|
|
|
}
|
2020-12-06 19:51:56 +01:00
|
|
|
buffer = new lv_32fc_t[STREAM_BUFFER_SIZE];
|
2020-11-02 03:57:44 +01:00
|
|
|
generic_block<SSBDemod>::registerInput(_in);
|
|
|
|
generic_block<SSBDemod>::registerOutput(&out);
|
2020-07-19 15:59:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
void setInput(stream<complex_t>* in) {
|
|
|
|
std::lock_guard<std::mutex> lck(generic_block<SSBDemod>::ctrlMtx);
|
|
|
|
generic_block<SSBDemod>::tempStop();
|
2020-11-02 17:48:17 +01:00
|
|
|
generic_block<SSBDemod>::unregisterInput(_in);
|
2020-11-02 03:57:44 +01:00
|
|
|
_in = in;
|
2020-11-02 17:48:17 +01:00
|
|
|
generic_block<SSBDemod>::registerInput(_in);
|
2020-11-02 03:57:44 +01:00
|
|
|
generic_block<SSBDemod>::tempStart();
|
2020-07-19 15:59:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
void setSampleRate(float sampleRate) {
|
|
|
|
// No need to restart
|
|
|
|
_sampleRate = sampleRate;
|
|
|
|
switch (_mode) {
|
|
|
|
case MODE_USB:
|
|
|
|
phaseDelta = lv_cmake(std::cos((_bandWidth / _sampleRate) * FL_M_PI), std::sin((_bandWidth / _sampleRate) * FL_M_PI));
|
|
|
|
break;
|
|
|
|
case MODE_LSB:
|
|
|
|
phaseDelta = lv_cmake(std::cos(-(_bandWidth / _sampleRate) * FL_M_PI), std::sin(-(_bandWidth / _sampleRate) * FL_M_PI));
|
|
|
|
break;
|
|
|
|
case MODE_DSB:
|
|
|
|
phaseDelta = lv_cmake(1.0f, 0.0f);
|
|
|
|
break;
|
|
|
|
}
|
2020-07-19 15:59:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
void setBandWidth(float bandWidth) {
|
|
|
|
// No need to restart
|
|
|
|
_bandWidth = bandWidth;
|
|
|
|
switch (_mode) {
|
|
|
|
case MODE_USB:
|
|
|
|
phaseDelta = lv_cmake(std::cos((_bandWidth / _sampleRate) * FL_M_PI), std::sin((_bandWidth / _sampleRate) * FL_M_PI));
|
|
|
|
break;
|
|
|
|
case MODE_LSB:
|
|
|
|
phaseDelta = lv_cmake(std::cos(-(_bandWidth / _sampleRate) * FL_M_PI), std::sin(-(_bandWidth / _sampleRate) * FL_M_PI));
|
|
|
|
break;
|
|
|
|
case MODE_DSB:
|
|
|
|
phaseDelta = lv_cmake(1.0f, 0.0f);
|
|
|
|
break;
|
2020-07-19 15:59:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMode(int mode) {
|
|
|
|
_mode = mode;
|
2020-11-02 03:57:44 +01:00
|
|
|
switch (_mode) {
|
|
|
|
case MODE_USB:
|
|
|
|
phaseDelta = lv_cmake(std::cos((_bandWidth / _sampleRate) * FL_M_PI), std::sin((_bandWidth / _sampleRate) * FL_M_PI));
|
|
|
|
break;
|
|
|
|
case MODE_LSB:
|
|
|
|
phaseDelta = lv_cmake(std::cos(-(_bandWidth / _sampleRate) * FL_M_PI), std::sin(-(_bandWidth / _sampleRate) * FL_M_PI));
|
|
|
|
break;
|
|
|
|
case MODE_DSB:
|
|
|
|
phaseDelta = lv_cmake(1.0f, 0.0f);
|
|
|
|
break;
|
2020-08-20 18:29:23 +02:00
|
|
|
}
|
2020-07-19 15:59:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
int run() {
|
2021-03-29 21:53:43 +02:00
|
|
|
int count = _in->read();
|
2020-11-02 03:57:44 +01:00
|
|
|
if (count < 0) { return -1; }
|
2020-07-19 15:59:44 +02:00
|
|
|
|
2020-12-25 16:58:07 +01:00
|
|
|
volk_32fc_s32fc_x2_rotator_32fc(buffer, (lv_32fc_t*)_in->readBuf, phaseDelta, &phase, count);
|
|
|
|
volk_32fc_deinterleave_real_32f(out.writeBuf, buffer, count);
|
2020-07-19 15:59:44 +02:00
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
_in->flush();
|
2020-12-25 16:58:07 +01:00
|
|
|
if (!out.swap(count)) { return -1; }
|
2020-11-02 03:57:44 +01:00
|
|
|
return count;
|
2020-07-19 15:59:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
stream<float> out;
|
2020-08-20 18:29:23 +02:00
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
private:
|
|
|
|
int _mode;
|
|
|
|
float _sampleRate, _bandWidth;
|
|
|
|
stream<complex_t>* _in;
|
2020-12-06 19:51:56 +01:00
|
|
|
lv_32fc_t* buffer;
|
2020-11-02 03:57:44 +01:00
|
|
|
lv_32fc_t phase;
|
|
|
|
lv_32fc_t phaseDelta;
|
2020-08-20 18:29:23 +02:00
|
|
|
|
2020-11-02 03:57:44 +01:00
|
|
|
};
|
2021-03-29 21:53:43 +02:00
|
|
|
|
|
|
|
class MSKDemod : public generic_hier_block<MSKDemod> {
|
|
|
|
public:
|
|
|
|
MSKDemod() {}
|
2021-04-01 16:54:16 +02:00
|
|
|
MSKDemod(stream<complex_t>* input, float sampleRate, float deviation, float baudRate, float omegaGain = (0.01*0.01) / 4, float muGain = 0.01f, float omegaRelLimit = 0.005f) {
|
2021-04-10 03:06:51 +02:00
|
|
|
init(input, sampleRate, deviation, baudRate, omegaGain, muGain, omegaRelLimit);
|
2021-04-01 16:54:16 +02:00
|
|
|
}
|
2021-03-29 21:53:43 +02:00
|
|
|
|
2021-04-01 16:54:16 +02:00
|
|
|
void init(stream<complex_t>* input, float sampleRate, float deviation, float baudRate, float omegaGain = (0.01*0.01) / 4, float muGain = 0.01f, float omegaRelLimit = 0.005f) {
|
|
|
|
_sampleRate = sampleRate;
|
|
|
|
_deviation = deviation;
|
|
|
|
_baudRate = baudRate;
|
|
|
|
_omegaGain = omegaGain;
|
|
|
|
_muGain = muGain;
|
|
|
|
_omegaRelLimit = omegaRelLimit;
|
|
|
|
|
|
|
|
demod.init(input, _sampleRate, _deviation);
|
|
|
|
recov.init(&demod.out, _sampleRate / _baudRate, _omegaGain, _muGain, _omegaRelLimit);
|
2021-03-29 21:53:43 +02:00
|
|
|
out = &recov.out;
|
|
|
|
|
|
|
|
generic_hier_block<MSKDemod>::registerBlock(&demod);
|
|
|
|
generic_hier_block<MSKDemod>::registerBlock(&recov);
|
|
|
|
}
|
|
|
|
|
2021-04-01 16:54:16 +02:00
|
|
|
void setSampleRate(float sampleRate) {
|
|
|
|
generic_hier_block<MSKDemod>::tempStop();
|
|
|
|
_sampleRate = sampleRate;
|
|
|
|
demod.setSampleRate(_sampleRate);
|
|
|
|
recov.setOmega(_sampleRate / _baudRate, _omegaRelLimit);
|
|
|
|
generic_hier_block<MSKDemod>::tempStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setDeviation(float deviation) {
|
|
|
|
_deviation = deviation;
|
|
|
|
demod.setDeviation(deviation);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setBaudRate(float baudRate, float omegaRelLimit) {
|
|
|
|
_baudRate = baudRate;
|
|
|
|
_omegaRelLimit = omegaRelLimit;
|
|
|
|
recov.setOmega(_sampleRate / _baudRate, _omegaRelLimit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMMGains(float omegaGain, float myGain) {
|
|
|
|
_omegaGain = omegaGain;
|
|
|
|
_muGain = myGain;
|
|
|
|
recov.setGains(_omegaGain, _muGain);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setOmegaRelLimit(float omegaRelLimit) {
|
|
|
|
_omegaRelLimit = omegaRelLimit;
|
|
|
|
recov.setOmegaRelLimit(_omegaRelLimit);
|
|
|
|
}
|
|
|
|
|
2021-03-29 21:53:43 +02:00
|
|
|
stream<float>* out = NULL;
|
|
|
|
|
|
|
|
private:
|
|
|
|
FloatFMDemod demod;
|
|
|
|
MMClockRecovery<float> recov;
|
2021-04-01 16:54:16 +02:00
|
|
|
|
|
|
|
float _sampleRate;
|
|
|
|
float _deviation;
|
|
|
|
float _baudRate;
|
|
|
|
float _omegaGain;
|
|
|
|
float _muGain;
|
|
|
|
float _omegaRelLimit;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<int ORDER, bool OFFSET>
|
|
|
|
class PSKDemod : public generic_hier_block<PSKDemod<ORDER, OFFSET>> {
|
|
|
|
public:
|
|
|
|
PSKDemod() {}
|
2021-04-10 03:06:51 +02:00
|
|
|
PSKDemod(stream<complex_t>* input, float sampleRate, float baudRate, int RRCTapCount = 31, float RRCAlpha = 0.32f, float agcRate = 10e-4, float costasLoopBw = 0.004f, float omegaGain = (0.01*0.01) / 4, float muGain = 0.01f, float omegaRelLimit = 0.005f) {
|
2021-04-01 17:42:04 +02:00
|
|
|
init(input, sampleRate, baudRate, RRCTapCount, RRCAlpha, agcRate, costasLoopBw, omegaGain, muGain, omegaRelLimit);
|
2021-04-01 16:54:16 +02:00
|
|
|
}
|
|
|
|
|
2021-04-10 03:06:51 +02:00
|
|
|
void init(stream<complex_t>* input, float sampleRate, float baudRate, int RRCTapCount = 31, float RRCAlpha = 0.32f, float agcRate = 10e-4, float costasLoopBw = 0.004f, float omegaGain = (0.01*0.01) / 4, float muGain = 0.01f, float omegaRelLimit = 0.005f) {
|
2021-04-01 16:54:16 +02:00
|
|
|
_RRCTapCount = RRCTapCount;
|
|
|
|
_RRCAlpha = RRCAlpha;
|
|
|
|
_sampleRate = sampleRate;
|
|
|
|
_agcRate = agcRate;
|
|
|
|
_costasLoopBw = costasLoopBw;
|
|
|
|
_baudRate = baudRate;
|
|
|
|
_omegaGain = omegaGain;
|
|
|
|
_muGain = muGain;
|
|
|
|
_omegaRelLimit = omegaRelLimit;
|
|
|
|
|
|
|
|
agc.init(input, 1.0f, 65535, _agcRate);
|
|
|
|
taps.init(_RRCTapCount, _sampleRate, _baudRate, _RRCAlpha);
|
|
|
|
rrc.init(&agc.out, &taps);
|
|
|
|
demod.init(&rrc.out, _costasLoopBw);
|
|
|
|
|
|
|
|
generic_hier_block<PSKDemod<ORDER, OFFSET>>::registerBlock(&agc);
|
|
|
|
generic_hier_block<PSKDemod<ORDER, OFFSET>>::registerBlock(&rrc);
|
|
|
|
generic_hier_block<PSKDemod<ORDER, OFFSET>>::registerBlock(&demod);
|
|
|
|
|
|
|
|
if constexpr (OFFSET) {
|
|
|
|
delay.init(&demod.out);
|
|
|
|
recov.init(&delay.out, _sampleRate / _baudRate, _omegaGain, _muGain, _omegaRelLimit);
|
|
|
|
generic_hier_block<PSKDemod<ORDER, OFFSET>>::registerBlock(&delay);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
recov.init(&demod.out, _sampleRate / _baudRate, _omegaGain, _muGain, _omegaRelLimit);
|
|
|
|
}
|
|
|
|
|
|
|
|
generic_hier_block<PSKDemod<ORDER, OFFSET>>::registerBlock(&recov);
|
|
|
|
|
|
|
|
out = &recov.out;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setInput(stream<complex_t>* input) {
|
|
|
|
agc.setInput(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setSampleRate(float sampleRate) {
|
|
|
|
_sampleRate = sampleRate;
|
|
|
|
rrc.tempStop();
|
|
|
|
recov.tempStop();
|
|
|
|
taps.setSampleRate(_sampleRate);
|
|
|
|
rrc.updateWindow(&taps);
|
|
|
|
recov.setOmega(_sampleRate / _baudRate, _omegaRelLimit);
|
|
|
|
rrc.tempStart();
|
|
|
|
recov.tempStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setBaudRate(float baudRate) {
|
|
|
|
_baudRate = baudRate;
|
|
|
|
rrc.tempStop();
|
|
|
|
recov.tempStop();
|
|
|
|
taps.setBaudRate(_baudRate);
|
|
|
|
rrc.updateWindow(&taps);
|
|
|
|
recov.setOmega(_sampleRate / _baudRate, _omegaRelLimit);
|
|
|
|
rrc.tempStart();
|
|
|
|
recov.tempStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setRRCParams(int RRCTapCount, float RRCAlpha) {
|
|
|
|
_RRCTapCount = RRCTapCount;
|
|
|
|
_RRCAlpha = RRCAlpha;
|
|
|
|
taps.setTapCount(_RRCTapCount);
|
|
|
|
taps.setAlpha(RRCAlpha);
|
|
|
|
rrc.updateWindow(&taps);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setAgcRate(float agcRate) {
|
|
|
|
_agcRate = agcRate;
|
|
|
|
agc.setRate(_agcRate);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setCostasLoopBw(float costasLoopBw) {
|
|
|
|
_costasLoopBw = costasLoopBw;
|
2021-04-01 17:42:30 +02:00
|
|
|
demod.setLoopBandwidth(_costasLoopBw);
|
2021-04-01 16:54:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void setMMGains(float omegaGain, float myGain) {
|
|
|
|
_omegaGain = omegaGain;
|
|
|
|
_muGain = myGain;
|
|
|
|
recov.setGains(_omegaGain, _muGain);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setOmegaRelLimit(float omegaRelLimit) {
|
|
|
|
_omegaRelLimit = omegaRelLimit;
|
|
|
|
recov.setOmegaRelLimit(_omegaRelLimit);
|
|
|
|
}
|
|
|
|
|
|
|
|
stream<complex_t>* out = NULL;
|
|
|
|
|
|
|
|
private:
|
|
|
|
dsp::ComplexAGC agc;
|
|
|
|
dsp::RRCTaps taps;
|
|
|
|
dsp::FIR<dsp::complex_t> rrc;
|
|
|
|
CostasLoop<ORDER> demod;
|
|
|
|
DelayImag delay;
|
|
|
|
MMClockRecovery<dsp::complex_t> recov;
|
|
|
|
|
|
|
|
int _RRCTapCount;
|
|
|
|
float _RRCAlpha;
|
|
|
|
float _sampleRate;
|
|
|
|
float _agcRate;
|
|
|
|
float _baudRate;
|
|
|
|
float _costasLoopBw;
|
|
|
|
float _omegaGain;
|
|
|
|
float _muGain;
|
|
|
|
float _omegaRelLimit;
|
2021-03-29 21:53:43 +02:00
|
|
|
};
|
2021-04-10 03:06:51 +02:00
|
|
|
|
|
|
|
class PMDemod : public generic_hier_block<PMDemod> {
|
|
|
|
public:
|
|
|
|
PMDemod() {}
|
|
|
|
PMDemod(stream<complex_t>* input, float sampleRate, float baudRate, float agcRate = 0.02e-3f, float pllLoopBandwidth = (0.06f*0.06f) / 4.0f, int rrcTapCount = 31, float rrcAlpha = 0.6f, float omegaGain = (0.01*0.01) / 4, float muGain = 0.01f, float omegaRelLimit = 0.005f) {
|
|
|
|
init(input, sampleRate, baudRate, agcRate, pllLoopBandwidth, rrcTapCount, rrcAlpha, omegaGain, muGain, omegaRelLimit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void init(stream<complex_t>* input, float sampleRate, float baudRate, float agcRate = 0.02e-3f, float pllLoopBandwidth = (0.06f*0.06f) / 4.0f, int rrcTapCount = 31, float rrcAlpha = 0.6f, float omegaGain = (0.01*0.01) / 4, float muGain = 0.01f, float omegaRelLimit = 0.005f) {
|
|
|
|
_sampleRate = sampleRate;
|
|
|
|
_baudRate = baudRate;
|
|
|
|
_agcRate = agcRate;
|
|
|
|
_pllLoopBandwidth = pllLoopBandwidth;
|
|
|
|
_rrcTapCount = rrcTapCount;
|
|
|
|
_rrcAlpha = rrcAlpha;
|
|
|
|
_omegaGain = omegaGain;
|
|
|
|
_muGain = muGain;
|
|
|
|
_omegaRelLimit = omegaRelLimit;
|
|
|
|
|
|
|
|
agc.init(input, 1.0f, 65535, _agcRate);
|
|
|
|
pll.init(&agc.out, _pllLoopBandwidth);
|
|
|
|
rrcwin.init(_rrcTapCount, _sampleRate, _baudRate, _rrcAlpha);
|
|
|
|
rrc.init(&pll.out, &rrcwin);
|
|
|
|
recov.init(&rrc.out, _sampleRate / _baudRate, _omegaGain, _muGain, _omegaRelLimit);
|
|
|
|
|
|
|
|
out = &recov.out;
|
|
|
|
|
|
|
|
generic_hier_block<PMDemod>::registerBlock(&agc);
|
|
|
|
generic_hier_block<PMDemod>::registerBlock(&pll);
|
|
|
|
generic_hier_block<PMDemod>::registerBlock(&rrc);
|
|
|
|
generic_hier_block<PMDemod>::registerBlock(&recov);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setInput(stream<complex_t>* input) {
|
|
|
|
agc.setInput(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setAgcRate(float agcRate) {
|
|
|
|
_agcRate = agcRate;
|
|
|
|
agc.setRate(_agcRate);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setPllLoopBandwidth(float pllLoopBandwidth) {
|
|
|
|
_pllLoopBandwidth = pllLoopBandwidth;
|
|
|
|
pll.setLoopBandwidth(_pllLoopBandwidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setRRCParams(int rrcTapCount, float rrcAlpha) {
|
|
|
|
_rrcTapCount = rrcTapCount;
|
|
|
|
_rrcAlpha = rrcAlpha;
|
|
|
|
rrcwin.setTapCount(_rrcTapCount);
|
|
|
|
rrcwin.setAlpha(_rrcAlpha);
|
|
|
|
rrc.updateWindow(&rrcwin);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMMGains(float omegaGain, float muGain) {
|
|
|
|
_omegaGain = omegaGain;
|
|
|
|
_muGain = muGain;
|
|
|
|
recov.setGains(_omegaGain, _muGain);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setOmegaRelLimit(float omegaRelLimit) {
|
|
|
|
_omegaRelLimit = omegaRelLimit;
|
|
|
|
recov.setOmegaRelLimit(_omegaRelLimit);
|
|
|
|
}
|
|
|
|
|
|
|
|
stream<float>* out = NULL;
|
|
|
|
|
|
|
|
private:
|
|
|
|
dsp::ComplexAGC agc;
|
|
|
|
dsp::CarrierTrackingPLL<float> pll;
|
|
|
|
dsp::RRCTaps rrcwin;
|
|
|
|
dsp::FIR<float> rrc;
|
|
|
|
dsp::MMClockRecovery<float> recov;
|
|
|
|
|
|
|
|
float _sampleRate;
|
|
|
|
float _baudRate;
|
|
|
|
float _agcRate;
|
|
|
|
float _pllLoopBandwidth;
|
|
|
|
int _rrcTapCount;
|
|
|
|
float _rrcAlpha;
|
|
|
|
float _omegaGain;
|
|
|
|
float _muGain;
|
|
|
|
float _omegaRelLimit;
|
|
|
|
};
|
2020-11-02 03:57:44 +01:00
|
|
|
}
|