apply @holiman s graph changes +

add demod data to graph.
some bugs are known:
if you close the graph window data plot will not bring it back.
exiting the application without closing the widget form results in
error.
autocorrect graph y labels are ugly
form has old askdemod tab.
sticky button purpose not defined/labeled well.
doesn't clear s_Buff when new graph loaded or sampled.
probably more...
This commit is contained in:
marshmellow42 2017-04-12 14:35:07 -04:00
commit b8fdac9e6f
12 changed files with 995 additions and 185 deletions

View file

@ -18,6 +18,9 @@
int GraphBuffer[MAX_GRAPH_TRACE_LEN];
int GraphTraceLen;
int s_Buff[MAX_GRAPH_TRACE_LEN];
/* write a manchester bit to the graph */
void AppendGraph(int redraw, int clock, int bit)
{
@ -290,3 +293,57 @@ bool graphJustNoise(int *BitStream, int size)
}
return justNoise1;
}
int autoCorr(const int* in, int *out, size_t len, int window)
{
static int CorrelBuffer[MAX_GRAPH_TRACE_LEN];
if (window == 0) {
PrintAndLog("needs a window");
return 0;
}
if (window >= len) {
PrintAndLog("window must be smaller than trace (%d samples)",
len);
return 0;
}
PrintAndLog("performing %d correlations", len - window);
for (int i = 0; i < len - window; ++i) {
int sum = 0;
for (int j = 0; j < window; ++j) {
sum += (in[j]*in[i + j]) / 256;
}
CorrelBuffer[i] = sum;
}
//GraphTraceLen = GraphTraceLen - window;
memcpy(out, CorrelBuffer, len * sizeof (int));
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 (int 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;
}