THD measurement added

pull/5/head
erikkaashoek 5 years ago
parent e660f336c0
commit aca8f2dbcc

@ -39,7 +39,7 @@
//#define __ULTRA__ // Add harmonics mode on low input. //#define __ULTRA__ // Add harmonics mode on low input.
//#define __ULTRA_SA__ // Adds ADF4351 control for extra high 1st IF stage //#define __ULTRA_SA__ // Adds ADF4351 control for extra high 1st IF stage
#define __SPUR__ // Does spur reduction by shifting IF #define __SPUR__ // Does spur reduction by shifting IF
#define __USE_SERIAL_CONSOLE__ // Enable serial I/O connection (need enable HAL_USE_SERIAL as TRUE in halconf.h) //#define __USE_SERIAL_CONSOLE__ // Enable serial I/O connection (need enable HAL_USE_SERIAL as TRUE in halconf.h)
/* /*
* main.c * main.c
*/ */
@ -235,6 +235,7 @@ extern int32_t frequencyExtra;
void set_10mhz(uint32_t); void set_10mhz(uint32_t);
void set_modulation(int); void set_modulation(int);
void set_modulation_frequency(int); void set_modulation_frequency(int);
int search_maximum(int m, int center, int span);
//extern int setting.modulation; //extern int setting.modulation;
void set_measurement(int); void set_measurement(int);
// extern int settingSpeed; // extern int settingSpeed;
@ -998,7 +999,7 @@ uint32_t calc_min_sweep_time_us(void);
pureRSSI_t perform(bool b, int i, uint32_t f, int e); pureRSSI_t perform(bool b, int i, uint32_t f, int e);
enum { enum {
M_OFF, M_IMD, M_OIP3, M_PHASE_NOISE, M_STOP_BAND, M_PASS_BAND, M_LINEARITY, M_AM, M_FM M_OFF, M_IMD, M_OIP3, M_PHASE_NOISE, M_STOP_BAND, M_PASS_BAND, M_LINEARITY, M_AM, M_FM, M_THD
}; };
enum { enum {

@ -2081,7 +2081,35 @@ static void cell_draw_marker_info(int x0, int y0)
active++; active++;
} }
} }
if (setting.measurement == M_THD && active >= 1)
active = 2;
for (int i = 0; i < MARKER_COUNT; i++) { for (int i = 0; i < MARKER_COUNT; i++) {
if (i >= 2 && setting.measurement == M_THD) {
if (i == 2) {
int old_unit = setting.unit;
setting.unit = U_WATT;
float p = value((actual_t[markers[0].index]));
int j = 2;
uint32_t f = markers[0].frequency;
float h = 0.0;
while (f * j < frequencies[sweep_points-1]) {
if (search_maximum(1, f*j, 4*j) ) // use marker 1 for searching harmonics
h += value((actual_t[markers[1].index]));
j++;
}
float thd = 100.0 * sqrt(h/p);
setting.unit = old_unit;
plot_printf(buf, sizeof buf, "THD: %4.1f%%", thd);
j = 1;
int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0;
int ypos = 1 + (j/2)*(16) - y0;
cell_drawstring_7x13(buf, xpos, ypos);
// cell_drawstring(buf, xpos, ypos);
break;
}
break;
} 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 = value((actual_t[markers[2].index]));
float ir = value((actual_t[markers[3].index])); float ir = value((actual_t[markers[3].index]));

@ -851,7 +851,6 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb)
break; break;
case M_LINEARITY: case M_LINEARITY:
set_measurement(M_LINEARITY); set_measurement(M_LINEARITY);
ui_mode_normal();
break; break;
case M_AM: // OIP3 case M_AM: // OIP3
reset_settings(setting.mode); reset_settings(setting.mode);
@ -882,6 +881,9 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb)
set_sweep_frequency(ST_SPAN, uistat.value*30); set_sweep_frequency(ST_SPAN, uistat.value*30);
set_measurement(M_FM); set_measurement(M_FM);
break; break;
case M_THD:
set_measurement(M_THD);
break;
} }
#endif #endif
// selection = -1; // selection = -1;
@ -1682,6 +1684,7 @@ static const menuitem_t menu_measure2[] = {
// { MT_ADV_CALLBACK | MT_LOW, M_LINEARITY, "LINEAR", menu_measure_acb}, // { MT_ADV_CALLBACK | MT_LOW, M_LINEARITY, "LINEAR", menu_measure_acb},
{ MT_ADV_CALLBACK, M_AM, "AM", menu_measure_acb}, { MT_ADV_CALLBACK, M_AM, "AM", menu_measure_acb},
{ MT_ADV_CALLBACK, M_FM, "FM", menu_measure_acb}, { MT_ADV_CALLBACK, M_FM, "FM", menu_measure_acb},
{ MT_ADV_CALLBACK, M_THD, "THD", menu_measure_acb},
{ MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel { MT_NONE, 0, NULL, NULL } // sentinel
}; };

Loading…
Cancel
Save

Powered by TurnKey Linux.