From d1e553f05a4f24ef7e531e15c12ceb74666fd1a9 Mon Sep 17 00:00:00 2001 From: Ryzerth Date: Sat, 17 Apr 2021 03:38:48 +0200 Subject: [PATCH] Fixes to filtering --- core/src/dsp/processing.h | 4 ++- core/src/dsp/utils/math.h | 4 +-- core/src/dsp/utils/window_functions.h | 18 ++++++------- core/src/dsp/window.h | 37 ++++++++------------------- core/src/gui/widgets/waterfall.cpp | 3 +++ core/src/gui/widgets/waterfall.h | 8 ++++++ root/res/colormaps/electric.json | 10 ++++++++ 7 files changed, 45 insertions(+), 39 deletions(-) create mode 100644 root/res/colormaps/electric.json diff --git a/core/src/dsp/processing.h b/core/src/dsp/processing.h index 7f8724f2..fce713ac 100644 --- a/core/src/dsp/processing.h +++ b/core/src/dsp/processing.h @@ -123,8 +123,10 @@ namespace dsp { level = pow(10, ((10.0f * log10f(level)) - (_CorrectedFallRate * count)) / 10.0f); + float absVal; for (int i = 0; i < count; i++) { - if (_in->readBuf[i] > level) { level = _in->readBuf[i]; } + absVal = fabsf(_in->readBuf[i]); + if (absVal > level) { level = absVal; } } volk_32f_s32f_multiply_32f(out.writeBuf, _in->readBuf, 1.0f / level, count); diff --git a/core/src/dsp/utils/math.h b/core/src/dsp/utils/math.h index 17fe733b..fcae2f46 100644 --- a/core/src/dsp/utils/math.h +++ b/core/src/dsp/utils/math.h @@ -5,8 +5,8 @@ namespace dsp { namespace math { - inline float sinc(float omega, float x, float norm) { - return (x == 0.0f) ? 1.0f : (sinf(omega*x)/(norm*x)); + inline double sinc(double omega, double x, double norm) { + return (x == 0.0f) ? 1.0f : (sin(omega*x)/(norm*x)); } } } \ No newline at end of file diff --git a/core/src/dsp/utils/window_functions.h b/core/src/dsp/utils/window_functions.h index 5f2dd4a0..c3a1379b 100644 --- a/core/src/dsp/utils/window_functions.h +++ b/core/src/dsp/utils/window_functions.h @@ -3,25 +3,25 @@ namespace dsp { namespace window_function { - inline float blackman(float n, float N, float alpha = 0.16f) { - float a0 = (1.0f-alpha) / 2.0f; - float a2 = alpha / 2.0f; - return a0 - (0.5f*cosf(2.0f*FL_M_PI*(n/N))) + (a2*cosf(4.0f*FL_M_PI*(n/N))); + inline double blackman(double n, double N, double alpha = 0.16f) { + double a0 = (1.0f-alpha) / 2.0f; + double a2 = alpha / 2.0f; + return a0 - (0.5f*cos(2.0f*FL_M_PI*(n/N))) + (a2*cos(4.0f*FL_M_PI*(n/N))); } - inline float blackmanThirdOrder(float n, float N, float a0, float a1, float a2, float a3) { - return a0 - (a1*cosf(2.0f*FL_M_PI*(n/N))) + (a2*cosf(4.0f*FL_M_PI*(n/N))) - (a3*cosf(6.0f*FL_M_PI*(n/N))); + inline double blackmanThirdOrder(double n, double N, double a0, double a1, double a2, double a3) { + return a0 - (a1*cos(2.0f*FL_M_PI*(n/N))) + (a2*cos(4.0f*FL_M_PI*(n/N))) - (a3*cos(6.0f*FL_M_PI*(n/N))); } - inline float nuttall(float n, float N) { + inline double nuttall(double n, double N) { return blackmanThirdOrder(n, N, 0.3635819f, 0.4891775f, 0.1365995f, 0.0106411f); } - inline float blackmanNuttall(float n, float N) { + inline double blackmanNuttall(double n, double N) { return blackmanThirdOrder(n, N, 0.3635819f, 0.4891775f, 0.1365995f, 0.0106411f); } - inline float blackmanHarris(float n, float N) { + inline double blackmanHarris(double n, double N) { return blackmanThirdOrder(n, N, 0.35875f, 0.48829f, 0.14128f, 0.01168f); } } diff --git a/core/src/dsp/window.h b/core/src/dsp/window.h index 491a119e..44aa67b7 100644 --- a/core/src/dsp/window.h +++ b/core/src/dsp/window.h @@ -51,38 +51,21 @@ namespace dsp { } void createTaps(float* taps, int tapCount, float factor = 1.0f) { - // // Calculate cuttoff frequency - // float omega = 2.0f * FL_M_PI * (_cutoff / _sampleRate); - // if (omega > FL_M_PI) { omega = FL_M_PI; } + // Calculate cuttoff frequency + float omega = 2.0f * FL_M_PI * (_cutoff / _sampleRate); + if (omega > FL_M_PI) { omega = FL_M_PI; } - // // Generate taps - // float val; - // float sum = 0.0f; - // for (int i = 0; i < tapCount; i++) { - // val = math::sinc(omega, i-(tapCount/2), FL_M_PI) * window_function::blackman(i, tapCount - 1); - // taps[i] = val; - // sum += val; - // } - - // // Normalize taps and multiply by supplied factor - // for (int i = 0; i < tapCount; i++) { - // taps[i] *= factor; - // taps[i] /= sum; - // } - - float fc = _cutoff / _sampleRate; - if (fc > 1.0f) { - fc = 1.0f; - } - float tc = tapCount; - float sum = 0.0f; + // Generate taps float val; + float sum = 0.0f; + float tc = tapCount; for (int i = 0; i < tapCount; i++) { - val = (sin(2.0f * FL_M_PI * fc * ((float)i - (tc / 2))) / ((float)i - (tc / 2))) * - (0.42f - (0.5f * cos(2.0f * FL_M_PI / tc)) + (0.8f * cos(4.0f * FL_M_PI / tc))); - taps[i] = val; // tapCount - i - 1 + val = math::sinc(omega, (float)i - (tc/2), FL_M_PI) * window_function::blackman(i, tc - 1); + taps[i] = val; sum += val; } + + // Normalize taps and multiply by supplied factor for (int i = 0; i < tapCount; i++) { taps[i] *= factor; taps[i] /= sum; diff --git a/core/src/gui/widgets/waterfall.cpp b/core/src/gui/widgets/waterfall.cpp index 90b0a2a0..35a0dac6 100644 --- a/core/src/gui/widgets/waterfall.cpp +++ b/core/src/gui/widgets/waterfall.cpp @@ -939,6 +939,9 @@ namespace ImGui { rectMin = ImVec2(widgetPos.x + 50 + left, widgetPos.y + 10); rectMax = ImVec2(widgetPos.x + 51 + right, widgetPos.y + fftHeight + 10); + + lbwSelMin = ImVec2(rectMin.x - 1, rectMin.y); + lbwSelMax = ImVec2(rectMin.x + 1, rectMax.y); } void WaterfallVFO::draw(ImGuiWindow* window, bool selected) { diff --git a/core/src/gui/widgets/waterfall.h b/core/src/gui/widgets/waterfall.h index 18e9238d..a0b576aa 100644 --- a/core/src/gui/widgets/waterfall.h +++ b/core/src/gui/widgets/waterfall.h @@ -42,6 +42,14 @@ namespace ImGui { ImVec2 wfRectMax; ImVec2 wfLineMin; ImVec2 wfLineMax; + ImVec2 lbwSelMin; + ImVec2 lbwSelMax; + ImVec2 rbwSelMin; + ImVec2 rbwSelMax; + ImVec2 wfLbwSelMin; + ImVec2 wfLbwSelMax; + ImVec2 wfRbwSelMin; + ImVec2 wfRbwSelMax; bool centerOffsetChanged = false; bool lowerOffsetChanged = false; diff --git a/root/res/colormaps/electric.json b/root/res/colormaps/electric.json new file mode 100644 index 00000000..d7e38b50 --- /dev/null +++ b/root/res/colormaps/electric.json @@ -0,0 +1,10 @@ +{ + "name": "Electric", + "author": "Ryzerth", + "map": [ + "#000000", + "#0000FF", + "#00FFFF", + "#FFFFFF" + ] +} \ No newline at end of file