mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
merge: add trace format of group delay
merge: use time mode for scale for group delay
This commit is contained in:
parent
cf73221ccb
commit
f072b77dd2
6
main.c
6
main.c
|
|
@ -33,6 +33,8 @@
|
|||
#include <math.h>
|
||||
|
||||
#define ENABLED_DUMP
|
||||
//#define __SCANRAW_CMD__
|
||||
|
||||
|
||||
static void apply_error_term_at(int i);
|
||||
static void apply_edelay_at(int i);
|
||||
|
|
@ -702,8 +704,6 @@ bool sweep(bool break_on_operation)
|
|||
return true;
|
||||
}
|
||||
|
||||
//#define __SCANRAW_CMD__
|
||||
|
||||
#ifdef __SCANRAW_CMD__
|
||||
#include <stdio.h>
|
||||
|
||||
|
|
@ -1542,7 +1542,7 @@ const struct {
|
|||
} trace_info[] = {
|
||||
{ "LOGMAG", 7, 10 },
|
||||
{ "PHASE", 4, 90 },
|
||||
{ "GD", 4, 5 },
|
||||
{ "DELAY", 4, 1e-9 },
|
||||
{ "SMITH", 0, 1 },
|
||||
{ "POLAR", 0, 1 },
|
||||
{ "LINEAR", 0, 0.125 },
|
||||
|
|
|
|||
55
plot.c
55
plot.c
|
|
@ -439,44 +439,29 @@ float phase(float *v)
|
|||
return 2 * atan2f(v[1], v[0]) / M_PI * 90;
|
||||
}
|
||||
|
||||
|
||||
static inline float unwrap(float a0)
|
||||
{
|
||||
if (a0 < -M_PI)
|
||||
a0 += 2 * M_PI;
|
||||
if (a0 > M_PI)
|
||||
a0 -= 2 * M_PI;
|
||||
return a0;
|
||||
}
|
||||
|
||||
/*
|
||||
* calculate group_delay = -deltaAngle(gamma) / (deltaf * 360)
|
||||
*/
|
||||
float group_delay(float v[101][2], uint32_t* f, int count, int i)
|
||||
float group_delay(float gamma[101][2], uint32_t* freq, int count, int index)
|
||||
{
|
||||
float a0, a1, a2;
|
||||
float delay;
|
||||
// handle first and last points by accepting assymetry
|
||||
if (i == 0)
|
||||
{
|
||||
a1 = atan2f(v[i][1], v[i][0]);
|
||||
a2 = atan2f(v[i+1][1], v[i+1][0]);
|
||||
delay = -unwrap(a2 - a1) / ((f[i+1] - f[i]) * 2 * M_PI);
|
||||
}
|
||||
else if (i == count-1)
|
||||
{
|
||||
a0 = atan2f(v[i-1][1], v[i-1][0]);
|
||||
a1 = atan2f(v[i][1], v[i][0]);
|
||||
delay = -unwrap(a1 - a0) / ((f[i] - f[i-1]) * 2 * M_PI);
|
||||
}
|
||||
else
|
||||
{
|
||||
a0 = atan2f(v[i-1][1], v[i-1][0]);
|
||||
a1 = atan2f(v[i][1], v[i][0]);
|
||||
a2 = atan2f(v[i+1][1], v[i+1][0]);
|
||||
delay = -(unwrap(a1-a0)/(f[i]-f[i-1]) + unwrap(a2-a1)/(f[i+1]-f[i])) / (2 * 2 * M_PI);
|
||||
}
|
||||
return delay * 1000000000.0; // to nanosecond
|
||||
float *v, *w;
|
||||
float deltaf;
|
||||
if (index == count-1) {
|
||||
deltaf = freq[index] - freq[index-1];
|
||||
v = gamma[index-1];
|
||||
w = gamma[index];
|
||||
}
|
||||
else {
|
||||
deltaf = freq[index+1] - freq[index];
|
||||
v = gamma[index];
|
||||
w = gamma[index+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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -693,7 +678,7 @@ static void trace_get_value_string(
|
|||
break;
|
||||
case TRC_DELAY:
|
||||
v = group_delay(coeff, freq, point_count, i);
|
||||
chsnprintf(buf, len, "%.3f ns", v);
|
||||
string_value_with_prefix(buf, len, v, 's');
|
||||
break;
|
||||
case TRC_LINEAR:
|
||||
v = linear(coeff[i]);
|
||||
|
|
|
|||
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;
|
||||
|
|
@ -757,12 +757,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();
|
||||
}
|
||||
}
|
||||
|
|
@ -1236,13 +1240,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
|
||||
|
|
@ -1502,6 +1507,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;
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -1721,6 +1729,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