phase_t
This commit is contained in:
parent
4306a234b9
commit
5991fa600d
19
dsp_lib.h
19
dsp_lib.h
@ -3,18 +3,21 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <complex>
|
#include <complex>
|
||||||
|
|
||||||
static uint32_t frequency_to_ftw(double f) {
|
typedef uint32_t phase_t;
|
||||||
return f*(double)UINT32_MAX;
|
#define PHASE_MAX UINT32_MAX
|
||||||
|
|
||||||
|
static phase_t frequency_to_ftw(double f) {
|
||||||
|
return f*(double)PHASE_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DDS {
|
class DDS {
|
||||||
private:
|
private:
|
||||||
uint32_t phase = 0;
|
phase_t phase = 0;
|
||||||
public:
|
public:
|
||||||
uint32_t ftw = 0;
|
phase_t ftw = 0;
|
||||||
double get() {
|
double get() {
|
||||||
phase += ftw; // wraps on overflow
|
phase += ftw; // wraps on overflow
|
||||||
return sin(phase*2.0*M_PI/(double)UINT32_MAX);
|
return sin(phase*2.0*M_PI/(double)PHASE_MAX);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -41,10 +44,10 @@ template<unsigned int order>
|
|||||||
class Lockin {
|
class Lockin {
|
||||||
private:
|
private:
|
||||||
double scale;
|
double scale;
|
||||||
uint32_t phase = 0;
|
phase_t phase = 0;
|
||||||
Lowpass<std::complex<double>, order> lpf;
|
Lowpass<std::complex<double>, order> lpf;
|
||||||
public:
|
public:
|
||||||
uint32_t ftw = 0;
|
phase_t ftw = 0;
|
||||||
void set_scale(double s) {
|
void set_scale(double s) {
|
||||||
scale = s;
|
scale = s;
|
||||||
}
|
}
|
||||||
@ -53,7 +56,7 @@ class Lockin {
|
|||||||
}
|
}
|
||||||
std::complex<double> update(double x) {
|
std::complex<double> update(double x) {
|
||||||
std::complex<double> rotated;
|
std::complex<double> rotated;
|
||||||
rotated = x*std::polar(scale, phase*2.0*M_PI/(double)UINT32_MAX);
|
rotated = x*std::polar(scale, phase*2.0*M_PI/(double)PHASE_MAX);
|
||||||
phase -= ftw; // wraps on underflow
|
phase -= ftw; // wraps on underflow
|
||||||
return lpf.update(rotated);
|
return lpf.update(rotated);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user