Commit f11f0886 authored by mzed's avatar mzed
Browse files

bayes filter seems to be running?

parent a97d656d
......@@ -13,7 +13,7 @@ RL_SVM=src/svmClassification.cpp dependencies/libsvm/libsvm.cpp
RL_NN=src/neuralNetwork.cpp src/regression.cpp
RL_MS=src/modelSet.cpp
RL_DTW=src/warpPath.cpp src/searchWindow.cpp src/dtw.cpp src/fastDTW.cpp src/seriesClassification.cpp
RL_STREAM=src/rapidStream.cpp
RL_STREAM=src/rapidStream.cpp dependencies/bayesfilter/src/BayesianFilter.cpp dependencies/bayesfilter/src/filter_utilities.cpp
SOURCE_RAPID = $(RL_MS) $(RL_NN) $(RL_KNN) $(RL_SVM) $(RL_DTW) $(RL_STREAM)
# destination .js file
......
......@@ -6,9 +6,15 @@
#include "regression.h"
#include "classification.h"
#include "seriesClassification.h"
#include "rapidStream.h"
int main(int argc, const char * argv[]) {
rapidStream<double> rapidProcess;
for (int i = 0; i < 100; ++i) {
std::cout << "bayes " << rapidProcess.bayesFilter(i/100.) << std::endl;
}
//vanAllenTesting
seriesClassification testDTW;
std::vector<trainingSeries> testVector;
......
......@@ -622,6 +622,13 @@ Module.StreamBuffer.prototype = {
rms: function () {
return this.rapidStream.rms();
},
/**
* Non-linear Bayesian filtering for EMG
* @return {number} envelope
*/
bayesFilter: function (input) {
return this.rapidStream.bayesFilter(parseFloat(input));
},
/**
* Calculate the minimum first-order difference over consecutive inputs in the buffer.
* @return {number} minimum velocity.
......
......@@ -27,6 +27,7 @@ EMSCRIPTEN_BINDINGS(rapidStream_module) {
.function("mean", &rapidStream<double>::mean)
.function("standardDeviation", &rapidStream<double>::standardDeviation)
.function("rms", &rapidStream<double>::rms)
.function("bayesFilter", &rapidStream<double>::bayesFilter)
.function("minVelocity", &rapidStream<double>::minVelocity)
.function("maxVelocity", &rapidStream<double>::maxVelocity)
.function("minAcceleration", &rapidStream<double>::minAcceleration)
......
......@@ -22,6 +22,13 @@ rapidStream<T>::rapidStream(int window_size) {
for (int i = 0; i < windowSize; ++i) {
circularWindow[i] = 0;
}
//Baysian Filter setup
bayesFilt.diffusion = powf(10., -2);
bayesFilt.jump_rate = powf(10., -5);
bayesFilt.mvc[0] = 1.;
bayesFilt.init();
}
template<typename T>
......@@ -126,6 +133,12 @@ T rapidStream<T>::rms() {
return sqrt(rms);
}
template<typename T>
T rapidStream<T>::bayesFilter(T input) {
std::vector<float> inputVec = { float(input) };
bayesFilt.update(inputVec);
return T(bayesFilt.output[0]);
}
template<typename T>
T rapidStream<T>::minVelocity() {
T minVel = std::numeric_limits<T>::infinity();
......
......@@ -9,6 +9,7 @@
#define rapidStream_h
#include <stdint.h>
#include "../dependencies/bayesfilter/src/BayesianFilter.h"
template<typename T>
class rapidStream {
......@@ -76,6 +77,11 @@ public:
*/
T rms();
/** Non-linear Baysian filtering for EMG envelope extraction.
* @return current envelope value
*/
T bayesFilter(T inputValue);
/** Calculate the minimum first-order difference over consecutive inputs in the buffer.
* @return double: minimum velocity.
*/
......@@ -102,7 +108,9 @@ private:
T *circularWindow;
T calcCurrentVel(int i);
BayesianFilter bayesFilt;
};
#endif
\ No newline at end of file
#endif
......@@ -447,4 +447,8 @@ describe('RapidLib Signal Processing', function () {
expect(velStream.maxAcceleration()).to.equal(45.63999999999999);
});
});
describe('when streaming to bayesFilter', function() {
let bf = new rapidMix.StreamBuffer();
console.log("ok " + bf.bayesFilter(0.2));
});
});
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment