As far as I have read, an FFT requires that the number of original data points must be a power of 2.

I'm wondering whether the tools like MATLAB or Python which have FFT functions take care of this fact.

Especially in MATLAB and Python; imagine I have samples of data in a file containing 13000 samples. If I want to read this file and plot its FFT, how does the FFT functions of MATLAB or Python treat the file? Does the function truncates the samples and obtain the number of samples as $2^n$ before performing the algorithm? Or should I sample it myself as $2^n$ samples at the beginning?


Matlab doesn’t require the number of samples to be a power of 2. You can read more about it in Matlab FFT help page.
It will handle any length of signal and will not truncate or pad the length unless you specifically say so.
BTW in the help page it says that Matlab FFT is based on FFTW. In the FFTW documentation it says:

FFTW is best at handling sizes of the form 2^a 3^b 5^c 7^d 11^e 13^f, where e+f is either 0 or 1, and the other exponents are arbitrary. Other sizes are computed by means of a slow, general-purpose algorithm (which nevertheless retains O(n log n) performance even for prime sizes).


Python doesn't have an FFT, but it's provided by external libraries like NumPy, SciPy, pyFFTW, etc.

None of these three libraries care what size the input is. It can process lengths that are power of 2, prime, etc. But prime lengths will take much longer to calculate than composite lengths, so users often choose efficient sizes, or zero-pad up to them, if the calculation allows it.

So length 997 (prime) will be slow, but length 1000 (2*2*2*5*5*5) will be fast.


Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.