shake.js icon indicating copy to clipboard operation
shake.js copied to clipboard

Calibrate threshold

Open roccomuso opened this issue 9 years ago • 2 comments

I noticed that threshold needs to be adjusted from device to device. There isn't a way to calibrate it?

roccomuso avatar Jan 21 '16 16:01 roccomuso

If yourself or anyone else can find a reliable way to do this pull requests are welcome

alexgibson avatar Jan 21 '16 16:01 alexgibson

You take a direct difference between accelerations (https://github.com/alexgibson/shake.js/blob/master/shake.js#L100) without accounting for the sampling frequency. That means that any variance in sampling frequency will change the effective threshold. You should at a minimum divide the difference by e.interval, and ideally perform smoothing on the values to simulate a consistent low sampling rate.

Those changes should make this perform near-identically on all devices.

davidje13 avatar Oct 06 '18 21:10 davidje13