feat: StepDetector update FPS, more FPS fixes
This commit is contained in:
@@ -94,8 +94,8 @@ protected:
|
|||||||
std::vector<bool> goods;
|
std::vector<bool> goods;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DebugRunningQuality(): lockedAt(-1), locked(false) {}
|
DebugRunningQuality(double fps): RunningQuality(fps), lockedAt(-1), locked(false) {}
|
||||||
explicit DebugRunningQuality(bool disableSsf): RunningQuality(disableSsf), locked(false) {}
|
explicit DebugRunningQuality(double fps, bool disableSsf): RunningQuality(fps, disableSsf), locked(false) {}
|
||||||
virtual ~DebugRunningQuality() {}
|
virtual ~DebugRunningQuality() {}
|
||||||
bool isLocked() { return locked; }
|
bool isLocked() { return locked; }
|
||||||
std::vector<double> getCorrs() { return corrs; }
|
std::vector<double> getCorrs() { return corrs; }
|
||||||
@@ -126,7 +126,8 @@ TEST(SignalTest, resample_same_len) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
TEST(SignalTest, RunningQuality_t1) {
|
TEST(SignalTest, RunningQuality_t1) {
|
||||||
DebugRunningQuality sqi(true);
|
double fps = 60.0;
|
||||||
|
DebugRunningQuality sqi(fps, true);
|
||||||
std::vector a {0.0, 0.3, 0.9, 1.0, 0.7, 0.5, 0.1};
|
std::vector a {0.0, 0.3, 0.9, 1.0, 0.7, 0.5, 0.1};
|
||||||
std::vector b {0.0, 0.3, 0.9, 1.0, 0.5, 0.5, 0.1};
|
std::vector b {0.0, 0.3, 0.9, 1.0, 0.5, 0.5, 0.1};
|
||||||
std::vector c {0.0, 0.3, 0.9, 1.0, 0.9, 0.5, 0.1};
|
std::vector c {0.0, 0.3, 0.9, 1.0, 0.9, 0.5, 0.1};
|
||||||
@@ -194,7 +195,7 @@ TEST(SignalTest, RunningQuality_t2) {
|
|||||||
|
|
||||||
// Debug SQI
|
// Debug SQI
|
||||||
|
|
||||||
DebugRunningQuality sqi;
|
DebugRunningQuality sqi(fps);
|
||||||
|
|
||||||
std::vector<double> beat_buf;
|
std::vector<double> beat_buf;
|
||||||
std::vector<double> ssf_buf;
|
std::vector<double> ssf_buf;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ TEST(StepDetector, t1_sub_sample_resolution) {
|
|||||||
// feed for actual test
|
// feed for actual test
|
||||||
for (size_t i = 0; i < N; i++) {
|
for (size_t i = 0; i < N; i++) {
|
||||||
const auto a_i = static_cast<float>(signal[i]);
|
const auto a_i = static_cast<float>(signal[i]);
|
||||||
det.filter(ts, std::vector<float> {0.0f, a_i, 0.0f});
|
det.filter(ts * 1e9, std::vector<float> {0.0f, a_i, 0.0f});
|
||||||
ts += 1.0 / fps;
|
ts += 1.0 / fps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
class SsfStepDetector {
|
class SsfStepDetector {
|
||||||
protected:
|
protected:
|
||||||
const size_t LEN_INIT;
|
size_t LEN_INIT;
|
||||||
const size_t LEN_TH_WIN;
|
size_t LEN_TH_WIN;
|
||||||
size_t num_samples;
|
size_t num_samples;
|
||||||
double ssf_threshold;
|
double ssf_threshold;
|
||||||
double ssf_threshold_nm1;
|
double ssf_threshold_nm1;
|
||||||
@@ -50,6 +50,7 @@ public:
|
|||||||
* @param len_refr duration of refractory period, in samples
|
* @param len_refr duration of refractory period, in samples
|
||||||
*/
|
*/
|
||||||
SsfStepDetector(double fps);
|
SsfStepDetector(double fps);
|
||||||
|
~SsfStepDetector();
|
||||||
double filter(double val);
|
double filter(double val);
|
||||||
double peek_threshold();
|
double peek_threshold();
|
||||||
|
|
||||||
@@ -62,18 +63,19 @@ public:
|
|||||||
class RunningQuality {
|
class RunningQuality {
|
||||||
protected:
|
protected:
|
||||||
// TODO: make it a filter (output proper samples)
|
// TODO: make it a filter (output proper samples)
|
||||||
|
// TODO: use fps info
|
||||||
|
|
||||||
/** template beat is resampled to this #samples */
|
/** template beat is resampled to this #samples */
|
||||||
const int BEAT_LEN = 120 /* 2*FPS for 30 bpm lower end */;
|
int BEAT_LEN;
|
||||||
|
|
||||||
/** threshold for accepting initial beats */
|
/** threshold for accepting initial beats */
|
||||||
const double BEAT_CORR_THR_1 = 0.9;
|
double BEAT_CORR_THR_1 = 0.9;
|
||||||
/** threshold for accepting subsequent beats */
|
/** threshold for accepting subsequent beats */
|
||||||
const double BEAT_CORR_THR_2 = 0.8;
|
double BEAT_CORR_THR_2 = 0.8;
|
||||||
/** absolute SSF threshold for accepting any beat */
|
/** absolute SSF threshold for accepting any beat */
|
||||||
const double SSF_THRESHOLD = 5.0;
|
double SSF_THRESHOLD = 5.0;
|
||||||
/** number of recent beats to use for beat template. must be even (alternating feet have different patterns; make it symmetric) */
|
/** number of recent beats to use for beat template. must be even (alternating feet have different patterns; make it symmetric) */
|
||||||
const int NUM_BEATS = 4;
|
int NUM_BEATS = 4;
|
||||||
|
|
||||||
std::deque<std::vector<double> > beatTemplates;
|
std::deque<std::vector<double> > beatTemplates;
|
||||||
std::vector<double> beatTemplate;
|
std::vector<double> beatTemplate;
|
||||||
@@ -93,8 +95,8 @@ protected:
|
|||||||
virtual void dispatchBeat(int idx, bool good, double posCorr);
|
virtual void dispatchBeat(int idx, bool good, double posCorr);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RunningQuality();
|
RunningQuality(double fps);
|
||||||
explicit RunningQuality(bool disableSsf);
|
explicit RunningQuality(double fps, bool disableSsf);
|
||||||
virtual ~RunningQuality();
|
virtual ~RunningQuality();
|
||||||
|
|
||||||
// note: arg should be an iterator really, but can do later
|
// note: arg should be an iterator really, but can do later
|
||||||
@@ -116,6 +118,7 @@ protected:
|
|||||||
double sqi;
|
double sqi;
|
||||||
public:
|
public:
|
||||||
RunningQualityFilter(double fps);
|
RunningQualityFilter(double fps);
|
||||||
|
~RunningQualityFilter();
|
||||||
double filter(double y, double ssf, double step);
|
double filter(double y, double ssf, double step);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ protected:
|
|||||||
Resampler res_x;
|
Resampler res_x;
|
||||||
Resampler res_y;
|
Resampler res_y;
|
||||||
Resampler res_z;
|
Resampler res_z;
|
||||||
|
double fps;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StepDetector(double fps, StepListener *listener, bool debug = false);
|
StepDetector(double fps, StepListener *listener, bool debug = false);
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ SsfStepDetector::SsfStepDetector(double fps) :
|
|||||||
{
|
{
|
||||||
assert (LEN_INIT >= LEN_TH_WIN && "LEN_INIT < LEN_TH_WIN, check normalization of initial ssf_threshold");
|
assert (LEN_INIT >= LEN_TH_WIN && "LEN_INIT < LEN_TH_WIN, check normalization of initial ssf_threshold");
|
||||||
}
|
}
|
||||||
|
SsfStepDetector::~SsfStepDetector() {}
|
||||||
double SsfStepDetector::filter(double ssf) {
|
double SsfStepDetector::filter(double ssf) {
|
||||||
double ssf_mean = f_ssf_mean.filter(ssf) / ((double) LEN_TH_WIN);
|
double ssf_mean = f_ssf_mean.filter(ssf) / ((double) LEN_TH_WIN);
|
||||||
double rv = 0.0;
|
double rv = 0.0;
|
||||||
@@ -154,8 +155,13 @@ void RunningQuality::replaceTemplate(std::vector<double>& x) {
|
|||||||
void RunningQuality::dispatchLocked() { /* implement me, add Listener etc. */ }
|
void RunningQuality::dispatchLocked() { /* implement me, add Listener etc. */ }
|
||||||
void RunningQuality::dispatchBeat(int idx, bool good, double posCorr) { /* implement me, add Listener etc. */ }
|
void RunningQuality::dispatchBeat(int idx, bool good, double posCorr) { /* implement me, add Listener etc. */ }
|
||||||
|
|
||||||
RunningQuality::RunningQuality(): beatCorrThr2(BEAT_CORR_THR_2), justLocked(false), idx(0), disableSsf(false) {}
|
static int get_beat_len(double fps) {
|
||||||
RunningQuality::RunningQuality(bool disableSsf): beatCorrThr2(BEAT_CORR_THR_2), justLocked(false), idx(0), disableSsf(disableSsf) {}
|
/* 2*FPS for 30 bpm lower end */
|
||||||
|
return 2.0 * fps;
|
||||||
|
}
|
||||||
|
|
||||||
|
RunningQuality::RunningQuality(double fps): BEAT_LEN(get_beat_len(fps)), beatCorrThr2(BEAT_CORR_THR_2), justLocked(false), idx(0), disableSsf(false) {}
|
||||||
|
RunningQuality::RunningQuality(double fps, bool disableSsf): BEAT_LEN(get_beat_len(fps)), beatCorrThr2(BEAT_CORR_THR_2), justLocked(false), idx(0), disableSsf(disableSsf) {}
|
||||||
RunningQuality::~RunningQuality() {}
|
RunningQuality::~RunningQuality() {}
|
||||||
|
|
||||||
// note: arg should be an iterator really, but can do later
|
// note: arg should be an iterator really, but can do later
|
||||||
@@ -221,7 +227,8 @@ bool RunningQuality::append(std::vector<double> &rawBeat, std::vector<double> &r
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RunningQualityFilter::RunningQualityFilter(double fps) : sqi(0.0) {}
|
RunningQualityFilter::RunningQualityFilter(double fps) : f_sqi(fps), sqi(0.0) {}
|
||||||
|
RunningQualityFilter::~RunningQualityFilter() {}
|
||||||
|
|
||||||
double RunningQualityFilter::filter(double y, double ssf, double step) {
|
double RunningQualityFilter::filter(double y, double ssf, double step) {
|
||||||
if (step == 1.0) {
|
if (step == 1.0) {
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ StepDetector::StepDetector(double fps, StepListener *listener, bool debug) :
|
|||||||
f_ssf(fps),
|
f_ssf(fps),
|
||||||
f_ssd(fps),
|
f_ssd(fps),
|
||||||
f_sqi(fps),
|
f_sqi(fps),
|
||||||
debug(debug)
|
debug(debug),
|
||||||
|
fps(0.0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
static int gravity_num_taps(double fps) {
|
static int gravity_num_taps(double fps) {
|
||||||
@@ -50,6 +51,14 @@ void StepDetector::filter(double ts, std::vector<float> values) {
|
|||||||
res_x.push(ts, values[0]);
|
res_x.push(ts, values[0]);
|
||||||
res_y.push(ts, values[1]);
|
res_y.push(ts, values[1]);
|
||||||
res_z.push(ts, values[2]);
|
res_z.push(ts, values[2]);
|
||||||
|
// as soon as there is 'fps' information, re-init the classes requiring fps info
|
||||||
|
if (fps == 0.0 && res_x.peek()) {
|
||||||
|
fps = res_x.get_fs();
|
||||||
|
f_grav = GravityFilter(fps);
|
||||||
|
f_ssf = SsfFilter(fps);
|
||||||
|
f_ssd = SsfStepDetector(fps);
|
||||||
|
f_sqi = RunningQualityFilter(fps);
|
||||||
|
}
|
||||||
while (res_x.peek()) {
|
while (res_x.peek()) {
|
||||||
double x = res_x.get(), y = res_y.get(), z = res_z.get();
|
double x = res_x.get(), y = res_y.get(), z = res_z.get();
|
||||||
std::vector<double> samp { x, y, z };
|
std::vector<double> samp { x, y, z };
|
||||||
@@ -85,7 +94,7 @@ double StepDetector::primeFilters(double fps, std::vector<double> sig) {
|
|||||||
double ts = 0;
|
double ts = 0;
|
||||||
for (size_t i = 0; i < N_INIT; i++) {
|
for (size_t i = 0; i < N_INIT; i++) {
|
||||||
const auto a_i = static_cast<float>(sig[i]);
|
const auto a_i = static_cast<float>(sig[i]);
|
||||||
filter(ts, std::vector<float> {0.0f, a_i, 0.0f});
|
filter(ts * 1e9, std::vector<float> {0.0f, a_i, 0.0f});
|
||||||
ts += 1.0 / fps;
|
ts += 1.0 / fps;
|
||||||
}
|
}
|
||||||
// clear debug buffers
|
// clear debug buffers
|
||||||
|
|||||||
Reference in New Issue
Block a user