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,8 +22,9 @@
#endif
#include "../../Assertions.h"
#include "../../math/dsp/fir/Real.h"
#include "../../math/dsp/fir/RealFactory.h"
#include "../../math/dsp/iir/BiQuadStack.h"
//#include "../../math/dsp/fir/Real.h"
//#include "../../math/dsp/fir/RealFactory.h"
#include "../../math/FixedFrequencyInterpolator.h"
#include "../../math/LocalMaxima.h"
#include "../../math/MovingAverageTS.h"
@@ -36,19 +37,20 @@
*/
class StepDetection2 {
static constexpr int sRate_hz = 75;
static constexpr int sRate_hz = 100;
static constexpr int every_ms = 1000 / sRate_hz;
private:
FixedFrequencyInterpolator<AccelerometerData> interpol;
FIR::Real::Filter fir;
//FIR::Real::Filter fir;
IIR::BiQuadStack<float> biquad;
LocalMaxima locMax;
// longterm average to center around zero
MovingAverageTS<float> avg = MovingAverageTS<float>(Timestamp::fromMS(2000), 0);
const float threshold = 0.50;
float threshold = 0.50;
#ifdef WITH_DEBUG_PLOT
K::Gnuplot gp;
@@ -69,16 +71,28 @@ private:
public:
/** ctor */
StepDetection2() : interpol(Timestamp::fromMS(every_ms)), locMax(8) {
StepDetection2(bool useBandPass) : interpol(Timestamp::fromMS(every_ms)), locMax(8) {
//fir.lowPass(0.66, 40); // allow deviation of +/- 0.66Hz
//fir.shiftBy(2.00); // typical step freq ~2Hz
//fir.lowPass(3.5, 25); // everything up to 3 HZ
FIR::Real::Factory fac(sRate_hz);
fir.setKernel(fac.getBandpass(0.66, 2.0, 40));
//FIR::Real::Factory fac(sRate_hz);
//fir.setKernel(fac.getBandpass(0.66, 2.0, 40));
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";
@@ -98,7 +112,7 @@ public:
/** does the given data indicate a step? */
bool add(const Timestamp ts, const AccelerometerData& acc) {
bool step = false;
bool gotStep = false;
// accel-data incoming on a fixed sampling rate (needed for FIR to work)
auto onResample = [&] (const Timestamp ts, const AccelerometerData data) {
@@ -109,17 +123,16 @@ public:
avg.add(ts, mag);
const float mag0 = mag - avg.get();
//const std::complex<float> c = fir.append(mag0);
//const float real = c.real();
//if (real != real) {return;}
//const float fMag = real;
const float f = fir.append(mag0);
if (f != f) {return;}
// const float f = fir.append(mag0);
// if (f != f) {return;}
const float f = biquad.filter(mag0);
const float fMag = f;
const bool isMax = locMax.add(fMag);
step = (isMax) && (locMax.get() > threshold);
const bool step = (isMax) && (locMax.get() > threshold);
if (step) {gotStep = true;}
#ifdef WITH_DEBUG_OUTPUT
if (step) {
@@ -163,7 +176,7 @@ public:
// ensure fixed sampling rate for FIR freq filters to work!
interpol.add(ts, acc, onResample);
return step;
return gotStep;
}