add: GravityFilter
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "step_detector.h"
|
||||
|
||||
#include "pd_signal.h"
|
||||
|
||||
StepDetector::StepDetector(double fps, StepListener *listener, bool debug) :
|
||||
listener(listener),
|
||||
f_neg(1, 0, 0, std::vector<double> {-1.0}),
|
||||
@@ -13,6 +15,36 @@ StepDetector::StepDetector(double fps, StepListener *listener, bool debug) :
|
||||
debug(debug)
|
||||
{}
|
||||
|
||||
static int gravity_num_taps(double fps) {
|
||||
return 5.0 * fps;
|
||||
}
|
||||
|
||||
// 5 secs buffer, prime y with direction of gravity (for tests & faster init)
|
||||
GravityFilter::GravityFilter(double fps) :
|
||||
N(gravity_num_taps(fps)),
|
||||
gauss_taps(pd_signal::gauss(N, N/2, N/4)),
|
||||
gx(N, 0, 0, gauss_taps),
|
||||
gy(N, 0, 0, gauss_taps),
|
||||
gz(N, 0, 0, gauss_taps)
|
||||
{
|
||||
gy.prime(-9.81);
|
||||
}
|
||||
|
||||
double GravityFilter::filter(std::vector<float> values) {
|
||||
gx.push(values[0]);
|
||||
gy.push(values[1]);
|
||||
gz.push(values[2]);
|
||||
double x = gx.peek(), y = gy.peek(), z = gz.peek();
|
||||
double g = sqrt(x * x + y * y + z * z);
|
||||
// e = mean(a)
|
||||
double ex = x / g, ey = y / g, ez = z / g;
|
||||
// e \in a
|
||||
double vx = values[0] * ex;
|
||||
double vy = values[1] * ey;
|
||||
double vz = values[2] * ez;
|
||||
return vx + vy + vz;
|
||||
}
|
||||
|
||||
void StepDetector::filter(std::vector<float> values) {
|
||||
// TODO: later on, we should use a vector projection towards gravity
|
||||
auto s1 = (double) values[1]; // take y-axis value for now
|
||||
|
||||
Reference in New Issue
Block a user