From 99809c791900cf30442cfb2766ccfc6ed67a5c13 Mon Sep 17 00:00:00 2001 From: Kyle Reed <3761006+kallanreed@users.noreply.github.com> Date: Thu, 29 Jun 2023 22:35:35 -0700 Subject: [PATCH] Consolidate anti_alias BW selection into function (#1217) --- firmware/application/apps/capture_app.cpp | 37 ++--------------------- firmware/application/apps/capture_app.hpp | 1 - firmware/application/apps/ui_level.cpp | 29 +----------------- firmware/application/apps/ui_recon.cpp | 29 +----------------- firmware/application/ui/ui_spectrum.cpp | 31 +++++++++++++++++++ firmware/application/ui/ui_spectrum.hpp | 4 +++ 6 files changed, 39 insertions(+), 92 deletions(-) diff --git a/firmware/application/apps/capture_app.cpp b/firmware/application/apps/capture_app.cpp index fd75974b2..d93c299fd 100644 --- a/firmware/application/apps/capture_app.cpp +++ b/firmware/application/apps/capture_app.cpp @@ -60,41 +60,8 @@ CaptureAppView::CaptureAppView(NavigationView& nav) /* ex. recording 500kHz BW to .C16 file, base_rate clock 500kHz x2(I,Q) x 2 bytes (int signed) =2MB/sec rate SD Card */ waterfall.on_hide(); - /* Set up proper anti aliasing BPF bandwith in MAX2837 before ADC sampling according to the new added BW Options . */ - switch (sampling_rate) { // we use the var fs (sampling_rate) , to set up BPF aprox < fs_max/2 by Nyquist theorem. - - case 0 ... 2000000: // BW Captured range (0 <= 250kHz max ) fs = 8 x 250 kHz - anti_alias_baseband_bandwidth_filter = 1750000; // Minimum BPF MAX2837 for all those lower BW options. - break; - - case 4000000 ... 6000000: // BW capture range (500k ... 750kHz max ) fs_max = 8 x 750kHz = 6Mhz - // BW 500k ... 750kHz , ex. 500kHz (fs = 8*BW = 4Mhz) , BW 600kHz (fs = 4,8Mhz) , BW 750 kHz (fs = 6Mhz) - anti_alias_baseband_bandwidth_filter = 2500000; // in some IC MAX2837 appear 2250000 , but both works similar. - break; - - case 8800000: // BW capture 1,1Mhz fs = 8 x 1,1Mhz = 8,8Mhz . (1Mhz showed slightly higher noise background). - anti_alias_baseband_bandwidth_filter = 3500000; - break; - - case 14000000: // BW capture 1,75Mhz , fs = 8 x 1,75Mhz = 14Mhz - // good BPF, good matching, but LCD making flicker , refresh rate should be < 20 Hz , but reasonable picture - anti_alias_baseband_bandwidth_filter = 5000000; - break; - - case 16000000: // BW capture 2Mhz , fs = 8 x 2Mhz = 16Mhz - // good BPF, good matching, but LCD making flicker , refresh rate should be < 20 Hz , but reasonable picture - anti_alias_baseband_bandwidth_filter = 6000000; - break; - - case 20000000: // BW capture 2,5Mhz , fs= 8 x 2,5 Mhz = 20Mhz - // good BPF, good matching, but LCD making flicker , refresh rate should be < 20 Hz , but reasonable picture - anti_alias_baseband_bandwidth_filter = 7000000; - break; - - default: // BW capture 2,75Mhz, fs = 8 x 2,75Mhz= 22Mhz max ADC sampling) and others. - // We tested also 9Mhz FPB stightly too much noise floor, better 8Mhz - anti_alias_baseband_bandwidth_filter = 8000000; - } + /* Set up proper anti aliasing BPF bandwith in MAX2837 before ADC sampling according to the new added BW Options. */ + auto anti_alias_baseband_bandwidth_filter = filter_bandwidth_for_sampling_rate(sampling_rate); record_view.set_sampling_rate(sampling_rate); receiver_model.set_sampling_rate(sampling_rate); diff --git a/firmware/application/apps/capture_app.hpp b/firmware/application/apps/capture_app.hpp index 0680274f0..62e973e45 100644 --- a/firmware/application/apps/capture_app.hpp +++ b/firmware/application/apps/capture_app.hpp @@ -56,7 +56,6 @@ class CaptureAppView : public View { app_settings::Options::UseGlobalTargetFrequency}; uint32_t sampling_rate = 0; - uint32_t anti_alias_baseband_bandwidth_filter = 2500000; Labels labels{ {{0 * 8, 1 * 16}, "Rate:", Color::light_grey()}, diff --git a/firmware/application/apps/ui_level.cpp b/firmware/application/apps/ui_level.cpp index 5a85e5863..50df2884b 100644 --- a/firmware/application/apps/ui_level.cpp +++ b/firmware/application/apps/ui_level.cpp @@ -205,34 +205,7 @@ size_t LevelView::change_mode(freqman_index_t new_mod) { receiver_model.set_modulation(ReceiverModel::Mode::Capture); field_bw.set_by_value(0); field_bw.on_change = [this](size_t, OptionsField::value_t sampling_rate) { - uint32_t anti_alias_baseband_bandwidth_filter = 2500000; - switch (sampling_rate) { // we use the var fs (sampling_rate) , to set up BPF aprox < fs_max/2 by Nyquist theorem. - case 0 ... 2000000: // BW Captured range (0 <= 250kHz max ) fs = 8 x 250 kHz - anti_alias_baseband_bandwidth_filter = 1750000; // Minimum BPF MAX2837 for all those lower BW options. - break; - case 4000000 ... 6000000: // BW capture range (500k ... 750kHz max ) fs_max = 8 x 750kHz = 6Mhz - // BW 500k ... 750kHz , ex. 500kHz (fs = 8*BW = 4Mhz) , BW 600kHz (fs = 4,8Mhz) , BW 750 kHz (fs = 6Mhz) - anti_alias_baseband_bandwidth_filter = 2500000; // in some IC MAX2837 appear 2250000 , but both works similar. - break; - case 8800000: // BW capture 1,1Mhz fs = 8 x 1,1Mhz = 8,8Mhz . (1Mhz showed slightly higher noise background). - anti_alias_baseband_bandwidth_filter = 3500000; - break; - case 14000000: // BW capture 1,75Mhz , fs = 8 x 1,75Mhz = 14Mhz - // good BPF, good matching, but LCD making flicker , refresh rate should be < 20 Hz , but reasonable picture - anti_alias_baseband_bandwidth_filter = 5000000; - break; - case 16000000: // BW capture 2Mhz , fs = 8 x 2Mhz = 16Mhz - // good BPF, good matching, but LCD making flicker , refresh rate should be < 20 Hz , but reasonable picture - anti_alias_baseband_bandwidth_filter = 6000000; - break; - case 20000000: // BW capture 2,5Mhz , fs= 8 x 2,5 Mhz = 20Mhz - // good BPF, good matching, but LCD making flicker , refresh rate should be < 20 Hz , but reasonable picture - anti_alias_baseband_bandwidth_filter = 7000000; - break; - default: // BW capture 2,75Mhz, fs = 8 x 2,75Mhz= 22Mhz max ADC sampling) and others. - // We tested also 9Mhz FPB stightly too much noise floor, better 8Mhz - anti_alias_baseband_bandwidth_filter = 8000000; - } + auto anti_alias_baseband_bandwidth_filter = filter_bandwidth_for_sampling_rate(sampling_rate); receiver_model.set_sampling_rate(sampling_rate); receiver_model.set_baseband_bandwidth(anti_alias_baseband_bandwidth_filter); }; diff --git a/firmware/application/apps/ui_recon.cpp b/firmware/application/apps/ui_recon.cpp index 134bffeef..6b509db34 100644 --- a/firmware/application/apps/ui_recon.cpp +++ b/firmware/application/apps/ui_recon.cpp @@ -1399,34 +1399,7 @@ size_t ReconView::change_mode(freqman_index_t new_mod) { receiver_model.set_modulation(ReceiverModel::Mode::Capture); field_bw.set_by_value(0); field_bw.on_change = [this](size_t, OptionsField::value_t sampling_rate) { - uint32_t anti_alias_baseband_bandwidth_filter = 2500000; - switch (sampling_rate) { // we use the var fs (sampling_rate) , to set up BPF aprox < fs_max/2 by Nyquist theorem. - case 0 ... 2000000: // BW Captured range (0 <= 250kHz max ) fs = 8 x 250 kHz - anti_alias_baseband_bandwidth_filter = 1750000; // Minimum BPF MAX2837 for all those lower BW options. - break; - case 4000000 ... 6000000: // BW capture range (500k ... 750kHz max ) fs_max = 8 x 750kHz = 6Mhz - // BW 500k ... 750kHz , ex. 500kHz (fs = 8*BW = 4Mhz) , BW 600kHz (fs = 4,8Mhz) , BW 750 kHz (fs = 6Mhz) - anti_alias_baseband_bandwidth_filter = 2500000; // in some IC MAX2837 appear 2250000 , but both works similar. - break; - case 8800000: // BW capture 1,1Mhz fs = 8 x 1,1Mhz = 8,8Mhz . (1Mhz showed slightly higher noise background). - anti_alias_baseband_bandwidth_filter = 3500000; - break; - case 14000000: // BW capture 1,75Mhz , fs = 8 x 1,75Mhz = 14Mhz - // good BPF, good matching, but LCD making flicker , refresh rate should be < 20 Hz , but reasonable picture - anti_alias_baseband_bandwidth_filter = 5000000; - break; - case 16000000: // BW capture 2Mhz , fs = 8 x 2Mhz = 16Mhz - // good BPF, good matching, but LCD making flicker , refresh rate should be < 20 Hz , but reasonable picture - anti_alias_baseband_bandwidth_filter = 6000000; - break; - case 20000000: // BW capture 2,5Mhz , fs= 8 x 2,5 Mhz = 20Mhz - // good BPF, good matching, but LCD making flicker , refresh rate should be < 20 Hz , but reasonable picture - anti_alias_baseband_bandwidth_filter = 7000000; - break; - default: // BW capture 2,75Mhz, fs = 8 x 2,75Mhz= 22Mhz max ADC sampling) and others. - // We tested also 9Mhz FPB stightly too much noise floor, better 8Mhz - anti_alias_baseband_bandwidth_filter = 8000000; - } + auto anti_alias_baseband_bandwidth_filter = filter_bandwidth_for_sampling_rate(sampling_rate); record_view->set_sampling_rate(sampling_rate); receiver_model.set_sampling_rate(sampling_rate); receiver_model.set_baseband_bandwidth(anti_alias_baseband_bandwidth_filter); diff --git a/firmware/application/ui/ui_spectrum.cpp b/firmware/application/ui/ui_spectrum.cpp index e94cbe5a9..2242d5eac 100644 --- a/firmware/application/ui/ui_spectrum.cpp +++ b/firmware/application/ui/ui_spectrum.cpp @@ -367,4 +367,35 @@ void WaterfallView::on_audio_spectrum() { } } /* namespace spectrum */ + +uint32_t filter_bandwidth_for_sampling_rate(int32_t sampling_rate) { + switch (sampling_rate) { // Use the var fs (sampling_rate) to set up BPF aprox < fs_max / 2 by Nyquist theorem. + case 0 ... 2000000: // BW Captured range (0 <= 250kHz max) fs = 8 x 250 kHz. + return 1750000; // Minimum BPF MAX2837 for all those lower BW options. + + case 4000000 ... 6000000: // BW capture range (500k...750kHz max) fs_max = 8 x 750kHz = 6Mhz + // BW 500k...750kHz, ex. 500kHz (fs = 8 x BW = 4Mhz), BW 600kHz (fs = 4,8Mhz), BW 750 kHz (fs = 6Mhz). + return 2500000; // In some IC, MAX2837 appears as 2250000, but both work similarly. + + case 8800000: // BW capture 1,1Mhz fs = 8 x 1,1Mhz = 8,8Mhz. (1Mhz showed slightly higher noise background). + return 3500000; + + case 14000000: // BW capture 1,75Mhz, fs = 8 x 1,75Mhz = 14Mhz + // Good BPF, good matching, but LCD flickers, refresh rate should be < 20 Hz, reasonable picture. + return 5000000; + + case 16000000: // BW capture 2Mhz, fs = 8 x 2Mhz = 16Mhz + // Good BPF, good matching, but LCD flickers, refresh rate should be < 20 Hz, reasonable picture. + return 6000000; + + case 20000000: // BW capture 2,5Mhz, fs = 8 x 2,5 Mhz = 20Mhz + // Good BPF, good matching, but LCD flickers, refresh rate should be < 20 Hz, reasonable picture. + return 7000000; + + default: // BW capture 2,75Mhz, fs = 8 x 2,75Mhz = 22Mhz max ADC sampling and others. + // We tested also 9Mhz FPB slightly too much noise floor, better at 8Mhz. + return 8000000; + } +} + } /* namespace ui */ diff --git a/firmware/application/ui/ui_spectrum.hpp b/firmware/application/ui/ui_spectrum.hpp index 58dc46b27..d46427181 100644 --- a/firmware/application/ui/ui_spectrum.hpp +++ b/firmware/application/ui/ui_spectrum.hpp @@ -192,6 +192,10 @@ class WaterfallView : public View { }; } /* namespace spectrum */ + +/* Calculates the best anti_alias_baseband_bandwidth_filter for the given sampling rate. */ +uint32_t filter_bandwidth_for_sampling_rate(int32_t sampling_rate); + } /* namespace ui */ #endif /*__UI_SPECTRUM_H__*/