I am using fftw3 lib for computing a fourier transform in c++. I have to repeatedly call it with a different input array everytime. I am initializing my array (called 'input' in code ) just once with size MAX_ELEMS and then using it as input to the fftw_plan function (changing contents and their size) on every call. However I am changing my n_samples everytime according to actual size of my array (number of valid data samples in the array). I wanted to know if this will cause any problems in my implementation- execution/accuracy wise.
fftw_plan fftw_plan_dft_r2c_1d(int n_samples,
double *in, fftw_complex *out,
Ideally you want to pick a specific size of FFT and stick with it, for two reasons:
Ideally you should use a fixed FFT size so that you create/destroy a plan just once.
If your data stream is contiguous then just pick an appropriate FFT size, N, and accumulate samples in a buffer until you have N samples to process, and save the rest until you have N samples again.
If your data is not contiguous then pick a reasonable size FFT, N, and then when you get < N samples you can pad the input with zeroes. When you get > N samples you can discard the extra samples.
In all cases of course you must apply a suitable window function prior to the FFT.