2026-03-15 23:07:05 +01:00
|
|
|
//
|
|
|
|
|
// Created by david on 15.03.2026.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#ifndef PASADASUPERPROJECT_STEP_DETECTOR_H
|
|
|
|
|
#define PASADASUPERPROJECT_STEP_DETECTOR_H
|
|
|
|
|
|
|
|
|
|
#include "iir_filter.h"
|
|
|
|
|
#include "ssf_filter.h"
|
2026-05-20 00:27:41 +02:00
|
|
|
#include "pd_resamp.h"
|
2026-03-15 23:07:05 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
class StepListener {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~StepListener() {}
|
|
|
|
|
virtual void playBeat() = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2026-05-20 00:27:41 +02:00
|
|
|
/** mean-filter the gravity vector, then take acceleration downwards */
|
|
|
|
|
class GravityFilter {
|
|
|
|
|
size_t N;
|
|
|
|
|
std::vector<double> gauss_taps;
|
|
|
|
|
Filt gx;
|
|
|
|
|
Filt gy;
|
|
|
|
|
Filt gz;
|
|
|
|
|
public:
|
|
|
|
|
// 5 secs buffer, prime y with direction of gravity (for tests & faster init)
|
|
|
|
|
GravityFilter(double fps);
|
|
|
|
|
double filter(std::vector<double> values);
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-15 23:07:05 +01:00
|
|
|
/**
|
|
|
|
|
* 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;
|
2026-05-20 00:27:41 +02:00
|
|
|
GravityFilter f_grav;
|
2026-03-15 23:07:05 +01:00
|
|
|
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;
|
|
|
|
|
|
2026-05-20 00:27:41 +02:00
|
|
|
Resampler res_x;
|
|
|
|
|
Resampler res_y;
|
|
|
|
|
Resampler res_z;
|
|
|
|
|
|
2026-03-15 23:07:05 +01:00
|
|
|
public:
|
2026-05-19 22:36:24 +02:00
|
|
|
StepDetector(double fps, StepListener *listener, bool debug = false);
|
2026-05-20 00:27:41 +02:00
|
|
|
void filter(double ts, std::vector<float> values);
|
|
|
|
|
void filter_a(double s1);
|
2026-03-15 23:07:05 +01:00
|
|
|
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.
|
|
|
|
|
*/
|
2026-05-20 00:27:41 +02:00
|
|
|
double primeFilters(double fps, std::vector<double> sig);
|
2026-05-20 00:10:37 +02:00
|
|
|
};
|
|
|
|
|
|
2026-03-15 23:07:05 +01:00
|
|
|
#endif //PASADASUPERPROJECT_STEP_DETECTOR_H
|