Skip to content

Commit d2a0099

Browse files
committed
Precalculate FFT window
Before this calculating FFT window was taking much more CPU time than calculating the FFT itself.
1 parent f9d6d22 commit d2a0099

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

csdr.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,8 @@ int main(int argc, char *argv[])
12451245
FFT_PLAN_T* plan=make_fft_c2c(fft_size, windowed, output, 1, benchmark);
12461246
if(benchmark) fprintf(stderr," done\n");
12471247
if(octave) printf("setenv(\"GNUTERM\",\"X11 noraise\");y=zeros(1,%d);semilogy(y,\"ydatasource\",\"y\");\n",fft_size);
1248+
float *windowt;
1249+
windowt = precalculate_window(fft_size, window);
12481250
for(;;)
12491251
{
12501252
FEOF_CHECK;
@@ -1263,7 +1265,8 @@ int main(int argc, char *argv[])
12631265
for(int i=0;i<fft_size-every_n_samples;i++) input[i]=input[i+every_n_samples];
12641266
fread(input+fft_size-every_n_samples, sizeof(complexf), every_n_samples, stdin);
12651267
}
1266-
apply_window_c(input,windowed,fft_size,window);
1268+
//apply_window_c(input,windowed,fft_size,window);
1269+
apply_precalculated_window_c(input,windowed,fft_size,windowt);
12671270
fft_execute(plan);
12681271
if(octave)
12691272
{

libcsdr.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,29 @@ void apply_window_c(complexf* input, complexf* output, int size, window_t window
930930
}
931931
}
932932

933+
float *precalculate_window(int size, window_t window)
934+
{
935+
float (*window_function)(float)=firdes_get_window_kernel(window);
936+
float *windowt;
937+
windowt = malloc(sizeof(float) * size);
938+
for(int i=0;i<size;i++) //@precalculate_window
939+
{
940+
float rate=(float)i/(size-1);
941+
windowt[i] = window_function(2.0*rate+1.0);
942+
}
943+
return windowt;
944+
}
945+
946+
void apply_precalculated_window_c(complexf* input, complexf* output, int size, float *windowt)
947+
{
948+
for(int i=0;i<size;i++) //@apply_precalculated_window_c
949+
{
950+
iof(output,i)=iof(input,i)*windowt[i];
951+
qof(output,i)=qof(input,i)*windowt[i];
952+
}
953+
}
954+
955+
933956
void apply_window_f(float* input, float* output, int size, window_t window)
934957
{
935958
float (*window_function)(float)=firdes_get_window_kernel(window);

libcsdr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ typedef struct rational_resampler_ff_s
135135
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);
136136
void rational_resampler_get_lowpass_f(float* output, int output_size, int interpolation, int decimation, window_t window);
137137

138+
float *precalculate_window(int size, window_t window);
138139
void apply_window_c(complexf* input, complexf* output, int size, window_t window);
140+
void apply_precalculated_window_c(complexf* input, complexf* output, int size, float *windowt);
139141
void apply_window_f(float* input, float* output, int size, window_t window);
140142
void logpower_cf(complexf* input, float* output, int size, float add_db);
141143
void accumulate_power_cf(complexf* input, float* output, int size);

0 commit comments

Comments
 (0)