Always measure noise power, silently ignore --measure-noise if given.
This commit is contained in:
parent
acd38708cc
commit
b8dc3973d1
52
convert.c
52
convert.c
|
@ -26,38 +26,7 @@ struct converter_state {
|
||||||
float z1_Q;
|
float z1_Q;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void convert_uc8_nodc_nopower(void *iq_data,
|
static void convert_uc8_nodc(void *iq_data,
|
||||||
uint16_t *mag_data,
|
|
||||||
unsigned nsamples,
|
|
||||||
struct converter_state *state,
|
|
||||||
double *out_power)
|
|
||||||
{
|
|
||||||
uint16_t *in = iq_data;
|
|
||||||
unsigned i;
|
|
||||||
|
|
||||||
MODES_NOTUSED(state);
|
|
||||||
|
|
||||||
// unroll this a bit
|
|
||||||
for (i = 0; i < (nsamples>>3); ++i) {
|
|
||||||
*mag_data++ = Modes.maglut[*in++];
|
|
||||||
*mag_data++ = Modes.maglut[*in++];
|
|
||||||
*mag_data++ = Modes.maglut[*in++];
|
|
||||||
*mag_data++ = Modes.maglut[*in++];
|
|
||||||
*mag_data++ = Modes.maglut[*in++];
|
|
||||||
*mag_data++ = Modes.maglut[*in++];
|
|
||||||
*mag_data++ = Modes.maglut[*in++];
|
|
||||||
*mag_data++ = Modes.maglut[*in++];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < (nsamples&7); ++i) {
|
|
||||||
*mag_data++ = Modes.maglut[*in++];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (out_power)
|
|
||||||
*out_power = 0.0; // not measured
|
|
||||||
}
|
|
||||||
|
|
||||||
static void convert_uc8_nodc_power(void *iq_data,
|
|
||||||
uint16_t *mag_data,
|
uint16_t *mag_data,
|
||||||
unsigned nsamples,
|
unsigned nsamples,
|
||||||
struct converter_state *state,
|
struct converter_state *state,
|
||||||
|
@ -251,23 +220,20 @@ static void convert_sc16q11_generic(void *iq_data,
|
||||||
static struct {
|
static struct {
|
||||||
input_format_t format;
|
input_format_t format;
|
||||||
int can_filter_dc;
|
int can_filter_dc;
|
||||||
int can_compute_power;
|
|
||||||
iq_convert_fn fn;
|
iq_convert_fn fn;
|
||||||
const char *description;
|
const char *description;
|
||||||
} converters_table[] = {
|
} converters_table[] = {
|
||||||
// In order of preference
|
// In order of preference
|
||||||
{ INPUT_UC8, 0, 0, convert_uc8_nodc_nopower, "UC8, integer/table path" },
|
{ INPUT_UC8, 0, convert_uc8_nodc, "UC8, integer/table path" },
|
||||||
{ INPUT_UC8, 0, 1, convert_uc8_nodc_power, "UC8, integer/table path, with power measurement" },
|
{ INPUT_UC8, 1, convert_uc8_generic, "UC8, float path" },
|
||||||
{ INPUT_UC8, 1, 1, convert_uc8_generic, "UC8, float path" },
|
{ INPUT_SC16, 1, convert_sc16_generic, "SC16, float path" },
|
||||||
{ INPUT_SC16, 1, 1, convert_sc16_generic, "SC16, float path" },
|
{ INPUT_SC16Q11, 1, convert_sc16q11_generic, "SC16Q11, float path" },
|
||||||
{ INPUT_SC16Q11, 1, 1, convert_sc16q11_generic, "SC16Q11, float path" },
|
{ 0, 0, NULL, NULL }
|
||||||
{ 0, 0, 0, NULL, NULL }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
iq_convert_fn init_converter(input_format_t format,
|
iq_convert_fn init_converter(input_format_t format,
|
||||||
double sample_rate,
|
double sample_rate,
|
||||||
int filter_dc,
|
int filter_dc,
|
||||||
int compute_power,
|
|
||||||
struct converter_state **out_state)
|
struct converter_state **out_state)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -277,14 +243,12 @@ iq_convert_fn init_converter(input_format_t format,
|
||||||
continue;
|
continue;
|
||||||
if (filter_dc && !converters_table[i].can_filter_dc)
|
if (filter_dc && !converters_table[i].can_filter_dc)
|
||||||
continue;
|
continue;
|
||||||
if (compute_power && !converters_table[i].can_compute_power)
|
|
||||||
continue;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!converters_table[i].fn) {
|
if (!converters_table[i].fn) {
|
||||||
fprintf(stderr, "no suitable converter for format=%d power=%d dc=%d\n",
|
fprintf(stderr, "no suitable converter for format=%d dc=%d\n",
|
||||||
format, compute_power, filter_dc);
|
format, filter_dc);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ typedef void (*iq_convert_fn)(void *iq_data,
|
||||||
iq_convert_fn init_converter(input_format_t format,
|
iq_convert_fn init_converter(input_format_t format,
|
||||||
double sample_rate,
|
double sample_rate,
|
||||||
int filter_dc,
|
int filter_dc,
|
||||||
int compute_power,
|
|
||||||
struct converter_state **out_state);
|
struct converter_state **out_state);
|
||||||
|
|
||||||
void cleanup_converter(struct converter_state *state);
|
void cleanup_converter(struct converter_state *state);
|
||||||
|
|
|
@ -423,8 +423,8 @@ void demodulate2400(struct mag_buf *mag)
|
||||||
useModesMessage(&mm);
|
useModesMessage(&mm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* update noise power if measured */
|
/* update noise power */
|
||||||
if (Modes.measure_noise) {
|
{
|
||||||
double sum_signal_power = sum_scaled_signal_power / 65535.0 / 65535.0;
|
double sum_signal_power = sum_scaled_signal_power / 65535.0 / 65535.0;
|
||||||
Modes.stats_current.noise_power_sum += (mag->total_power - sum_signal_power);
|
Modes.stats_current.noise_power_sum += (mag->total_power - sum_signal_power);
|
||||||
Modes.stats_current.noise_power_count += mag->length;
|
Modes.stats_current.noise_power_count += mag->length;
|
||||||
|
|
|
@ -256,7 +256,6 @@ void modesInit(void) {
|
||||||
Modes.converter_function = init_converter(Modes.input_format,
|
Modes.converter_function = init_converter(Modes.input_format,
|
||||||
Modes.sample_rate,
|
Modes.sample_rate,
|
||||||
Modes.dc_filter,
|
Modes.dc_filter,
|
||||||
Modes.measure_noise, /* total power is interesting if we want noise */
|
|
||||||
&Modes.converter_state);
|
&Modes.converter_state);
|
||||||
if (!Modes.converter_function) {
|
if (!Modes.converter_function) {
|
||||||
fprintf(stderr, "Can't initialize sample converter, giving up.\n");
|
fprintf(stderr, "Can't initialize sample converter, giving up.\n");
|
||||||
|
@ -723,7 +722,6 @@ void showHelp(void) {
|
||||||
"--json-location-accuracy <n> Accuracy of receiver location in json metadata: 0=no location, 1=approximate, 2=exact\n"
|
"--json-location-accuracy <n> Accuracy of receiver location in json metadata: 0=no location, 1=approximate, 2=exact\n"
|
||||||
"--oversample Use the 2.4MHz demodulator\n"
|
"--oversample Use the 2.4MHz demodulator\n"
|
||||||
"--dcfilter Apply a 1Hz DC filter to input data (requires lots more CPU)\n"
|
"--dcfilter Apply a 1Hz DC filter to input data (requires lots more CPU)\n"
|
||||||
"--measure-noise Measure noise power (requires slightly more CPU)\n"
|
|
||||||
"--help Show this help\n"
|
"--help Show this help\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Debug mode flags: d = Log frames decoded with errors\n"
|
"Debug mode flags: d = Log frames decoded with errors\n"
|
||||||
|
@ -955,7 +953,7 @@ int main(int argc, char **argv) {
|
||||||
} else if (!strcmp(argv[j],"--dcfilter")) {
|
} else if (!strcmp(argv[j],"--dcfilter")) {
|
||||||
Modes.dc_filter = 1;
|
Modes.dc_filter = 1;
|
||||||
} else if (!strcmp(argv[j],"--measure-noise")) {
|
} else if (!strcmp(argv[j],"--measure-noise")) {
|
||||||
Modes.measure_noise = 1;
|
// Ignored
|
||||||
} else if (!strcmp(argv[j],"--fix")) {
|
} else if (!strcmp(argv[j],"--fix")) {
|
||||||
Modes.nfix_crc = 1;
|
Modes.nfix_crc = 1;
|
||||||
} else if (!strcmp(argv[j],"--no-fix")) {
|
} else if (!strcmp(argv[j],"--no-fix")) {
|
||||||
|
|
|
@ -253,7 +253,6 @@ struct { // Internal state
|
||||||
|
|
||||||
// Sample conversion
|
// Sample conversion
|
||||||
int dc_filter; // should we apply a DC filter?
|
int dc_filter; // should we apply a DC filter?
|
||||||
int measure_noise; // should we measure noise power?
|
|
||||||
iq_convert_fn converter_function;
|
iq_convert_fn converter_function;
|
||||||
struct converter_state *converter_state;
|
struct converter_state *converter_state;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue