Files
libpasada/pasada-lib/include/step_detector.h

64 lines
1.5 KiB
C
Raw Normal View History

//
// 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"
#include <vector>
class StepListener {
public:
virtual ~StepListener() {}
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:
2026-05-19 22:36:24 +02:00
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.
*/
2026-05-19 22:36:24 +02:00
void primeFilters(double fps, std::vector<double> sig);
};
2026-05-20 00:10:37 +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<float> values);
};
#endif //PASADASUPERPROJECT_STEP_DETECTOR_H