# fft result with the number of integer multiples of fs

With the cosine signal fc=3Hz and the fs=13Hz as below,

fc=3;
fs=13;
Ts=1/fs;

N=101*13; % 101 times of fs
n=0:N-1;
x=cos(2*pi*fc*n*Ts);


and then fft with the number nfft=N

nfft=N;
Xk=fft(x,nfft);
Pxx=(abs(Xk)/nfft).^2;
f=(0:nfft-1)*fs/nfft;

plot(f,10*log10(Pxx))


and I got the result as below figure

and then I tried with different number N=1200 I got different shape of fft result as shown below figure

After several fft trials with different numbers, I found that only when N is an integer number of multiples of fs, I get the same result as the first picture. I wonder why this phenomenon is happening.

• This is probably the single most asked question on this forum. Search for "spectral leakage". Jun 6, 2021 at 13:02
• The FFT can be compared to samples of the DTFT of your signal multiplied by a window with length N, which results a convolution in the frequency domain between your signal and a sinc function, taking different N means sampling that spectrum at different points. By taking N as integer number of multiple of fs, you sample the spectrum at the exact points the sinc zeros. Jun 7, 2021 at 5:55