fix: RunningQuality must add ssf, not add beat

This commit is contained in:
2026-03-12 21:28:50 +01:00
parent ee77180994
commit bfb3c99184
4 changed files with 20 additions and 6 deletions

View File

@@ -81,10 +81,11 @@ TEST(SignalTest, ranges) {
class DebugRunningQuality : public RunningQuality { class DebugRunningQuality : public RunningQuality {
protected: protected:
virtual void dispatchLocked() { locked = true; } virtual void dispatchLocked() { locked = true; }
virtual void dispatchBeat(int idx, bool good, double posCorr) { corrs.push_back(posCorr); } virtual void dispatchBeat(int idx, bool good, double posCorr) { goods.push_back(good); corrs.push_back(posCorr); }
bool locked; bool locked;
std::vector<double> corrs; std::vector<double> corrs;
std::vector<bool> goods;
public: public:
DebugRunningQuality(): locked(false) {} DebugRunningQuality(): locked(false) {}
@@ -92,6 +93,7 @@ public:
virtual ~DebugRunningQuality() {} virtual ~DebugRunningQuality() {}
bool isLocked() { return locked; } bool isLocked() { return locked; }
std::vector<double> getCorrs() { return corrs; } std::vector<double> getCorrs() { return corrs; }
std::vector<bool> getGoods() { return goods; }
std::vector<double> getBeatTemplate() { return this->beatTemplate; } std::vector<double> getBeatTemplate() { return this->beatTemplate; }
}; };
@@ -210,4 +212,7 @@ TEST(SignalTest, RunningQuality_t2) {
std::vector<double> corrs(sqi.getCorrs()); std::vector<double> corrs(sqi.getCorrs());
npy_save("test3/ssf_t3_sqi_corrs.npy", corrs); npy_save("test3/ssf_t3_sqi_corrs.npy", corrs);
std::vector<bool> goods(sqi.getGoods());
npy_save("test3/ssf_t3_sqi_goods.npy", goods);
} }

View File

@@ -10,6 +10,13 @@ void npy_save(std::string path, std::vector<double>& x) {
d.shape = {(unsigned long) x.size()}; d.shape = {(unsigned long) x.size()};
npy::write_npy(path, d); npy::write_npy(path, d);
} }
void npy_save(std::string path, std::vector<bool>& x) {
npy::npy_data_ptr<int> d;
std::vector<int> xx(x.begin(), x.end());
d.data_ptr = xx.data();
d.shape = {(unsigned long) x.size()};
npy::write_npy(path, d);
}
std::vector<double> fetch_y_axis(npy::npy_data<double>& acc) { std::vector<double> fetch_y_axis(npy::npy_data<double>& acc) {
// TODO: later on, we should use a vector projection towards gravity // TODO: later on, we should use a vector projection towards gravity

View File

@@ -20,6 +20,7 @@ template <typename T> static std::vector<double> apply_filter(T& filter, std::ve
} }
void npy_save(std::string path, std::vector<double>& x); void npy_save(std::string path, std::vector<double>& x);
void npy_save(std::string path, std::vector<bool>& x);
std::vector<double> fetch_y_axis(npy::npy_data<double>& acc); std::vector<double> fetch_y_axis(npy::npy_data<double>& acc);

View File

@@ -6,6 +6,7 @@
#include "pd_signal.h" #include "pd_signal.h"
#include <limits> #include <limits>
#include <cassert> #include <cassert>
#include <iomanip>
#include <iostream> #include <iostream>
static std::vector<double> make_ones(size_t sw) { static std::vector<double> make_ones(size_t sw) {
@@ -138,19 +139,19 @@ void RunningQuality::append(std::vector<double> &rawBeat, std::vector<double> &r
if (beatTemplates.size() == 0) { if (beatTemplates.size() == 0) {
// cannot correlate the first beat, no template yet // cannot correlate the first beat, no template yet
std::cerr << "(0) first beat -> addTemplate()" << std::endl; std::cerr << "(0) first beat -> addTemplate()" << std::endl;
addTemplate(beat); addTemplate(ssf);
justLocked = false; justLocked = false;
} else if (beatTemplates.size() <= 2) { } else if (beatTemplates.size() <= 2) {
// restart if there is no clear correlation between beats // restart if there is no clear correlation between beats
if (goodBeat) { if (goodBeat) {
std::cerr << "(2) good initial beat -> addTemplate()" << std::endl; std::cerr << "(2) good initial beat -> addTemplate()" << std::endl;
addTemplate(beat); addTemplate(ssf);
if (beatTemplates.size() > 2) if (beatTemplates.size() > 2)
justLocked = true; // TODO why not set? wrong compiler optimization? (is it unaware of member change?) justLocked = true; // TODO why not set? wrong compiler optimization? (is it unaware of member change?)
//std::cerr << " (2) beatTemplates.size()=" << beatTemplates.size() << " justLocked=" << ((int) justLocked) << std::endl; //std::cerr << " (2) beatTemplates.size()=" << beatTemplates.size() << " justLocked=" << ((int) justLocked) << std::endl;
} else { } else {
std::cerr << "(2) bad initial beat -> replaceTemplate()" << std::endl; std::cerr << "(2) bad initial beat idx=" << idx << " -> replaceTemplate() corr=" << std::fixed << std::setw(7) << std::setprecision(4) << corr << " checkedSsf=" << checkedSsf << std::endl;
replaceTemplate(beat); replaceTemplate(ssf);
//badBeatRanges.clear(); //badBeatRanges.clear();
justLocked = false; justLocked = false;
} }
@@ -159,7 +160,7 @@ void RunningQuality::append(std::vector<double> &rawBeat, std::vector<double> &r
std::cerr << "(3) running mode, good=" << ((int) goodBeat) << " justLocked=" << ((int) justLocked) << std::endl; std::cerr << "(3) running mode, good=" << ((int) goodBeat) << " justLocked=" << ((int) justLocked) << std::endl;
if (goodBeat) { if (goodBeat) {
addTemplate(beat); addTemplate(ssf);
} else { } else {
// badBeatRanges.add(s, e) // badBeatRanges.add(s, e)
// numNoisy++ // numNoisy++