# Difference Between fft(signal, nfft) and fft(signal)

I want to know the difference between these following commands (matlab) and why I get two different outputs?

fft(signal);

fft(signal, nfft);


I found that the output arrays are not the same, but I don't know why! how it works with the signal of any length without padding the original signal with zeros!

• signal length is't a power of 2
• nfft is the next power of 2
• Nice question. There at least two reasons I can think of. Firstly, FFT routines are highly optimized for sequences that are power of 2. There are many other "optimal lengths" such as primes, etc, but this is generally the case. On the other hand, fft can still be calculated for sequence lengths that are not powers of two, but then calculations are not as fast, as well as truncation errors can manifest themselves.
– jojek
Apr 30, 2016 at 21:16
• Is this Matlab code? please be more clear on what exact difference you observed ? And, if your second line means taking an N-point FFT with N = "nfft" in your code, and if the signal has a different length than "nfft", then how do you compare the two FFTs of different lengths ? Apr 30, 2016 at 21:26
• A matlab code, and nFFT is the next power of 2 from the length of the original signal, for example if the original length is 60, then nFFT=64. Apr 30, 2016 at 21:32
• @KamalMoussa ok see my answer please. Apr 30, 2016 at 21:37

The two calls would result in two DFTs which are of different lengths and which ,in general, take different values. This is because they are in fact L and N samples of DTFT $X(e^{j\omega})$ of the signal x[n].
• Nice. In my second paragraph I describe why fft(x) and fft(x,N) will "be" different due to they are getting different samples from DTFT $X(e^{j\omega})$ . Now if you want to return L-point (L:signal length) DFT for an arbitrary L, you should either use more complex radix-M decompostions or you may "resample" N point FFT into L point... but I'm not sure if it works Apr 30, 2016 at 22:19