Hello I am new to FFT and trying to understand the behaviour of FFT, I was just playing around with it and observed something which is not understandable to me. Can someone please explain the behaviour? I have taken these code examples from Matlab Central.
When I create a sine wave with 120 frequency and apply FFT I get only one peak at 120. (reference to the first figure) FFT result with frequency 120.
But when I change the frequency like 130 or 140 then there are many peaks in the FFT result. (Reference to the second figure)FFT result with frequency 140.
Can someone please explain why and how this is happening. I am using the following code for learning purpose.
clc, clearvars, close all
FS = 8000; % samples per second
dt = 1/FS; % seconds per sample
StopTime = 0.25; % seconds
t = (0:dt:StopTime-dt)'; % seconds
%% Sine wave:
Fc = 125; % hertz
x = sin(2*pi*Fc*t);
% Plot the signal versus time:
subplot(121);
plot(t,x);
xlabel('time (in seconds)');
title('Signal versus Time, frequency=125');
L=length(x);
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = (fft(x,NFFT)/L);
f = FS/2*linspace(0,1,NFFT/2+1);
% Plot single-sided amplitude spectrum.
subplot(122);stem(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum')
xlabel('Frequency (Hz)')
ylabel('Amplitude')