worked on step-detection

adjusted iir biquad
added biquad-stacking
This commit is contained in:
2018-08-07 19:36:07 +02:00
parent d6ac8a72ca
commit f990485d44
5 changed files with 135 additions and 44 deletions

View File

@@ -22,7 +22,7 @@
#endif
#include "../../Assertions.h"
#include "../../math/dsp/iir/BiQuad.h"
#include "../../math/dsp/iir/BiQuadStack.h"
#include "../../math/FixedFrequencyInterpolator.h"
#include "../../math/DelayBuffer.h"
@@ -38,9 +38,12 @@ class StepDetection3 {
static constexpr float gravity = 9.81;
static constexpr float stepRate_hz = 2.0;
static constexpr float cutOff_hz = 3.0;
static constexpr float iirQ = 0.70;
static constexpr int sRate_hz = 100;
static constexpr int every_ms = 1000 / sRate_hz;
static constexpr float threshold = 1.0;
float threshold = 0.8;
float max = 0;
Timestamp maxTS;
@@ -48,8 +51,8 @@ class StepDetection3 {
private:
FixedFrequencyInterpolator<AccelerometerData> interpol;
IIR::BiQuad<float> biquad;
DelayBuffer<float> delay;
IIR::BiQuadStack<float> biquad;
DelayBuffer<float> lookBehind;
@@ -72,10 +75,23 @@ private:
public:
/** ctor */
StepDetection3() : interpol(Timestamp::fromMS(every_ms)), delay(10) {
StepDetection3(bool useBandPass) : interpol(Timestamp::fromMS(every_ms)), lookBehind(5) {
biquad.setBandPass(stepRate_hz, 1.0, sRate_hz);
biquad.preFill(gravity);
//biquad.setBandPass(stepRate_hz, 1.5, sRate_hz);
//biquad.preFill(gravity);
if (useBandPass) {
biquad.resize(3);
biquad[0].setHighPass(1, 0.7, sRate_hz);
biquad[1].setLowPass(3.0, 0.7, sRate_hz);
biquad[2].setLowPass(3.0, 1.0, sRate_hz);
//biquad.setBandPass(2, 3.0, sRate_hz);
threshold = 0.6; // needs a little reduction
} else {
threshold = 0.8;
biquad.resize(1);
biquad[0].setLowPass(3, 0.7, sRate_hz);
}
#ifdef WITH_DEBUG_PLOT
gp << "set autoscale xfix\n";
@@ -105,10 +121,10 @@ public:
const float mag = data.magnitude();
// apply filter
const float fMag = biquad.filter(mag);
const float fMag = biquad.filter(mag - 9.81); // remove gravity
// history buffer
float fMagOld = delay.add(fMag);
float fMagOld = lookBehind.add(fMag);
// zero crossing?
float tmp = max;
@@ -117,16 +133,22 @@ public:
step = true;
gotStep = true;
}
delay.setAll(0);
lookBehind.setAll(0);
max = 0;
}
// track maximum value
if (fMag > max) {max = fMag; maxTS = ts;}
#ifdef WITH_DEBUG_OUTPUT
if (step) {
std::cout << ts.ms() << std::endl;
// // track delay due to zero crossing
// const float tsDelay = ts.ms() - maxTS.ms();
// std::cout << "step at " << ts.ms() << ". delay due to zero crossing: " << tsDelay << std::endl;
outSteps << maxTS.ms() << " " << tmp << "\n";
outSteps.flush();
}