Always measure noise power, silently ignore --measure-noise if given.

This commit is contained in:
Oliver Jowett 2016-05-31 11:54:34 +01:00
parent acd38708cc
commit b8dc3973d1
5 changed files with 15 additions and 55 deletions

View file

@ -26,42 +26,11 @@ struct converter_state {
float z1_Q;
};
static void convert_uc8_nodc_nopower(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,
unsigned nsamples,
struct converter_state *state,
double *out_power)
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;
@ -251,23 +220,20 @@ static void convert_sc16q11_generic(void *iq_data,
static struct {
input_format_t format;
int can_filter_dc;
int can_compute_power;
iq_convert_fn fn;
const char *description;
} converters_table[] = {
// In order of preference
{ INPUT_UC8, 0, 0, convert_uc8_nodc_nopower, "UC8, integer/table path" },
{ INPUT_UC8, 0, 1, convert_uc8_nodc_power, "UC8, integer/table path, with power measurement" },
{ INPUT_UC8, 1, 1, convert_uc8_generic, "UC8, float path" },
{ INPUT_SC16, 1, 1, convert_sc16_generic, "SC16, float path" },
{ INPUT_SC16Q11, 1, 1, convert_sc16q11_generic, "SC16Q11, float path" },
{ 0, 0, 0, NULL, NULL }
{ INPUT_UC8, 0, convert_uc8_nodc, "UC8, integer/table path" },
{ INPUT_UC8, 1, convert_uc8_generic, "UC8, float path" },
{ INPUT_SC16, 1, convert_sc16_generic, "SC16, float path" },
{ INPUT_SC16Q11, 1, convert_sc16q11_generic, "SC16Q11, float path" },
{ 0, 0, NULL, NULL }
};
iq_convert_fn init_converter(input_format_t format,
double sample_rate,
int filter_dc,
int compute_power,
struct converter_state **out_state)
{
int i;
@ -277,14 +243,12 @@ iq_convert_fn init_converter(input_format_t format,
continue;
if (filter_dc && !converters_table[i].can_filter_dc)
continue;
if (compute_power && !converters_table[i].can_compute_power)
continue;
break;
}
if (!converters_table[i].fn) {
fprintf(stderr, "no suitable converter for format=%d power=%d dc=%d\n",
format, compute_power, filter_dc);
fprintf(stderr, "no suitable converter for format=%d dc=%d\n",
format, filter_dc);
return NULL;
}

View file

@ -32,7 +32,6 @@ typedef void (*iq_convert_fn)(void *iq_data,
iq_convert_fn init_converter(input_format_t format,
double sample_rate,
int filter_dc,
int compute_power,
struct converter_state **out_state);
void cleanup_converter(struct converter_state *state);

View file

@ -423,8 +423,8 @@ void demodulate2400(struct mag_buf *mag)
useModesMessage(&mm);
}
/* update noise power if measured */
if (Modes.measure_noise) {
/* update noise power */
{
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_count += mag->length;

View file

@ -256,7 +256,6 @@ void modesInit(void) {
Modes.converter_function = init_converter(Modes.input_format,
Modes.sample_rate,
Modes.dc_filter,
Modes.measure_noise, /* total power is interesting if we want noise */
&Modes.converter_state);
if (!Modes.converter_function) {
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"
"--oversample Use the 2.4MHz demodulator\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"
"\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")) {
Modes.dc_filter = 1;
} else if (!strcmp(argv[j],"--measure-noise")) {
Modes.measure_noise = 1;
// Ignored
} else if (!strcmp(argv[j],"--fix")) {
Modes.nfix_crc = 1;
} else if (!strcmp(argv[j],"--no-fix")) {

View file

@ -253,7 +253,6 @@ struct { // Internal state
// Sample conversion
int dc_filter; // should we apply a DC filter?
int measure_noise; // should we measure noise power?
iq_convert_fn converter_function;
struct converter_state *converter_state;