diff options
author | Ching-Kang Yen <chingkang@chromium.org> | 2020-09-18 00:29:51 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-09-29 13:31:20 +0000 |
commit | 9513a63a626021b071199d02b7c73112eb746833 (patch) | |
tree | 17dd2259d9c0e1a617e0814f20785405b10cd17a | |
parent | 17d47b68f8730a5404e9d2379a4b1a20c87d045b (diff) | |
download | chrome-ec-9513a63a626021b071199d02b7c73112eb746833.tar.gz |
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 <chingkang@chromium.org>
Change-Id: I2a7416b0bd8d0aac51d16c3aed9d962837f52c0b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2416477
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Heng-ruey Hsu <henryhsu@chromium.org>
-rw-r--r-- | common/body_detection.c | 11 | ||||
-rw-r--r-- | include/config.h | 4 |
2 files changed, 14 insertions, 1 deletions
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 */ |