Fix logaveragepower_cf for FFT sizes below 16384

This commit is contained in:
Tatu Peltola 2016-10-22 22:16:47 +03:00
parent 8cbf028732
commit 38d567d96e
2 changed files with 10 additions and 14 deletions

22
csdr.c
View file

@ -1344,27 +1344,23 @@ int main(int argc, char *argv[])
sscanf(argv[3],"%d",&fft_size);
sscanf(argv[4],"%d",&avgnumber);
if(!getbufsize()) return -2; //dummy
if(!sendbufsize(initialize_buffers())) return -2;
float *input = malloc(sizeof(float)*2 * fft_size);
float *output = malloc(sizeof(float) * fft_size);
if(fft_size != the_bufsize) return -2;
//fprintf(stderr, "logaveragepower_cf %f %d=%d %d\n", add_db, fft_size, the_bufsize, avgnumber);
add_db -= 10*log10(avgnumber);
add_db -= 10.0*log10(avgnumber);
for(;;)
{
int i,n;
for(i = 0; i < the_bufsize; i++) {
output_buffer[i] = 0;
for(i = 0; i < fft_size; i++) {
output[i] = 0;
}
FEOF_CHECK;
for(n = 0; n < avgnumber; n++) {
FREAD_C;
//fprintf(stderr, "averaged %d\n", n);
accumulate_power_cf((complexf*)input_buffer, output_buffer, the_bufsize);
fread (input, sizeof(float)*2, fft_size, stdin);
accumulate_power_cf((complexf*)input, output, fft_size);
}
log_ff(NULL, output_buffer, the_bufsize, add_db);
FWRITE_R;
log_ff(output, output, fft_size, add_db);
fwrite (output, sizeof(float), fft_size, stdout);
TRY_YIELD;
}
return 0;

View file

@ -979,7 +979,7 @@ void accumulate_power_cf(complexf* input, float* output, int size)
}
void log_ff(float* input, float* output, int size, float add_db) {
for(int i=0;i<size;i++) output[i]=log10(output[i]); //@logpower_cf: pass 2
for(int i=0;i<size;i++) output[i]=log10(input[i]); //@logpower_cf: pass 2
for(int i=0;i<size;i++) output[i]=10*output[i]+add_db; //@logpower_cf: pass 3
}