add trace format of group delay

This commit is contained in:
TT 2019-09-08 18:44:33 +09:00
parent 3fc17e18f9
commit 342c5ff669
3 changed files with 36 additions and 5 deletions

2
main.c
View file

@ -1438,7 +1438,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
View file

@ -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++;
}

2
ui.c
View file

@ -1221,7 +1221,7 @@ 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
};