0
$\begingroup$

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

enter image description here

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

enter image description here

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.

$\endgroup$
2
  • 2
    $\begingroup$ This is probably the single most asked question on this forum. Search for "spectral leakage". $\endgroup$
    – Hilmar
    Jun 6, 2021 at 13:02
  • $\begingroup$ 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. $\endgroup$
    – Ran Greidi
    Jun 7, 2021 at 5:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.