Calculate AM modulation depth and improved pass band calculation

master
erikkaashoek 5 years ago
parent 041709b4e4
commit ba506d5173

@ -519,6 +519,13 @@ draw_on_strut(int v0, int d, int color)
* calculate log10f(abs(gamma)) * calculate log10f(abs(gamma))
*/ */
float
index_to_value(const int i)
{
return(value(actual_t[i]));
}
float float
value(const float v) value(const float v)
{ {
@ -2084,31 +2091,47 @@ static void cell_draw_marker_info(int x0, int y0)
if (setting.measurement == M_THD && active >= 1) if (setting.measurement == M_THD && active >= 1)
active = 2; active = 2;
for (int i = 0; i < MARKER_COUNT; i++) { for (int i = 0; i < MARKER_COUNT; i++) {
if (i == 3 && setting.measurement == M_PASS_BAND) { if (i == 3) {
if (setting.measurement == M_PASS_BAND) {
uint32_t f; uint32_t f;
if (markers[2].frequency>markers[1].frequency) if (markers[2].frequency>markers[1].frequency)
f = markers[2].frequency-markers[1].frequency; f = markers[2].frequency-markers[1].frequency;
else else
f = markers[1].frequency-markers[2].frequency; f = markers[1].frequency-markers[2].frequency;
plot_printf(buf, sizeof buf, "WIDTH: %8.3qHz", f); plot_printf(buf, sizeof buf, "WIDTH: %8.3qHz", f);
show_computed:
j = 3; j = 3;
int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0; int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0;
int ypos = 1 + (j/2)*(16) - y0; int ypos = 1 + (j/2)*(16) - y0;
cell_drawstring_7x13(buf, xpos, ypos); cell_drawstring_7x13(buf, xpos, ypos);
// cell_drawstring(buf, xpos, ypos); // cell_drawstring(buf, xpos, ypos);
} else if (setting.measurement == M_AM){
#ifdef AM_IN_VOLT
int old_unit = setting.unit;
setting.unit = U_VOLT;
float level = (index_to_value(markers[1].index) + index_to_value(markers[2].index))/2 / index_to_value(markers[0].index);
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)( (15.0 - level) / 9.0 * 50) + 50;
#endif
plot_printf(buf, sizeof buf, "DEPTH: %3d%%", depth);
goto show_computed;
break; break;
} else }
}
if (i >= 2 && setting.measurement == M_THD) { if (i >= 2 && setting.measurement == M_THD) {
if (i == 2 && (markers[0].index << 5) > sweep_points ) { if (i == 2 && (markers[0].index << 5) > sweep_points ) {
int old_unit = setting.unit; int old_unit = setting.unit;
setting.unit = U_WATT; setting.unit = U_WATT;
float p = value((actual_t[markers[0].index])); float p = index_to_value(markers[0].index);
int j = 2; int j = 2;
uint32_t f = markers[0].frequency; uint32_t f = markers[0].frequency;
float h = 0.0; float h = 0.0;
while (f * j < frequencies[sweep_points-1]) { while (f * j < frequencies[sweep_points-1]) {
if (search_maximum(1, f*j, 4*j) ) // use marker 1 for searching harmonics if (search_maximum(1, f*j, 4*j) ) // use marker 1 for searching harmonics
h += value((actual_t[markers[1].index])); h += index_to_value(markers[1].index);
j++; j++;
} }
float thd = 100.0 * sqrt(h/p); float thd = 100.0 * sqrt(h/p);
@ -2125,10 +2148,10 @@ static void cell_draw_marker_info(int x0, int y0)
break; break;
} else } else
if (i >= 2 && setting.measurement == M_OIP3 && markers[2].enabled && markers[3].enabled) { if (i >= 2 && setting.measurement == M_OIP3 && markers[2].enabled && markers[3].enabled) {
float il = value((actual_t[markers[2].index])); float il = index_to_value(markers[2].index);
float ir = value((actual_t[markers[3].index])); float ir = index_to_value(markers[3].index);
float sl = value((actual_t[markers[0].index])); float sl = index_to_value(markers[0].index);
float sr = value((actual_t[markers[1].index])); float sr = index_to_value(markers[1].index);
float ip = sl+ (sr - il)/2; float ip = sl+ (sr - il)/2;
plot_printf(buf, sizeof buf, "OIP3: %4.1fdB", ip); plot_printf(buf, sizeof buf, "OIP3: %4.1fdB", ip);

@ -2374,18 +2374,18 @@ sweep_again: // stay in sweep loop when output mo
if (markers[2].index < 0) markers[1].index = setting._sweep_points - 1; if (markers[2].index < 0) markers[1].index = setting._sweep_points - 1;
markers[2].frequency = frequencies[markers[2].index]; markers[2].frequency = frequencies[markers[2].index];
} else if (setting.measurement == M_PASS_BAND && markers[0].index > 10) { // ----------------Pass band measurement } else if (setting.measurement == M_PASS_BAND && markers[0].index > 10) { // ----------------Pass band measurement
int t = markers[0].index; int t = 0;
float v = actual_t[t]; float v = actual_t[markers[0].index] - 3.0;
while (t > 0 && actual_t[t] > v - 4.0) // Find left -3dB point while (t < markers[0].index && actual_t[t+1] < v) // Find left -3dB point
t --; t++;
if (t > 0) { if (t< markers[0].index) {
markers[1].index = t; markers[1].index = t;
markers[1].frequency = frequencies[t]; markers[1].frequency = frequencies[t];
} }
t = markers[0].index; t = setting._sweep_points-1;;
while (t < setting._sweep_points - 1 && actual_t[t] > v - 4.0) // find right -3dB point while (t > markers[0].index && actual_t[t-1] < v) // find right -3dB point
t ++; t--;
if (t < setting._sweep_points - 1 ) { if (t > markers[0].index) {
markers[2].index = t; markers[2].index = t;
markers[2].frequency = frequencies[t]; markers[2].frequency = frequencies[t];
} }
@ -3584,7 +3584,9 @@ void self_test(int test)
reset_settings(M_LOW); reset_settings(M_LOW);
setting.step_delay_mode = SD_NORMAL; setting.step_delay_mode = SD_NORMAL;
setting.step_delay = 0; setting.step_delay = 0;
} else if (test == 5) { }
#ifdef DOESNOTFIT
else if (test == 5) {
// reset_settings(M_LOW); // Make sure we are in a defined state // reset_settings(M_LOW); // Make sure we are in a defined state
in_selftest = true; in_selftest = true;
switch (setting.test_argument) { switch (setting.test_argument) {
@ -3622,6 +3624,7 @@ void self_test(int test)
} }
in_selftest = false; in_selftest = false;
} }
#endif
show_test_info = FALSE; show_test_info = FALSE;
in_selftest = false; in_selftest = false;
test_wait = false; test_wait = false;

Loading…
Cancel
Save

Powered by TurnKey Linux.