From 9513a63a626021b071199d02b7c73112eb746833 Mon Sep 17 00:00:00 2001 From: Ching-Kang Yen Date: Fri, 18 Sep 2020 00:29:51 +0800 Subject: common: body_detection: modify calculation of noise level We used rms_noise^2 as noise level for body_detection. But, there are still some different noise level based on different devices. Add the CONFIG_BODY_DETECTION_VAR_NOISE_FACTOR to adjust the noise_level. Default value is 120%, since the 100% of the rms_noise^2 is not enough, especially in 200Hz. BRANCH=None BUG=b:123434029 TEST=make buildall; make BOARD=ampton, re-flash the DUT, see if the body detection works Signed-off-by: Ching-Kang Yen Change-Id: I2a7416b0bd8d0aac51d16c3aed9d962837f52c0b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2416477 Reviewed-by: Gwendal Grignou Reviewed-by: Heng-ruey Hsu --- common/body_detection.c | 11 ++++++++++- include/config.h | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/common/body_detection.c b/common/body_detection.c index 020314e71e..f7ea95c8c4 100644 --- a/common/body_detection.c +++ b/common/body_detection.c @@ -147,7 +147,16 @@ static void determine_threshold_scale(int range, int resolution, int rms_noise) const int data_1g = BIT(resolution - 1) / range; const int multiplier = POW2(data_1g); const int divisor = POW2(9800); - const int var_noise = POW2((int64_t)rms_noise) * POW2(98) / POW2(10000); + /* + * We are measuring the var(X) + var(Y), so theoretically, the + * var(noise) should be 2 * rms_noise^2. However, in most case, on a + * very stationary plane, the average of var(noise) are less than 2 * + * rms_noise^2. We can multiply the rms_noise^2 with the + * CONFIG_BODY_DETECTION_VAR_NOISE_FACTOR / 100. + */ + const int var_noise = POW2((uint64_t)rms_noise) * + CONFIG_BODY_DETECTION_VAR_NOISE_FACTOR * POW2(98) + / 100 / POW2(10000); var_threshold_scaled = (uint64_t) (CONFIG_BODY_DETECTION_VAR_THRESHOLD + var_noise) * diff --git a/include/config.h b/include/config.h index bc95e85046..c80636f33d 100644 --- a/include/config.h +++ b/include/config.h @@ -190,6 +190,9 @@ #undef CONFIG_BODY_DETECTION_VAR_THRESHOLD #undef CONFIG_BODY_DETECTION_CONFIDENCE_DELTA +/* How much noise affect threshold of variance */ +#undef CONFIG_BODY_DETECTION_VAR_NOISE_FACTOR + /* The confidence limit of on_body/off_body */ #undef CONFIG_BODY_DETECTION_ON_BODY_CON #undef CONFIG_BODY_DETECTION_OFF_BODY_CON @@ -5728,6 +5731,7 @@ #define CONFIG_BODY_DETECTION_MAX_WINDOW_SIZE 250 /* max sensor odr (Hz) */ #define CONFIG_BODY_DETECTION_VAR_THRESHOLD 550 /* (mm/s^2)^2 */ #define CONFIG_BODY_DETECTION_CONFIDENCE_DELTA 525 /* (mm/s^2)^2 */ +#define CONFIG_BODY_DETECTION_VAR_NOISE_FACTOR 120 /* % */ #define CONFIG_BODY_DETECTION_ON_BODY_CON 50 /* % */ #define CONFIG_BODY_DETECTION_OFF_BODY_CON 10 /* % */ #define CONFIG_BODY_DETECTION_STATIONARY_DURATION 15 /* second */ -- cgit v1.2.1