summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/body_detection.c11
-rw-r--r--include/config.h4
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 */