FIX: detect noise signal by measuring amplitude of signal.

This commit is contained in:
iceman1001 2017-10-30 19:18:30 +01:00
parent 6f948be842
commit db56ca11a3
4 changed files with 44 additions and 23 deletions

View file

@ -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;

View file

@ -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

View file

@ -265,15 +265,28 @@ 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;

View file

@ -66,7 +66,8 @@ 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;
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.