From 9632d9124087b93ec0296919c87467645f5a3834 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 30 Oct 2017 20:03:36 +0100 Subject: [PATCH] FIX: absolute value when comparing against threhold --- client/graph.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/graph.c b/client/graph.c index b09d30ad4..6e57e331d 100644 --- a/client/graph.c +++ b/client/graph.c @@ -272,16 +272,16 @@ bool is_justnoise(int *bits, uint32_t size) { //might not be high enough for noisy environments #define NOICE_AMPLITUDE_THRESHOLD 10; - uint32_t sum = 0, mean = 0, high = 0, low = 255; + int32_t sum = 0, mean = 0, high = -127, low = 127; for ( size_t i = 0; i < size; i++) { if ( bits[i] < low ) low = bits[i]; if ( bits[i] > high ) high = bits[i]; sum += bits[i]; } - mean = sum / size; + mean = sum / (int)size; // measure amplitude of signal - bool isnoise = (high - mean) < NOICE_AMPLITUDE_THRESHOLD; + bool isnoise = ABS(high - mean) < NOICE_AMPLITUDE_THRESHOLD; if (g_debugMode == 2) PrintAndLog("DEBUG: (is_justnoise) mean %u | hi %u | low %u | IS NOISE %c", mean, high, low, isnoise?'Y':'N');