ESP  0.1
The Example-based Sensor Predictions (ESP) system tries to bring machine learning to the maker community.
user_sudden_motion.cpp

Detect sudden motions.

#include <ESP.h>
GestureRecognitionPipeline pipeline;
double zeroG = 0, oneG = 0;
double processAccelerometerData(double input) {
return (input - zeroG) / (oneG - zeroG);
}
CalibrateResult restingDataCollected(const MatrixDouble& data) {
// take average of X and Y acceleration as the zero G value
zeroG = (data.getMean()[0] + data.getMean()[1]) / 2;
oneG = data.getMean()[2]; // use Z acceleration as one G value
}
int num_dim = 3;
void setup() {
calibrator.addCalibrateProcess("Resting",
"Rest accelerometer on flat surface.", restingDataCollected);
useCalibrator(calibrator);
pipeline.addPreProcessingModule(
Derivative(Derivative::FIRST_DERIVATIVE, 1, num_dim));
pipeline.addFeatureExtractionModule(
ZeroCrossingCounter(3, 0.1, num_dim, ZeroCrossingCounter::COMBINED_FEATURE_MODE));
}