This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/math/stats/SampleRateEstimator.h
frank 857d7a1553 fixed some issues
added new pose/turn detections
new helper classes
define-flags for libEigen
2018-09-04 10:49:00 +02:00

42 lines
609 B
C++

#ifndef SAMPLERATEESTIMATOR_H
#define SAMPLERATEESTIMATOR_H
#include "../../data/Timestamp.h"
class SampleRateEstimator {
private:
const double a = 0.99;
double curHz = 0;
Timestamp tsLast;
public:
float update(const Timestamp ts) {
// first
if (tsLast.isZero()) {
tsLast = ts;
return 0;
}
const double diffSec = static_cast<double>((ts-tsLast).sec());
tsLast = ts;
if (diffSec != 0) {
curHz = a*curHz + (1-a) * (1.0/diffSec);
}
return static_cast<float>(curHz);
}
float getCurHz() const {
return static_cast<float>(curHz);
}
};
#endif // SAMPLERATEESTIMATOR_H