MATLAB: Does length of signal matter in computing amplitude spectrum using fft

fft

I am looking into the fft document. In the first example – noisy signal, if I change the length of the signal into L = 1520, I cannot get the correct amplitude-spectrum plot as in the third figure. The amplitude of the two components is a little less than what they are expected (0.7 and 1).
I tried several lengths of the signal. Only when L is a multiple of 100 can give the correct amplitude spectrum. I am wondering why.
Thanks,
Jiaqi

Best Answer

A bit more information would be nice, so guessing here.
The effect you are seeing is most likely the effect of doing a discrete Fourier transform with floating-point arithemtic. There is probably frequency ‘leakage’ in your fft results when the length is not a multiple of 100. You can most easily see this if you look closely at the area near zero amplitude for each peak. The peaks will look much more dispersed with some values of ‘L’ as compared to others. All the energy is still in the fft results. It is simply not as ‘concentrated’ at the peak frequencies for all values of ‘L’.