From 998d752bd5e5712720fe218afd0ce008bb8de5a9 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 27 Jul 2017 22:17:16 +0200 Subject: [PATCH] more directionalThreshold... --- client/cmddata.c | 51 ++++++++++++++++++++++++++---------------------- client/cmddata.h | 9 +++++---- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/client/cmddata.c b/client/cmddata.c index 49c90aa7f..5931c23c2 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -2397,6 +2397,33 @@ int CmdScale(const char *Cmd) RepaintGraphWindow(); return 0; } +int directionalThreshold(const int* in, int *out, size_t len, int8_t up, int8_t down) +{ + int lastValue = in[0]; + out[0] = 0; // Will be changed at the end, but init 0 as we adjust to last samples value if no threshold kicks in. + + for (size_t i = 1; i < len; ++i) { + // Apply first threshold to samples heading up + if (in[i] >= up && in[i] > lastValue) + { + lastValue = out[i]; // Buffer last value as we overwrite it. + out[i] = 1; + } + // Apply second threshold to samples heading down + else if (in[i] <= down && in[i] < lastValue) + { + lastValue = out[i]; // Buffer last value as we overwrite it. + out[i] = -1; + } + else + { + lastValue = out[i]; // Buffer last value as we overwrite it. + out[i] = out[i-1]; + } + } + out[0] = out[1]; // Align with first edited sample. + return 0; +} int CmdDirectionalThreshold(const char *Cmd) { @@ -2405,29 +2432,7 @@ int CmdDirectionalThreshold(const char *Cmd) printf("Applying Up Threshold: %d, Down Threshold: %d\n", upThres, downThres); - int lastValue = GraphBuffer[0]; - GraphBuffer[0] = 0; // Will be changed at the end, but init 0 as we adjust to last samples value if no threshold kicks in. - - for (int i = 1; i < GraphTraceLen; ++i) { - // Apply first threshold to samples heading up - if (GraphBuffer[i] >= upThres && GraphBuffer[i] > lastValue) - { - lastValue = GraphBuffer[i]; // Buffer last value as we overwrite it. - GraphBuffer[i] = 1; - } - // Apply second threshold to samples heading down - else if (GraphBuffer[i] <= downThres && GraphBuffer[i] < lastValue) - { - lastValue = GraphBuffer[i]; // Buffer last value as we overwrite it. - GraphBuffer[i] = -1; - } - else - { - lastValue = GraphBuffer[i]; // Buffer last value as we overwrite it. - GraphBuffer[i] = GraphBuffer[i-1]; - } - } - GraphBuffer[0] = GraphBuffer[1]; // Aline with first edited sample. + directionalThreshold(GraphBuffer, GraphBuffer,GraphTraceLen, upThres, downThres); RepaintGraphWindow(); return 0; } diff --git a/client/cmddata.h b/client/cmddata.h index e62aa8a07..9c5872e04 100644 --- a/client/cmddata.h +++ b/client/cmddata.h @@ -16,9 +16,6 @@ #include //bool #include "cmdparser.h" // for command_t -#define MAX_DEMOD_BUF_LEN (1024*128) -#define BIGBUF_SIZE 40000 - command_t * CmdDataCommands(); int CmdData(const char *Cmd); @@ -80,11 +77,15 @@ void printEM410x(uint32_t hi, uint64_t id); int getSamples(const char *Cmd, bool silent); void setGrid_Clock(uint8_t clock); - +int directionalThreshold(const int* in, int *out, size_t len, int8_t up, int8_t down); int CmdDataIIR(const char *Cmd); +#define MAX_DEMOD_BUF_LEN (1024*128) +#define BIGBUF_SIZE 40000 extern uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN]; extern size_t DemodBufferLen; +extern int g_DemodStartIdx; +extern int g_DemodClock; extern uint8_t g_debugMode; #endif