summaryrefslogtreecommitdiff
path: root/common/body_detection.c
diff options
context:
space:
mode:
authorChing-Kang Yen <chingkang@chromium.org>2020-10-06 23:27:21 +0800
committerCommit Bot <commit-bot@chromium.org>2020-11-06 06:02:48 +0000
commit4d8de47ad47141bbc070725a0a4359a126bbb962 (patch)
tree934b87c5786d3a21859964067a86b4a9adc6f2b1 /common/body_detection.c
parent8f91458a1b888bb75f6f4d3ffe4d0de1a221a589 (diff)
downloadchrome-ec-4d8de47ad47141bbc070725a0a4359a126bbb962.tar.gz
common: body_detection: modify variance updating formula
Modify the variance formula to speed up body detection. BRANCH=None BUG=b:123434029 TEST=make buildall; TEST=make BOARD=ampton, re-flash the DUT, see if the body detection works Signed-off-by: Ching-Kang Yen <chingkang@chromium.org> Change-Id: Ib444abb6bdfbc637539103d563b515817865acc9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2452133 Reviewed-by: Heng-ruey Hsu <henryhsu@chromium.org>
Diffstat (limited to 'common/body_detection.c')
-rw-r--r--common/body_detection.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/common/body_detection.c b/common/body_detection.c
index 334009e320..375b4456d0 100644
--- a/common/body_detection.c
+++ b/common/body_detection.c
@@ -48,18 +48,18 @@ static struct body_detect_motion_data
* x_0: oldest value in the window, will be replaced by x_n
* x_n: new coming value
*
- * n^2 * var(x') = n^2 * var(x) + (sum(x') - sum(x))^2 +
- * (n * x_n - sum(x'))^2 / n - (n * x_0 - sum(x'))^2 / n
+ * n^2 * var(x') = n^2 * var(x) + (x_n - x_0) *
+ * (n * (x_n + x_0) - sum(x') - sum(x))
*/
static void update_motion_data(struct body_detect_motion_data *x, int x_n)
{
const int n = window_size;
const int x_0 = x->history[history_idx];
- const int new_sum = x->sum + (x_n - x->history[history_idx]);
+ const int sum_diff = x_n - x_0;
+ const int new_sum = x->sum + sum_diff;
- x->n2_variance = x->n2_variance + POW2((int64_t)new_sum - x->sum) +
- (POW2((int64_t)x_n * n - new_sum) -
- POW2((int64_t)x_0 * n - new_sum)) / n;
+ x->n2_variance += sum_diff *
+ ((int64_t)n * (x_n + x_0) - new_sum - x->sum);
x->sum = new_sum;
x->history[history_idx] = x_n;
}