match the stream against that pattern regardless of time stretching. devicemotion((e) => { let { motions } = this; motions.unshift(e); if (motions.length > 32) motions.pop(); let xs = motions.map(e => e.acceleration.x); let ys = motions.map(e => e.acceleration.y); let zs = motions.map(e => e.acceleration.z); let slashDTWX = new DTW(); let slashDTWY = new DTW(); let slashDTWZ = new DTW(); let slashCostX = slashDTWX.compute(xs, [-0.2486258743215352,-0.2486258743215352, ...]); let slashCostY = slashDTWY.compute(ys, [-0.35158794388510284,-0.35158794388510284, ...]); let slashCostZ = slashDTWZ.compute(zs, [0.14063087035836652,0.14063087035836652, ...]); let stillDTWX = new DTW(); let stillDTWY = new DTW(); let stillDTWZ = new DTW(); let stillCostX = stillDTWX.compute(xs, [0, 0, 0, 0]); let stillCostY = stillDTWY.compute(ys, [0, 0, 0, 0]); let stillCostZ = stillDTWZ.compute(zs, [0, 0, 0, 0]); let slashCost = slashCostX + slashCostY + slashCostZ; let stillCost = stillCostX + stillCostY + slashCostZ; if (slashCost < stillCost) { dbg('dm cost: slash', slashCost); dbg('dm cost: still', stillCost); this.triggerSound(); motions.length = 0; } });