From c13ee0732082f3020850d63b45817f1aa5cd63ff Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Tue, 3 Nov 2020 09:13:24 +0100 Subject: [PATCH] Force AM markers --- plot.c | 10 +++++++--- sa_core.c | 21 +++++++++++++++++++++ ui_sa.c | 19 +++++++++++++++---- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/plot.c b/plot.c index fab749c..7ace985 100644 --- a/plot.c +++ b/plot.c @@ -2113,12 +2113,16 @@ static void cell_draw_marker_info(int x0, int y0) setting.unit = old_unit; int depth = (int)( level * 2.0 * 80.0) + 20; #else - float level = actual_t[markers[0].index] - (actual_t[markers[1].index] + actual_t[markers[2].index])/2.0; - int depth =(int) (pow((float)10.0, 2.0 + (-level + 6.0) / 31.0)); + float delta = actual_t[markers[1].index] - actual_t[markers[2].index]; + if (delta < -5 || delta > 5) + break; + float level = (actual_t[markers[1].index] + actual_t[markers[2].index])/2.0 - actual_t[markers[0].index]; + if (level < -40 || level > 0) + break; + int depth =(int) (pow((float)10.0, 2.0 + (level + 6.02) /20.0)); #endif plot_printf(buf, sizeof buf, "DEPTH: %3d%%", depth); goto show_computed; - break; } } if (i >= 2 && setting.measurement == M_THD) { diff --git a/sa_core.c b/sa_core.c index acf0a9f..cebd9b8 100644 --- a/sa_core.c +++ b/sa_core.c @@ -2311,6 +2311,27 @@ sweep_again: // stay in sweep loop when output mo if (markers[m].enabled && markers[m].mtype & M_TRACKING) { // Available marker found markers[m].index = max_index[i]; markers[m].frequency = frequencies[markers[m].index]; +#if 0 + float v = actual_t[markers[m].index] - 10.0; // -10dB points + int index = markers[m].index; + uint32_t f = markers[m].frequency; + uint32_t s = actual_rbw_x10 * 200; // twice the selected RBW + int left = index, right = index; + while (t > 0 && actual_t[t+1] > v && markers[t].frequency > f - s) // Find left point + t--; + if (t > 0) { + left = t; + } + t = setting._sweep_points-1;; + while (t > setting._sweep_points-1 && actual_t[t+1] > v) // find right -3dB point + t++; + if (t > index) { + right = t; + markers[2].frequency = frequencies[t]; + } + +#endif + #if 1 // Hyperbolic interpolation, can be removed to save memory const int idx = markers[m].index; if (idx > 0 && idx < sweep_points-1) diff --git a/ui_sa.c b/ui_sa.c index d62fc5e..e1794c9 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -854,20 +854,31 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb) case M_LINEARITY: set_measurement(M_LINEARITY); break; - case M_AM: // OIP3 + case M_AM: // AM reset_settings(setting.mode); for (int i = 0; i< 3; i++) { markers[i].enabled = M_ENABLED; - markers[i].mtype = M_DELTA | M_TRACKING; + markers[i].mtype = M_DELTA;// | M_TRACKING; } - markers[0].mtype = M_REFERENCE | M_TRACKING; + uint32_t center, span; + markers[0].mtype = M_REFERENCE;// | M_TRACKING; kp_help_text = "Frequency of signal"; ui_mode_keypad(KM_CENTER); ui_process_keypad(); + center = uistat.value; + kp_help_text = "Modulation frequency, 2 .. 10 kHz"; + ui_mode_keypad(KM_SPAN); + ui_process_keypad(); + if (uistat.value < 2000) + break; + span = uistat.value + 1500; // Enlarge span for RBW width set_sweep_frequency(ST_SPAN, 100000); // 100kHz set_measurement(M_AM); + set_marker_frequency(0, center); + set_marker_frequency(1, center-span); + set_marker_frequency(2, center+span); break; - case M_FM: // OIP3 + case M_FM: // FM reset_settings(setting.mode); for (int i = 0; i< 3; i++) { markers[i].enabled = M_ENABLED;