diff --git a/armsrc/fpgaloader.c b/armsrc/fpgaloader.c index a24c98049..e7a691811 100644 --- a/armsrc/fpgaloader.c +++ b/armsrc/fpgaloader.c @@ -231,7 +231,7 @@ static bool reset_fpga_stream(int bitstream_version, z_streamp compressed_fpga_s header[i] = get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer); // Check for a valid .bit file (starts with _bitparse_fixed_header) - if(memcmp(_bitparse_fixed_header, header, FPGA_BITSTREAM_FIXED_HEADER_SIZE) == 0) + if (memcmp(_bitparse_fixed_header, header, FPGA_BITSTREAM_FIXED_HEADER_SIZE) == 0) return true; return false; diff --git a/armsrc/fpgaloader.h b/armsrc/fpgaloader.h index ededa3579..95eaab8ba 100644 --- a/armsrc/fpgaloader.h +++ b/armsrc/fpgaloader.h @@ -85,14 +85,10 @@ extern void switch_off(); #define FPGA_HF_ISO14443A_READER_LISTEN (3<<0) #define FPGA_HF_ISO14443A_READER_MOD (4<<0) - //options for Felica. #define FPGA_MAJOR_MODE_ISO18092 (5<<5) #define FPGA_HF_ISO18092_FLAG_NOMOD (1<<0) //disable modulation module #define FPGA_HF_ISO18092_FLAG_424K (2<<0) // should enable 414k mode (untested). No autodetect #define FPGA_HF_ISO18092_FLAG_READER (4<<0) // enables antenna power, to act as a reader instead of tag - - - #endif \ No newline at end of file diff --git a/client/graph.c b/client/graph.c index 457e4ae14..b09d30ad4 100644 --- a/client/graph.c +++ b/client/graph.c @@ -265,16 +265,29 @@ uint8_t fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, bool verbose, int *f return 1; } -// test samples are not just noise +//test samples are not just noise +// By measuring mean and look at amplitude of signal from HIGH / LOW, +// we can detect noise bool is_justnoise(int *bits, uint32_t size) { //might not be high enough for noisy environments - #define NOICE_THRESHOLD 15; + #define NOICE_AMPLITUDE_THRESHOLD 10; - // if we take the mean on the sample set and see if its - // below the threshold, it will be a better indicator - int32_t mean = compute_mean_int(bits, size); - return mean < NOICE_THRESHOLD; + uint32_t sum = 0, mean = 0, high = 0, low = 255; + 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; + // measure amplitude of signal + bool isnoise = (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'); + + return isnoise; + /* bool isNoise = true; for(int i=0; i < size && isNoise; i++) diff --git a/common/lfdemod.c b/common/lfdemod.c index 5dedc73ed..2cdbb5cbc 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -65,8 +65,9 @@ void dummy(char *fmt, ...){} uint32_t compute_mean_uint(uint8_t *in, size_t N) { uint32_t mean = 0; for (size_t i = 0; i < N; i++) - mean += in[i]; - return (uint32_t)mean/N; + mean += in[i]; + + return mean / N; } // Function to compute mean for a series // rounded to integer.. @@ -74,22 +75,33 @@ int32_t compute_mean_int(int *in, size_t N) { int32_t mean = 0; for (size_t i = 0; i < N; i++) mean += in[i]; - return (int32_t)mean/N; + + return mean / (int)N; } //test samples are not just noise +// By measuring mean and look at amplitude of signal from HIGH / LOW, +// we can detect noise bool justNoise(uint8_t *bits, size_t size) { - // if we take the mean on the sample set and see if its - // below the threshold, it will be a better indicator - uint32_t mean = compute_mean_uint(bits, size); - uint8_t counter = 0; - for ( size_t i = 0; i < size && counter < 10; i++) { - if ( bits[i] > mean ) counter++; - } - if (g_debugMode == 2) prnt("DEBUG: (justNoise) mean %u | %i | counter %u", mean, FSK_PSK_THRESHOLD, counter); - return counter < 10; + //might not be high enough for noisy environments + #define NOICE_AMPLITUDE_THRESHOLD 10; + uint32_t sum = 0, mean = 0, high = 0, low = 255; + 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; + // measure amplitude of signal + bool isnoise = (high - mean) < NOICE_AMPLITUDE_THRESHOLD; + + if (g_debugMode == 2) + prnt("DEBUG: (justNoise) mean %u | hi %u | low %u | IS NOISE %c", mean, high, low, isnoise?'Y':'N'); + + return isnoise; /* // loop until a sample is larger than threshold. // one sample above threshold is not a good indicator.