fixed some plotting issues
modified step detection
This commit is contained in:
@@ -1,6 +1,63 @@
|
||||
#ifndef LOCALMAXIMA_H
|
||||
#define LOCALMAXIMA_H
|
||||
|
||||
#include "Delay.h"
|
||||
|
||||
class LocalMaxima {
|
||||
|
||||
int delay;
|
||||
Delay<float> d0;
|
||||
Delay<float> d1;
|
||||
float cur;
|
||||
int block = 0;
|
||||
|
||||
public:
|
||||
|
||||
LocalMaxima(int delay) : delay(delay), d0(delay*2), d1(delay) {
|
||||
;
|
||||
}
|
||||
|
||||
bool add(const float s) {
|
||||
|
||||
if (block > 0) {--block;}
|
||||
|
||||
d0.add(s);
|
||||
d1.add(s);
|
||||
this->cur = s;
|
||||
|
||||
if (isMax()) {
|
||||
block = delay;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
float get() {
|
||||
return d1.get();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
bool isMax() {
|
||||
|
||||
if (block > 0) {return false;}
|
||||
|
||||
if (!d0.isValid()) {return false;}
|
||||
if (!d1.isValid()) {return false;}
|
||||
|
||||
const float s0 = d0.get();
|
||||
const float s1 = d1.get();
|
||||
const float s2 = cur;
|
||||
|
||||
return (s1 > s0) && (s1 > s2);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
class LocalMaxima {
|
||||
|
||||
static constexpr float MAX = 1e40;
|
||||
@@ -21,12 +78,12 @@ public:
|
||||
Res(bool isMax, float val) : isMax(isMax), val(val) {;}
|
||||
};
|
||||
|
||||
/** ctor. use only every n-th sample */
|
||||
// ctor. use only every n-th sample
|
||||
LocalMaxima(const size_t everyNth) : everyNth(everyNth) {
|
||||
reset();
|
||||
}
|
||||
|
||||
/** is the given value a local maxima? */
|
||||
// is the given value a local maxima?
|
||||
Res add(const float s) {
|
||||
|
||||
if (cnt == 0*everyNth) {s0 = s;} // set, wait some time
|
||||
@@ -60,5 +117,5 @@ private:
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
*/
|
||||
#endif // LOCALMAXIMA_H
|
||||
|
||||
Reference in New Issue
Block a user