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 <complex>
|
||||
|
||||
static uint32_t frequency_to_ftw(double f) {
|
||||
return f*(double)UINT32_MAX;
|
||||
typedef uint32_t phase_t;
|
||||
#define PHASE_MAX UINT32_MAX
|
||||
|
||||
static phase_t frequency_to_ftw(double f) {
|
||||
return f*(double)PHASE_MAX;
|
||||
}
|
||||
|
||||
class DDS {
|
||||
private:
|
||||
uint32_t phase = 0;
|
||||
phase_t phase = 0;
|
||||
public:
|
||||
uint32_t ftw = 0;
|
||||
phase_t ftw = 0;
|
||||
double get() {
|
||||
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 {
|
||||
private:
|
||||
double scale;
|
||||
uint32_t phase = 0;
|
||||
phase_t phase = 0;
|
||||
Lowpass<std::complex<double>, order> lpf;
|
||||
public:
|
||||
uint32_t ftw = 0;
|
||||
phase_t ftw = 0;
|
||||
void set_scale(double s) {
|
||||
scale = s;
|
||||
}
|
||||
@ -53,7 +56,7 @@ class Lockin {
|
||||
}
|
||||
std::complex<double> update(double x) {
|
||||
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
|
||||
return lpf.update(rotated);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user