Averaged noise marker caching and improve LF noise floor with large RBW

multi_trace
erikkaashoek 5 years ago
parent 98f574f296
commit 3427a4501a

@ -676,6 +676,7 @@ float get_level_offset(void);
extern uint8_t in_selftest; extern uint8_t in_selftest;
extern int display_test(void); extern int display_test(void);
extern void clear_marker_cache(void);
// //
// Shell config functions and macros // Shell config functions and macros

@ -280,9 +280,20 @@ index_to_value(const int i)
return(value(actual_t[i])); return(value(actual_t[i]));
} }
#endif #endif
float marker_cache[MARKERS_MAX];
bool marker_cache_valid[MARKERS_MAX];
void
clear_marker_cache(void)
{
for (int i = 0; i<MARKERS_MAX; i++)
marker_cache_valid[i] = false;
}
float float
marker_to_value(const int i) marker_to_value(const int i)
{ {
if (marker_cache_valid[i])
return marker_cache[i];
float *ref_marker_levels; float *ref_marker_levels;
if (markers[i].mtype & M_STORED ) if (markers[i].mtype & M_STORED )
ref_marker_levels = stored_t; ref_marker_levels = stored_t;
@ -290,11 +301,26 @@ marker_to_value(const int i)
ref_marker_levels = actual_t; ref_marker_levels = actual_t;
float v = value(ref_marker_levels[markers[i].index]); float v = value(ref_marker_levels[markers[i].index]);
if (markers[i].mtype & M_AVER) { if (markers[i].mtype & M_AVER) {
int old_unit = setting.unit;
if (markers[i].mtype & M_NOISE)
setting.unit = U_WATT; // Noise averaging should always be done in Watts
v = 0; v = 0;
for (int i=0; i<sweep_points; i++) for (int i=0; i<sweep_points; i++)
v += value(ref_marker_levels[i]); v += value(ref_marker_levels[i]); // TODO this should be power averaging for noise markers
v /= sweep_points; v /= sweep_points;
v = to_dBm(v);
setting.unit = old_unit;
v = value(v);
}
if (markers[i].mtype & M_NOISE){
v = v - logf(actual_rbw_x10*100.0) * (10.0/logf(10.0))
#ifdef TINYSA4
+ SI4463_noise_correction_x10/10.0
#endif
;
} }
marker_cache_valid[i] = true;
marker_cache[i] = v;
return(v); return(v);
} }
@ -1444,13 +1470,6 @@ static void trace_print_value_string( // Only used at one place
// if (mtype & M_NOISE) // if (mtype & M_NOISE)
// *ptr2++ = 'N'; // *ptr2++ = 'N';
*ptr2++ = ' '; *ptr2++ = ' ';
if (mtype & M_NOISE){
v += - logf(actual_rbw_x10*100.0) * (10.0/logf(10.0))
#ifdef TINYSA4
+ SI4463_noise_correction_x10/10.0
#endif
;
}
// Not possible ??? // Not possible ???
if (v == -INFINITY){ if (v == -INFINITY){
cell_printf(xpos, ypos, FONT_b"%s-INF", buf2); cell_printf(xpos, ypos, FONT_b"%s-INF", buf2);
@ -1480,15 +1499,15 @@ static void trace_print_value_string( // Only used at one place
} }
const char *format; const char *format;
if (UNIT_IS_LINEAR(setting.unit)) if (UNIT_IS_LINEAR(setting.unit))
format = FONT_s"%s %.3F%s%s"; // 5 characters incl u, m, etc... format = FONT_s"%s %.3F%s%s%s"; // 5 characters incl u, m, etc...
else else
format = FONT_s"%s %.1f%s%s"; format = FONT_s"%s %.1f%s%s%s";
#ifdef TINYSA4 #ifdef TINYSA4
format++; // Skip small prefix for bold output format++; // Skip small prefix for bold output
#else #else
if (bold) format++; // Skip small prefix for bold output if (bold) format++; // Skip small prefix for bold output
#endif #endif
cell_printf(xpos, ypos, format, buf2, v, unit_string[unit_index], (mtype & M_NOISE?"/Hz":(mtype & M_AVER?"/T":""))); cell_printf(xpos, ypos, format, buf2, v, unit_string[unit_index], (mtype & M_NOISE?"/Hz":""), (mtype & M_AVER?"/T":""));
} }
static void cell_draw_marker_info(int x0, int y0) static void cell_draw_marker_info(int x0, int y0)
@ -1608,21 +1627,14 @@ static void cell_draw_marker_info(int x0, int y0)
#ifdef __NOISE_FIGURE__ #ifdef __NOISE_FIGURE__
} else if (i>=2 && setting.measurement == M_NF && markers[0].enabled) { } else if (i>=2 && setting.measurement == M_NF && markers[0].enabled) {
float aNP = 0; float aNP = 0;
#if 1
for (int i =0; i < sweep_points; i++) {
aNP += actual_t[i];
}
aNP /= sweep_points;
#else
aNP = marker_to_value(0); aNP = marker_to_value(0);
#endif float mNF = aNP + 173.93 - nf_gain; // measured noise figure at 20C
float mNF = aNP - logf(actual_rbw_x10*100.0) * (10.0/logf(10.0)) + 173.93 + SI4463_noise_correction_x10/10.0; // measured noise figure at 20C
if (nf_gain != 0) { if (nf_gain != 0) {
float mnf = expf((mNF - nf_gain)/10 * logf(10)); // measure noise factor float mnf = expf(mNF/10.0 * logf(10)); // measure noise factor
float tnf = expf(config.noise_figure/10 * logf(10)); // tinySA noise factor float tnf = expf(config.noise_figure/10.0 * logf(10.0)); // tinySA noise factor
float amp_gain = expf(nf_gain/10 * logf(10)); float amp_gain = expf(nf_gain/10.0 * logf(10.0));
float anf = mnf - (tnf - 1.0)/amp_gain; float anf = mnf - (tnf - 1.0)/amp_gain;
mNF = 10*logf(anf)/logf(10); mNF = 10.0*logf(anf)/logf(10.0);
} }
// powf(10,x) = expf(x * logf(10)) // powf(10,x) = expf(x * logf(10))
// log10f(x) = logf(x)/logf(10) // log10f(x) = logf(x)/logf(10)

@ -3320,7 +3320,7 @@ again: // Spur redu
} }
set_freq(ADF4351_LO, target_f); set_freq(ADF4351_LO, target_f);
#if 1 // Compensate frequency ADF4350 error with SI4468 #if 1 // Compensate frequency ADF4350 error with SI4468
if (actual_rbw_x10 < 3000 || setting.frequency_step < 100000) { if (actual_rbw_x10 < 10000 || setting.frequency_step < 100000) {
int32_t error_f = 0; int32_t error_f = 0;
if (real_old_freq[ADF4351_LO] > target_f) { if (real_old_freq[ADF4351_LO] > target_f) {
error_f = real_old_freq[ADF4351_LO] - target_f; error_f = real_old_freq[ADF4351_LO] - target_f;
@ -3588,11 +3588,13 @@ again: // Spur redu
my_step_delay = my_step_delay * 2; my_step_delay = my_step_delay * 2;
// if (LO_shifted) // || SI4463_offset_changed) // if (LO_shifted) // || SI4463_offset_changed)
// my_step_delay = my_step_delay * 2; // my_step_delay = my_step_delay * 2;
#if 0 // Always have some delay before measuring RSSI
if (old_R < 4 && actual_rbw_x10 >= 1000 && SI4463_frequency_changed && ADF4351_frequency_changed) { if (old_R < 4 && actual_rbw_x10 >= 1000 && SI4463_frequency_changed && ADF4351_frequency_changed) {
my_step_delay -= 200; // compensate for additional delay of setting SI4463 my_step_delay -= 200; // compensate for additional delay of setting SI4463
if (my_step_delay < 0) if (my_step_delay < 0)
my_step_delay = 0; my_step_delay = 0;
} }
#endif
my_microsecond_delay(my_step_delay * (old_R > 5 ? 8 : (old_R > 3 ? 2 : 1))); my_microsecond_delay(my_step_delay * (old_R > 5 ? 8 : (old_R > 3 ? 2 : 1)));
ADF4351_frequency_changed = false; ADF4351_frequency_changed = false;
SI4463_frequency_changed = false; SI4463_frequency_changed = false;
@ -3738,7 +3740,7 @@ static bool sweep(bool break_on_operation)
float vbw_rssi; float vbw_rssi;
#endif #endif
#endif #endif
clear_marker_cache();
again: // Waiting for a trigger jumps back to here again: // Waiting for a trigger jumps back to here
setting.measure_sweep_time_us = 0; // start measure sweep time setting.measure_sweep_time_us = 0; // start measure sweep time
// start_of_sweep_timestamp = chVTGetSystemTimeX(); // Will be set in perform // start_of_sweep_timestamp = chVTGetSystemTimeX(); // Will be set in perform

@ -1347,7 +1347,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb)
case M_NF: // noise figure case M_NF: // noise figure
// reset_settings(setting.mode); // reset_settings(setting.mode);
markers[0].enabled = M_ENABLED; markers[0].enabled = M_ENABLED;
markers[0].mtype = M_NOISE; // Not tracking markers[0].mtype = M_NOISE | M_AVER; // Not tracking
set_extra_lna(true); set_extra_lna(true);
kp_help_text = "Amplifier Gain "; kp_help_text = "Amplifier Gain ";
float old_gain = setting.external_gain; float old_gain = setting.external_gain;

Loading…
Cancel
Save

Powered by TurnKey Linux.