mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
Merge branch 'format_delay'
This commit is contained in:
commit
5651d1e447
2
main.c
2
main.c
|
|
@ -1442,7 +1442,7 @@ const struct {
|
|||
} trace_info[] = {
|
||||
{ "LOGMAG", 7, 10 },
|
||||
{ "PHASE", 4, 90 },
|
||||
{ "DELAY", 4, 1 },
|
||||
{ "DELAY", 4, 1e-9 },
|
||||
{ "SMITH", 0, 1 },
|
||||
{ "POLAR", 0, 1 },
|
||||
{ "LINEAR", 0, 0.125 },
|
||||
|
|
|
|||
37
plot.c
37
plot.c
|
|
@ -439,6 +439,24 @@ float phase(float *v)
|
|||
return 2 * atan2f(v[1], v[0]) / M_PI * 90;
|
||||
}
|
||||
|
||||
/*
|
||||
* calculate groupdelay
|
||||
*/
|
||||
float groupdelay(float *v, float deltaf)
|
||||
{
|
||||
float *w = &v[2]; // point to next coeff
|
||||
#if 1
|
||||
// w = w[0]/w[1]
|
||||
// v = v[0]/v[1]
|
||||
// atan(w)-atan(v) = atan((w-v)/(1+wv))
|
||||
float r = w[0]*v[1] - w[1]*v[0];
|
||||
float i = w[0]*v[0] + w[1]*v[1];
|
||||
return atan2f(r, i) / (2 * M_PI * deltaf);
|
||||
#else
|
||||
return (atan2f(w[0], w[1]) - atan2f(v[0], v[1])) / (2 * M_PI * deltaf);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* calculate abs(gamma)
|
||||
*/
|
||||
|
|
@ -502,6 +520,12 @@ trace_into_index(int x, int t, int i, float coeff[2])
|
|||
case TRC_PHASE:
|
||||
v = refpos - phase(coeff) * scale;
|
||||
break;
|
||||
case TRC_DELAY:
|
||||
if (i != 100) {
|
||||
float deltaf = frequencies[i+1] - frequencies[i];
|
||||
v = refpos - groupdelay(coeff, deltaf) * scale;
|
||||
}
|
||||
break;
|
||||
case TRC_LINEAR:
|
||||
v = refpos + linear(coeff) * scale;
|
||||
break;
|
||||
|
|
@ -631,7 +655,7 @@ gamma2reactance(char *buf, int len, const float coeff[2])
|
|||
}
|
||||
|
||||
static void
|
||||
trace_get_value_string(int t, char *buf, int len, float coeff[2], uint32_t frequency)
|
||||
trace_get_value_string(int t, char *buf, int len, float coeff[2], int i)
|
||||
{
|
||||
float v;
|
||||
switch (trace[t].type) {
|
||||
|
|
@ -646,6 +670,13 @@ trace_get_value_string(int t, char *buf, int len, float coeff[2], uint32_t frequ
|
|||
v = phase(coeff);
|
||||
chsnprintf(buf, len, "%.2f" S_DEGREE, v);
|
||||
break;
|
||||
case TRC_DELAY:
|
||||
{
|
||||
float deltaf = frequencies[i+1] - frequencies[i];
|
||||
v = groupdelay(coeff, deltaf);
|
||||
string_value_with_prefix(buf, len, v, 's');
|
||||
}
|
||||
break;
|
||||
case TRC_LINEAR:
|
||||
v = linear(coeff);
|
||||
chsnprintf(buf, len, "%.2f", v);
|
||||
|
|
@ -655,7 +686,7 @@ trace_get_value_string(int t, char *buf, int len, float coeff[2], uint32_t frequ
|
|||
chsnprintf(buf, len, "%.2f", v);
|
||||
break;
|
||||
case TRC_SMITH:
|
||||
gamma2imp(buf, len, coeff, frequency);
|
||||
gamma2imp(buf, len, coeff, frequencies[i]);
|
||||
break;
|
||||
case TRC_REAL:
|
||||
chsnprintf(buf, len, "%.2f", coeff[0]);
|
||||
|
|
@ -1379,7 +1410,7 @@ cell_draw_marker_info(int m, int n, int w, int h)
|
|||
trace_get_info(t, buf, sizeof buf);
|
||||
cell_drawstring_5x7(w, h, buf, xpos, ypos, config.trace_color[t]);
|
||||
xpos += 64;
|
||||
trace_get_value_string(t, buf, sizeof buf, measured[trace[t].channel][idx], frequencies[idx]);
|
||||
trace_get_value_string(t, buf, sizeof buf, measured[trace[t].channel][idx], idx);
|
||||
cell_drawstring_5x7(w, h, buf, xpos, ypos, config.trace_color[t]);
|
||||
j++;
|
||||
}
|
||||
|
|
|
|||
23
ui.c
23
ui.c
|
|
@ -68,7 +68,7 @@ enum {
|
|||
};
|
||||
|
||||
enum {
|
||||
KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_SCALE, KM_REFPOS, KM_EDELAY, KM_VELOCITY_FACTOR
|
||||
KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_SCALE, KM_REFPOS, KM_EDELAY, KM_VELOCITY_FACTOR, KM_SCALEDELAY
|
||||
};
|
||||
|
||||
uint8_t ui_mode = UI_NORMAL;
|
||||
|
|
@ -742,12 +742,16 @@ static void
|
|||
menu_scale_cb(int item)
|
||||
{
|
||||
int status;
|
||||
int km = KM_SCALE + item;
|
||||
if (km == KM_SCALE && trace[uistat.current_trace].type == TRC_DELAY) {
|
||||
km = KM_SCALEDELAY;
|
||||
}
|
||||
status = btn_wait_release();
|
||||
if (status & EVT_BUTTON_DOWN_LONG) {
|
||||
ui_mode_numeric(KM_SCALE + item);
|
||||
ui_mode_numeric(km);
|
||||
ui_process_numeric();
|
||||
} else {
|
||||
ui_mode_keypad(KM_SCALE + item);
|
||||
ui_mode_keypad(km);
|
||||
ui_process_keypad();
|
||||
}
|
||||
}
|
||||
|
|
@ -1221,13 +1225,14 @@ const keypads_t * const keypads_mode_tbl[] = {
|
|||
keypads_freq, // span
|
||||
keypads_freq, // cw freq
|
||||
keypads_scale, // scale
|
||||
keypads_scale, // respos
|
||||
keypads_scale, // refpos
|
||||
keypads_time, // electrical delay
|
||||
keypads_scale // velocity factor
|
||||
keypads_scale, // velocity factor
|
||||
keypads_time // scale of delay
|
||||
};
|
||||
|
||||
const char * const keypad_mode_label[] = {
|
||||
"START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE", "REFPOS", "EDELAY", "VELOCITY%"
|
||||
"START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE", "REFPOS", "EDELAY", "VELOCITY%", "DELAY"
|
||||
};
|
||||
|
||||
void
|
||||
|
|
@ -1487,6 +1492,9 @@ fetch_numeric_target(void)
|
|||
case KM_VELOCITY_FACTOR:
|
||||
uistat.value = velocity_factor;
|
||||
break;
|
||||
case KM_SCALEDELAY:
|
||||
uistat.value = get_trace_scale(uistat.current_trace) * 1e12;
|
||||
break;
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -1706,6 +1714,9 @@ keypad_click(int key)
|
|||
case KM_VELOCITY_FACTOR:
|
||||
velocity_factor = value;
|
||||
break;
|
||||
case KM_SCALEDELAY:
|
||||
set_trace_scale(uistat.current_trace, value * 1e-12); // pico second
|
||||
break;
|
||||
}
|
||||
|
||||
return KP_DONE;
|
||||
|
|
|
|||
Loading…
Reference in a new issue