- I assume your purpose here is to make the
hilbert
function faster, because you will call it multiple times. You've moved the FFT plan creation outside ofhilbert
, which is probably a huge speed increase. However, you still callfftw_destroy_plan
withinhilbert
. This is a problem if you callhilbert
more than once. You should movefftw_destroy_plan
outside ofhilbert
, so it would be called frommain
instead. - You have three different
for
loops insidehilbert
. One copies data from input vector to output vector. One scales half the output vector by a factor of 2. One scales the output vector by 1/N. These loops can all be combined into a single loop at the beginning ofhilbert
. This works because an FFT is linear, so scaling the input by a constant factor is the same as scaling the output by a constant factor. This new loop would look something like:
Then you would get rid of the otherauto scale = 2.0 / N; for (int i = 0; i < N; ++i) { out[i][REAL] = in[i] * scale; out[i][IMAG] = 0.0; }
for
loops. You would also get rid of the code which multiplies out[hN] by 2 (but keep the call tomemset
which zeros the second half of the output). Finally, you need to fix out[0], which is now too large by a factor of two:
However, the speed increase from combining these loops is probably small compared to the FFT time.out[0][REAL] /= 2.0; out[0][IMAG] /= 2.0;
- It may take a little more work, but you could change the forward FFT so that it takes its input directly from the real-valued input vector. This is probably close to twice as fast as the complex FFT you are currently doing (but this is just for the forward FFT, so your overall speed increase might be up to 25%). Still, I think you will findit is likely that your complex FFT is already fast enough now that you removeyou've removed the creation/destruction of the plan outside of
hilbert
.
Explain that overall speed increase from a real-valued forward FFT would be up to 25%.
Eric Backus
- 241
- 1
- 4
- 7