So, I have gesture detection working relatively well, the next hurdle is speed of the gesture. It sounds like a relatively simple problem to solve, but it’s deceptively complex, especially since we’re dealing with a series of data points.

In the video above, I am using a simple moving average on stream 3 of the input. Whenever the current data point drops below the moving average, that’s considered an “out”, when it drops above, that’s considered an “in”, the result is data that looks something like this:

Whenever the data value crosses the moving average in any direction, I consider that a “tick”. I then count the number of ticks in the last n samples to get an average speed during those samples.

It works surprisingly well, you could increase the number of samples to get a smoother speed calculation, but I think a responsive value is better. I am currently summing across 16 ticks.

In theory, a Fast Fourier Transform should be able to give me the frequency of the signal I am recording and that frequency could be used to approximate speed of the “hand job” gesture. In practice, I think the moving average approach is relatively computationally cheap as well as robust.