Skip to content

Commit

Permalink
more updates
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreRouma committed Jul 27, 2022
1 parent 60221ad commit 38b3b28
Show file tree
Hide file tree
Showing 19 changed files with 311 additions and 30 deletions.
6 changes: 3 additions & 3 deletions src/dsp/channel/frequency_xlator.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "../processor.h"
#include "../math/freq_to_omega.h"
#include "../math/hz_to_rads.h"

namespace dsp::channel {
class FrequencyXlator : public Processor<complex_t, complex_t> {
Expand All @@ -19,7 +19,7 @@ namespace dsp::channel {
}

void init(stream<complex_t>* in, double offset, double samplerate) {
init(in, math::freqToOmega(offset, samplerate));
init(in, math::hzToRads(offset, samplerate));
}

void setOffset(double offset) {
Expand All @@ -29,7 +29,7 @@ namespace dsp::channel {
}

void setOffset(double offset, double samplerate) {
setOffset(math::freqToOmega(offset, samplerate));
setOffset(math::hzToRads(offset, samplerate));
}

void reset() {
Expand Down
2 changes: 1 addition & 1 deletion src/dsp/clock_recovery/fd.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ namespace dsp::clock_recovery {
protected:
void generateInterpTaps() {
double bw = 0.5 / (double)_interpPhaseCount;
dsp::tap<float> lp = dsp::taps::windowedSinc<float>(_interpPhaseCount * _interpTapCount, dsp::math::freqToOmega(bw, 1.0), dsp::window::nuttall, _interpPhaseCount);
dsp::tap<float> lp = dsp::taps::windowedSinc<float>(_interpPhaseCount * _interpTapCount, dsp::math::hzToRads(bw, 1.0), dsp::window::nuttall, _interpPhaseCount);
interpBank = dsp::multirate::buildPolyphaseBank<float>(_interpPhaseCount, lp);
taps::free(lp);
}
Expand Down
2 changes: 1 addition & 1 deletion src/dsp/clock_recovery/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ namespace dsp::clock_recovery {
protected:
void generateInterpTaps() {
double bw = 0.5 / (double)_interpPhaseCount;
dsp::tap<float> lp = dsp::taps::windowedSinc<float>(_interpPhaseCount * _interpTapCount, dsp::math::freqToOmega(bw, 1.0), dsp::window::nuttall, _interpPhaseCount);
dsp::tap<float> lp = dsp::taps::windowedSinc<float>(_interpPhaseCount * _interpTapCount, dsp::math::hzToRads(bw, 1.0), dsp::window::nuttall, _interpPhaseCount);
interpBank = dsp::multirate::buildPolyphaseBank<float>(_interpPhaseCount, lp);
taps::free(lp);
}
Expand Down
6 changes: 3 additions & 3 deletions src/dsp/demod/broadcast_fm.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace dsp::demod {
pilotFirTaps = taps::bandPass<complex_t>(18750.0, 19250.0, 3000.0, _samplerate, true);
pilotFir.init(NULL, pilotFirTaps);
rtoc.init(NULL);
pilotPLL.init(NULL, 25000.0 / _samplerate, 0.0, math::freqToOmega(19000.0, _samplerate), math::freqToOmega(18750.0, _samplerate), math::freqToOmega(19250.0, _samplerate));
pilotPLL.init(NULL, 25000.0 / _samplerate, 0.0, math::hzToRads(19000.0, _samplerate), math::hzToRads(18750.0, _samplerate), math::hzToRads(19250.0, _samplerate));
lprDelay.init(NULL, ((pilotFirTaps.size - 1) / 2) + 1);
lmrDelay.init(NULL, ((pilotFirTaps.size - 1) / 2) + 1);
audioFirTaps = taps::lowPass(15000.0, 4000.0, _samplerate);
Expand Down Expand Up @@ -82,8 +82,8 @@ namespace dsp::demod {
pilotFirTaps = taps::bandPass<complex_t>(18750.0, 19250.0, 3000.0, samplerate, true);
pilotFir.setTaps(pilotFirTaps);

pilotPLL.setFrequencyLimits(math::freqToOmega(18750.0, _samplerate), math::freqToOmega(19250.0, _samplerate));
pilotPLL.setInitialFreq(math::freqToOmega(19000.0, _samplerate));
pilotPLL.setFrequencyLimits(math::hzToRads(18750.0, _samplerate), math::hzToRads(19250.0, _samplerate));
pilotPLL.setInitialFreq(math::hzToRads(19000.0, _samplerate));
lprDelay.setDelay(((pilotFirTaps.size - 1) / 2) + 1);
lmrDelay.setDelay(((pilotFirTaps.size - 1) / 2) + 1);

Expand Down
10 changes: 5 additions & 5 deletions src/dsp/demod/quadrature.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once
#include "../processor.h"
#include "../math/fast_atan2.h"
#include "../math/freq_to_omega.h"
#include "../math/norm_phase_diff.h"
#include "../math/hz_to_rads.h"
#include "../math/normalize_phase.h"

namespace dsp::demod {
class Quadrature : public Processor<complex_t, float> {
Expand All @@ -21,7 +21,7 @@ namespace dsp::demod {
}

virtual void init(stream<complex_t>* in, double deviation, double samplerate) {
init(in, math::freqToOmega(deviation, samplerate));
init(in, math::hzToRads(deviation, samplerate));
}

void setDeviation(double deviation) {
Expand All @@ -33,13 +33,13 @@ namespace dsp::demod {
void setDeviation(double deviation, double samplerate) {
assert(base_type::_block_init);
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
_invDeviation = 1.0 / math::freqToOmega(deviation, samplerate);
_invDeviation = 1.0 / math::hzToRads(deviation, samplerate);
}

inline int process(int count, complex_t* in, float* out) {
for (int i = 0; i < count; i++) {
float cphase = in[i].phase();
out[i] = math::normPhaseDiff(cphase - phase) * _invDeviation;
out[i] = math::normalizePhase(cphase - phase) * _invDeviation;
phase = cphase;
}
return count;
Expand Down
8 changes: 7 additions & 1 deletion src/dsp/loop/carrier_tracking_pll.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ namespace dsp::loop {
class CarrierTrackingPLL : public PLL {
using base_type = PLL;
public:
CarrierTrackingPLL() {}

CarrierTrackingPLL(stream<complex_t>* in, double bandwidth, double initPhase = 0.0, double initFreq = 0.0, double minFreq = -FL_M_PI, double maxFreq = FL_M_PI) {
base_type::init(in, bandwidth, initFreq, initPhase, minFreq, maxFreq);
}

inline int process(int count, complex_t* in, complex_t* out) {
for (int i = 0; i < count; i++) {
out[i] = in[i] * math::phasor(-pcl.phase);
pcl.advance(math::normPhaseDiff(in[i].phase() - pcl.phase));
pcl.advance(math::normalizePhase(in[i].phase() - pcl.phase));
}
return count;
}
Expand Down
6 changes: 6 additions & 0 deletions src/dsp/loop/costas.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ namespace dsp::loop {
static_assert(ORDER == 2 || ORDER == 4 || ORDER == 8, "Invalid costas order");
using base_type = PLL;
public:
Costas() {}

Costas(stream<complex_t>* in, double bandwidth, double initPhase = 0.0, double initFreq = 0.0, double minFreq = -FL_M_PI, double maxFreq = FL_M_PI) {
base_type::init(in, bandwidth, initFreq, initPhase, minFreq, maxFreq);
}

inline int process(int count, complex_t* in, complex_t* out) {
for (int i = 0; i < count; i++) {
out[i] = in[i] * math::phasor(-pcl.phase);
Expand Down
4 changes: 2 additions & 2 deletions src/dsp/loop/pll.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "../processor.h"
#include "../math/norm_phase_diff.h"
#include "../math/normalize_phase.h"
#include "../math/phasor.h"
#include "phase_control_loop.h"

Expand Down Expand Up @@ -64,7 +64,7 @@ namespace dsp::loop {
virtual inline int process(int count, complex_t* in, complex_t* out) {
for (int i = 0; i < count; i++) {
out[i] = math::phasor(pcl.phase);
pcl.advance(math::normPhaseDiff(in[i].phase() - pcl.phase));
pcl.advance(math::normalizePhase(in[i].phase() - pcl.phase));
}
return count;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dsp/math/freq_to_omega.h → src/dsp/math/hz_to_rads.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "constants.h"

namespace dsp::math {
inline double freqToOmega(double freq, double samplerate) {
inline double hzToRads(double freq, double samplerate) {
return 2.0 * DB_M_PI * (freq / samplerate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace dsp::math {
template<class T>
T normPhaseDiff(T diff) {
T normalizePhase(T diff) {
if (diff > FL_M_PI) { diff -= 2.0f * FL_M_PI; }
else if (diff <= -FL_M_PI) { diff += 2.0f * FL_M_PI; }
return diff;
Expand Down
86 changes: 86 additions & 0 deletions src/dsp/mod/gfsk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#pragma once
#include "../multirate/rrc_interpolator.h"
#include "quadrature.h"

namespace dsp::mod {
class GFSK : public Processor<float, complex_t> {
using base_type = Processor<float, complex_t>;
public:
GFSK() {}

GFSK(stream<float>* in, double symbolrate, double samplerate, double rrcBeta, int rrcTapCount, double deviation) {
init(in, symbolrate, samplerate, rrcBeta, rrcTapCount, deviation);
}

void init(stream<float>* in, double symbolrate, double samplerate, double rrcBeta, int rrcTapCount, double deviation) {
_samplerate = samplerate;
_deviation = deviation;

interp.init(NULL, symbolrate, _samplerate, rrcBeta, rrcTapCount);
mod.init(NULL, _deviation, _samplerate);

base_type::init(in);
}

void setRates(double symbolrate, double samplerate) {
assert(base_type::_block_init);
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
base_type::tempStop();
_samplerate = samplerate;
interp.setRates(symbolrate, _samplerate);
mod.setDeviation(_deviation, _samplerate);
base_type::tempStart();
}

void setRRCParams(double rrcBeta, int rrcTapCount) {
assert(base_type::_block_init);
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
base_type::tempStop();
interp.setRRCParam(rrcBeta, rrcTapCount);
base_type::tempStart();
}

void setDeviation(double deviation) {
assert(base_type::_block_init);
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
_deviation = deviation;
mod.setDeviation(_deviation, _samplerate);
}

void reset() {
assert(base_type::_block_init);
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
base_type::tempStop();
interp.reset();
mod.reset();
base_type::tempStart();
}

inline int process(int count, const float* in, complex_t* out) {
count = interp.process(count, in, interp.out.writeBuf);
mod.process(count, interp.out.writeBuf, out);
return count;
}

int run() {
int count = base_type::_in->read();
if (count < 0) { return -1; }

int outCount = process(count, base_type::_in->readBuf, base_type::out.writeBuf);

// Swap if some data was generated
base_type::_in->flush();
if (outCount) {
if (!base_type::out.swap(outCount)) { return -1; }
}
return outCount;
}

private:
double _samplerate;
double _deviation;

multirate::RRCInterpolator<float> interp;
Quadrature mod;
};
}
6 changes: 6 additions & 0 deletions src/dsp/mod/psk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once
#include "../multirate/rrc_interpolator.h"

namespace dsp::mod {
typedef multirate::RRCInterpolator<complex_t> PSK;
}
67 changes: 67 additions & 0 deletions src/dsp/mod/quadrature.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#pragma once
#include "../processor.h"
#include "../math/phasor.h"
#include "../math/normalize_phase.h"
#include "../math/hz_to_rads.h"

namespace dsp::mod {
class Quadrature : Processor<float, complex_t> {
using base_type = Processor<float, complex_t>;
public:
Quadrature() {}

Quadrature(stream<float>* in, double deviation) { init(in, deviation); }

Quadrature(stream<float>* in, double deviation, double samplerate) { init(in, deviation, samplerate); }

void init(stream<float>* in, double deviation) {
_deviation = deviation;
base_type::init(in);
}

void init(stream<float>* in, double deviation, double samplerate) {
init(in, math::hzToRads(deviation, samplerate));
}

void setDeviation(double deviation) {
assert(base_type::_block_init);
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
_deviation = deviation;
}

void setDeviation(double deviation, double samplerate) {
assert(base_type::_block_init);
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
_deviation = math::hzToRads(deviation, samplerate);
}

void reset() {
assert(base_type::_block_init);
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
phase = 0.0f;
}

inline int process(int count, const float* in, complex_t* out) {
for (int i = 0; i < count; i++) {
phase = math::normalizePhase(phase + (_deviation * in[i]));
out[i] = math::phasor(phase);
}
return count;
}

virtual int run() {
int count = base_type::_in->read();
if (count < 0) { return -1; }

process(count, base_type::_in->readBuf, base_type::out.writeBuf);

base_type::_in->flush();
if (!base_type::out.swap(count)) { return -1; }
return count;
}

private:
float _deviation;
float phase = 0.0f;
};
}
10 changes: 10 additions & 0 deletions src/dsp/multirate/rational_resampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ namespace dsp::multirate {
base_type::tempStart();
}

void setRates(double inSamplerate, double outSamplerate) {
assert(base_type::_block_init);
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
base_type::tempStop();
_inSamplerate = inSamplerate;
_outSamplerate = outSamplerate;
reconfigure();
base_type::tempStart();
}

inline int process(int count, const T* in, T* out) {
switch(mode) {
case Mode::BOTH:
Expand Down
Loading

0 comments on commit 38b3b28

Please sign in to comment.