Can we use a High-Pass filter on an observable stream to detect a shake event?

326 views Asked by At

Specifically, if we have a stream of events representing x/y/z acceleration on device, which rxjs can give us, how could we implement this algorithm high-pass filter in a streaming fashion in order to utilize a longer sliding window of samples in shake detection ?

Shake.js approach is promising but based only on 2 consecutive samples, and 2 samples do not a signal stream make.

I feel like once shown how to use signal processing concepts I'm familiar with from audio/music work upon streaming user input data, my ability to leverage this framework will really take off, thanks in advance.

1

There are 1 answers

2
cwharris On BEST ANSWER

This is what I was able to do by converting the implementation found on Wikipedia.

Rx.Observable.prototype.highpass = function (rc) {
  return this
    .timestamp()
    .bufferWithCount(2, 1)
    .scan(0, function (acc, x) {
      var dt = x[1].timestamp - x[0].timestamp;
      var a = rc / (rc + dt);
      return a * (acc + (x[1].value - x[0].value));
    });
};

The following example doesn't work super great. Anyway, it still serves a purpose, assuming you keep the mouse moving.

http://jsfiddle.net/xixonia/j2H3k/