Skip to content

Commit 168e28c

Browse files
added SNR meter smoothing
1 parent 8d05c1e commit 168e28c

File tree

4 files changed

+61
-16
lines changed

4 files changed

+61
-16
lines changed

core/src/core.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ int sdrpp_main(int argc, char* argv[]) {
119119
defConfig["fftHoldSpeed"] = 60;
120120
defConfig["fftSmoothing"] = false;
121121
defConfig["fftSmoothingSpeed"] = 100;
122+
defConfig["snrSmoothing"] = false;
123+
defConfig["snrSmoothingSpeed"] = 20;
122124
defConfig["fastFFT"] = false;
123125
defConfig["fftHeight"] = 300;
124126
defConfig["fftRate"] = 20;

core/src/gui/menus/display.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ namespace displaymenu {
2525
int fftHoldSpeed = 60;
2626
bool fftSmoothing = false;
2727
int fftSmoothingSpeed = 100;
28+
bool snrSmoothing = false;
29+
int snrSmoothingSpeed = 20;
2830

2931
OptionList<float, float> uiScales;
3032

@@ -63,6 +65,7 @@ namespace displaymenu {
6365
void updateFFTSpeeds() {
6466
gui::waterfall.setFFTHoldSpeed((float)fftHoldSpeed / ((float)fftRate * 10.0f));
6567
gui::waterfall.setFFTSmoothingSpeed(std::min<float>((float)fftSmoothingSpeed / (float)(fftRate * 10.0f), 1.0f));
68+
gui::waterfall.setSNRSmoothingSpeed(std::min<float>((float)snrSmoothingSpeed / (float)(fftRate * 10.0f), 1.0f));
6669
}
6770

6871
void init() {
@@ -111,6 +114,9 @@ namespace displaymenu {
111114
fftSmoothing = core::configManager.conf["fftSmoothing"];
112115
fftSmoothingSpeed = core::configManager.conf["fftSmoothingSpeed"];
113116
gui::waterfall.setFFTSmoothing(fftSmoothing);
117+
snrSmoothing = core::configManager.conf["snrSmoothing"];
118+
snrSmoothingSpeed = core::configManager.conf["snrSmoothingSpeed"];
119+
gui::waterfall.setSNRSmoothing(snrSmoothing);
114120
updateFFTSpeeds();
115121

116122
// Define and load UI scales
@@ -151,30 +157,44 @@ namespace displaymenu {
151157
core::configManager.conf["fftHold"] = fftHold;
152158
core::configManager.release(true);
153159
}
160+
ImGui::SameLine();
161+
ImGui::FillWidth();
162+
if (ImGui::InputInt("##sdrpp_fft_hold_speed", &fftHoldSpeed)) {
163+
updateFFTSpeeds();
164+
core::configManager.acquire();
165+
core::configManager.conf["fftHoldSpeed"] = fftHoldSpeed;
166+
core::configManager.release(true);
167+
}
154168

155169
if (ImGui::Checkbox("FFT Smoothing##_sdrpp", &fftSmoothing)) {
156170
gui::waterfall.setFFTSmoothing(fftSmoothing);
157171
core::configManager.acquire();
158172
core::configManager.conf["fftSmoothing"] = fftSmoothing;
159173
core::configManager.release(true);
160174
}
161-
162-
ImGui::LeftLabel("FFT Hold Speed");
175+
ImGui::SameLine();
163176
ImGui::FillWidth();
164-
if (ImGui::InputInt("##sdrpp_fft_hold_speed", &fftHoldSpeed)) {
177+
if (ImGui::InputInt("##sdrpp_fft_smoothing_speed", &fftSmoothingSpeed)) {
178+
fftSmoothingSpeed = std::max<int>(fftSmoothingSpeed, 1);
165179
updateFFTSpeeds();
166180
core::configManager.acquire();
167-
core::configManager.conf["fftHoldSpeed"] = fftHoldSpeed;
181+
core::configManager.conf["fftSmoothingSpeed"] = fftSmoothingSpeed;
168182
core::configManager.release(true);
169183
}
170184

171-
ImGui::LeftLabel("FFT Smoothing Speed");
185+
if (ImGui::Checkbox("SNR Smoothing##_sdrpp", &snrSmoothing)) {
186+
gui::waterfall.setSNRSmoothing(snrSmoothing);
187+
core::configManager.acquire();
188+
core::configManager.conf["snrSmoothing"] = snrSmoothing;
189+
core::configManager.release(true);
190+
}
191+
ImGui::SameLine();
172192
ImGui::FillWidth();
173-
if (ImGui::InputInt("##sdrpp_fft_smoothing_speed", &fftSmoothingSpeed)) {
174-
fftSmoothingSpeed = std::max<int>(fftSmoothingSpeed, 1);
193+
if (ImGui::InputInt("##sdrpp_snr_smoothing_speed", &snrSmoothingSpeed)) {
194+
snrSmoothingSpeed = std::max<int>(snrSmoothingSpeed, 1);
175195
updateFFTSpeeds();
176196
core::configManager.acquire();
177-
core::configManager.conf["fftSmoothingSpeed"] = fftSmoothingSpeed;
197+
core::configManager.conf["snrSmoothingSpeed"] = snrSmoothingSpeed;
178198
core::configManager.release(true);
179199
}
180200

core/src/gui/widgets/waterfall.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -886,15 +886,22 @@ namespace ImGui {
886886
// Apply smoothing if enabled
887887
if (fftSmoothing && latestFFT != NULL && smoothingBuf != NULL && fftLines != 0) {
888888
std::lock_guard<std::mutex> lck2(smoothingBufMtx);
889-
volk_32f_s32f_multiply_32f(latestFFT, latestFFT, smoothingAlpha, dataWidth);
890-
volk_32f_s32f_multiply_32f(smoothingBuf, smoothingBuf, smoothingBeta, dataWidth);
889+
volk_32f_s32f_multiply_32f(latestFFT, latestFFT, fftSmoothingAlpha, dataWidth);
890+
volk_32f_s32f_multiply_32f(smoothingBuf, smoothingBuf, fftSmoothingBeta, dataWidth);
891891
volk_32f_x2_add_32f(smoothingBuf, latestFFT, smoothingBuf, dataWidth);
892892
memcpy(latestFFT, smoothingBuf, dataWidth * sizeof(float));
893893
}
894894

895895
if (selectedVFO != "" && vfos.size() > 0) {
896896
float dummy;
897-
calculateVFOSignalInfo(waterfallVisible ? &rawFFTs[currentFFTLine * rawFFTSize] : rawFFTs, vfos[selectedVFO], dummy, selectedVFOSNR);
897+
if (snrSmoothing) {
898+
float newSNR = 0.0f;
899+
calculateVFOSignalInfo(waterfallVisible ? &rawFFTs[currentFFTLine * rawFFTSize] : rawFFTs, vfos[selectedVFO], dummy, newSNR);
900+
selectedVFOSNR = (snrSmoothingBeta*selectedVFOSNR) + (snrSmoothingAlpha*newSNR);
901+
}
902+
else {
903+
calculateVFOSignalInfo(waterfallVisible ? &rawFFTs[currentFFTLine * rawFFTSize] : rawFFTs, vfos[selectedVFO], dummy, selectedVFOSNR);
904+
}
898905
}
899906

900907
// If FFT hold is enabled, update it
@@ -1155,8 +1162,17 @@ namespace ImGui {
11551162

11561163
void WaterFall::setFFTSmoothingSpeed(float speed) {
11571164
std::lock_guard<std::mutex> lck(smoothingBufMtx);
1158-
smoothingAlpha = speed;
1159-
smoothingBeta = 1.0f - speed;
1165+
fftSmoothingAlpha = speed;
1166+
fftSmoothingBeta = 1.0f - speed;
1167+
}
1168+
1169+
void WaterFall::setSNRSmoothing(bool enabled) {
1170+
snrSmoothing = enabled;
1171+
}
1172+
1173+
void WaterFall::setSNRSmoothingSpeed(float speed) {
1174+
snrSmoothingAlpha = speed;
1175+
snrSmoothingBeta = 1.0f - speed;
11601176
}
11611177

11621178
float* WaterFall::acquireLatestFFT(int& width) {

core/src/gui/widgets/waterfall.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ namespace ImGui {
172172
void setFFTSmoothing(bool enabled);
173173
void setFFTSmoothingSpeed(float speed);
174174

175+
void setSNRSmoothing(bool enabled);
176+
void setSNRSmoothingSpeed(float speed);
177+
175178
float* acquireLatestFFT(int& width);
176179
void releaseLatestFFT();
177180

@@ -185,7 +188,7 @@ namespace ImGui {
185188
bool mouseInFFT = false;
186189
bool mouseInWaterfall = false;
187190

188-
float selectedVFOSNR = NAN;
191+
float selectedVFOSNR = 0.0f;
189192

190193
bool centerFrequencyLocked = false;
191194

@@ -331,8 +334,12 @@ namespace ImGui {
331334
float fftHoldSpeed = 0.3f;
332335

333336
bool fftSmoothing = false;
334-
float smoothingAlpha = 0.5;
335-
float smoothingBeta = 0.5;
337+
float fftSmoothingAlpha = 0.5;
338+
float fftSmoothingBeta = 0.5;
339+
340+
bool snrSmoothing = false;
341+
float snrSmoothingAlpha = 0.5;
342+
float snrSmoothingBeta = 0.5;
336343

337344
// UI Select elements
338345
bool fftResizeSelect = false;

0 commit comments

Comments
 (0)