feat: add GravityFilter and Resampler to StepDetector

This commit is contained in:
2026-05-20 00:27:41 +02:00
parent 2371d16af8
commit f591f4950f
3 changed files with 66 additions and 44 deletions

View File

@@ -7,6 +7,7 @@
#include "iir_filter.h"
#include "ssf_filter.h"
#include "pd_resamp.h"
#include <vector>
class StepListener {
@@ -15,39 +16,6 @@ public:
virtual void playBeat() = 0;
};
/**
* Step detector from accelerometer signal.
*
* Settling time is 3.0 sec (defined in SsfStepDetector.LEN_INIT),
* no steps are detected before.
*/
class StepDetector {
protected:
StepListener *listener;
Filt f_neg;
SsfFilter f_ssf;
SsfStepDetector f_ssd;
RunningQualityFilter f_sqi;
bool debug;
std::vector<double> buf_ssd;
std::vector<double> buf_sqi;
std::vector<double> buf_out;
public:
StepDetector(double fps, StepListener *listener, bool debug = false);
void filter(std::vector<float> values);
std::vector<double> getBufSsd();
std::vector<double> getBufSqi();
std::vector<double> getBufOut();
/**
* Prime the filters using the given input signal.
* Used for debugging (non-realtime processing) to align the signal.
*/
void primeFilters(double fps, std::vector<double> sig);
};
/** mean-filter the gravity vector, then take acceleration downwards */
class GravityFilter {
size_t N;
@@ -58,7 +26,45 @@ class GravityFilter {
public:
// 5 secs buffer, prime y with direction of gravity (for tests & faster init)
GravityFilter(double fps);
double filter(std::vector<float> values);
double filter(std::vector<double> values);
};
/**
* Step detector from accelerometer signal.
*
* Settling time is 3.0 sec (defined in SsfStepDetector.LEN_INIT),
* no steps are detected before.
*/
class StepDetector {
protected:
StepListener *listener;
GravityFilter f_grav;
SsfFilter f_ssf;
SsfStepDetector f_ssd;
RunningQualityFilter f_sqi;
bool debug;
std::vector<double> buf_ssd;
std::vector<double> buf_sqi;
std::vector<double> buf_out;
Resampler res_x;
Resampler res_y;
Resampler res_z;
public:
StepDetector(double fps, StepListener *listener, bool debug = false);
void filter(double ts, std::vector<float> values);
void filter_a(double s1);
std::vector<double> getBufSsd();
std::vector<double> getBufSqi();
std::vector<double> getBufOut();
/**
* Prime the filters using the given input signal.
* Used for debugging (non-realtime processing) to align the signal.
*/
double primeFilters(double fps, std::vector<double> sig);
};
#endif //PASADASUPERPROJECT_STEP_DETECTOR_H