From 1167bdec16c81bb99a190dde8ef192fcdb485d5b Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sat, 15 Aug 2020 14:39:51 +0200 Subject: [PATCH] Hyperbolic interpolation of tracking marker frequencies (OneOfEleven) --- plot.c | 15 ++++++--------- sa_core.c | 13 +++++++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/plot.c b/plot.c index 8dbbf28..51bc308 100644 --- a/plot.c +++ b/plot.c @@ -845,13 +845,10 @@ extern const char *unit_string[]; static void trace_get_value_string( int t, char *buf, int len, int i, float coeff[POINTS_COUNT], - uint32_t freq[POINTS_COUNT], - int point_count, - int ri, int mtype) + int ri, int mtype, + uint32_t i_freq, uint32_t ref_freq) { (void) t; - (void)freq; - (void) point_count; float v; char buf2[16]; char buf3[8]; @@ -864,17 +861,17 @@ static void trace_get_value_string( *ptr2++ = S_DELTA[0]; unit_index = setting.unit+5; if (ri > i) { - dfreq = frequencies[ri] - frequencies[i]; + dfreq = ref_freq - i_freq; ii = ri - i; *ptr2++ = '-'; } else { - dfreq = frequencies[i] - frequencies[ri]; + dfreq = i_freq - ref_freq; ii = i - ri; *ptr2++ = '+'; } rlevel = value(coeff[ri]); } else { - dfreq = frequencies[i]; + dfreq = i_freq; } if (FREQ_IS_CW()) { float t = ii*(setting.actual_sweep_time_us)/(sweep_points - 1); @@ -2112,7 +2109,7 @@ static void cell_draw_marker_info(int x0, int y0) // cell_drawstring_7x13(buf, xpos, ypos); trace_get_value_string( t, &buf[k], (sizeof buf) - k, - idx, measured[trace[t].channel], frequencies, sweep_points, ridx, markers[i].mtype); + idx, measured[trace[t].channel], ridx, markers[i].mtype,markers[i].frequency, markers[ref_marker].frequency); if (/* strlen(buf)*7> WIDTH/2 && */active > 1) cell_drawstring(buf, xpos, ypos); else diff --git a/sa_core.c b/sa_core.c index 3e512e3..442f3ca 100644 --- a/sa_core.c +++ b/sa_core.c @@ -2073,6 +2073,19 @@ 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 1 // Hyperbolic interpolation, can be removed to save memory + const int idx = markers[m].index; + if (idx > 0 && idx < sweep_points-1) + { + const float y1 = actual_t[idx - 1]; + const float y2 = actual_t[idx + 0]; + const float y3 = actual_t[idx + 1]; + const float d = 0.5f * (y1 - y3) / ((y1 - (2 * y2) + y3) + 1e-12f); + //const float bin = (float)idx + d; + const int32_t delta_Hz = abs((int64_t)frequencies[idx + 0] - frequencies[idx + 1]); + markers[m].frequency += (int32_t)(delta_Hz * d); + } +#endif m++; break; // Next maximum }