Precalculate FFT window

Before this calculating FFT window was taking much more CPU time than calculating the FFT itself.
This commit is contained in:
Tatu Peltola 2016-03-26 11:44:28 +02:00
parent f9d6d22fe2
commit d2a0099227
3 changed files with 29 additions and 1 deletions

5
csdr.c
View file

@ -1245,6 +1245,8 @@ int main(int argc, char *argv[])
FFT_PLAN_T* plan=make_fft_c2c(fft_size, windowed, output, 1, benchmark); FFT_PLAN_T* plan=make_fft_c2c(fft_size, windowed, output, 1, benchmark);
if(benchmark) fprintf(stderr," done\n"); if(benchmark) fprintf(stderr," done\n");
if(octave) printf("setenv(\"GNUTERM\",\"X11 noraise\");y=zeros(1,%d);semilogy(y,\"ydatasource\",\"y\");\n",fft_size); if(octave) printf("setenv(\"GNUTERM\",\"X11 noraise\");y=zeros(1,%d);semilogy(y,\"ydatasource\",\"y\");\n",fft_size);
float *windowt;
windowt = precalculate_window(fft_size, window);
for(;;) for(;;)
{ {
FEOF_CHECK; FEOF_CHECK;
@ -1263,7 +1265,8 @@ int main(int argc, char *argv[])
for(int i=0;i<fft_size-every_n_samples;i++) input[i]=input[i+every_n_samples]; for(int i=0;i<fft_size-every_n_samples;i++) input[i]=input[i+every_n_samples];
fread(input+fft_size-every_n_samples, sizeof(complexf), every_n_samples, stdin); fread(input+fft_size-every_n_samples, sizeof(complexf), every_n_samples, stdin);
} }
apply_window_c(input,windowed,fft_size,window); //apply_window_c(input,windowed,fft_size,window);
apply_precalculated_window_c(input,windowed,fft_size,windowt);
fft_execute(plan); fft_execute(plan);
if(octave) if(octave)
{ {

View file

@ -930,6 +930,29 @@ void apply_window_c(complexf* input, complexf* output, int size, window_t window
} }
} }
float *precalculate_window(int size, window_t window)
{
float (*window_function)(float)=firdes_get_window_kernel(window);
float *windowt;
windowt = malloc(sizeof(float) * size);
for(int i=0;i<size;i++) //@precalculate_window
{
float rate=(float)i/(size-1);
windowt[i] = window_function(2.0*rate+1.0);
}
return windowt;
}
void apply_precalculated_window_c(complexf* input, complexf* output, int size, float *windowt)
{
for(int i=0;i<size;i++) //@apply_precalculated_window_c
{
iof(output,i)=iof(input,i)*windowt[i];
qof(output,i)=qof(input,i)*windowt[i];
}
}
void apply_window_f(float* input, float* output, int size, window_t window) void apply_window_f(float* input, float* output, int size, window_t window)
{ {
float (*window_function)(float)=firdes_get_window_kernel(window); float (*window_function)(float)=firdes_get_window_kernel(window);

View file

@ -135,7 +135,9 @@ typedef struct rational_resampler_ff_s
rational_resampler_ff_t rational_resampler_ff(float *input, float *output, int input_size, int interpolation, int decimation, float *taps, int taps_length, int last_taps_delay); rational_resampler_ff_t rational_resampler_ff(float *input, float *output, int input_size, int interpolation, int decimation, float *taps, int taps_length, int last_taps_delay);
void rational_resampler_get_lowpass_f(float* output, int output_size, int interpolation, int decimation, window_t window); void rational_resampler_get_lowpass_f(float* output, int output_size, int interpolation, int decimation, window_t window);
float *precalculate_window(int size, window_t window);
void apply_window_c(complexf* input, complexf* output, int size, window_t window); void apply_window_c(complexf* input, complexf* output, int size, window_t window);
void apply_precalculated_window_c(complexf* input, complexf* output, int size, float *windowt);
void apply_window_f(float* input, float* output, int size, window_t window); void apply_window_f(float* input, float* output, int size, window_t window);
void logpower_cf(complexf* input, float* output, int size, float add_db); void logpower_cf(complexf* input, float* output, int size, float add_db);
void accumulate_power_cf(complexf* input, float* output, int size); void accumulate_power_cf(complexf* input, float* output, int size);