1

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')
SAIP
  • 99
  • 7
  • You need to apply a window function prior to the FFT. – Paul R May 01 '18 at 13:54
  • Hi, Thank you for this. I want to ask something else as well you have previously answered to this question but as I am new so I can not add a comment there. Therefore I am asking here, https://stackoverflow.com/questions/8824021/how-to-find-the-frequency-from-fft-data-in-matlab I wanted to know that in this case there is no need to specify sampling frequency am I right? please correct me and sorry for asking very randomly. – SAIP May 01 '18 at 15:09
  • Sampling frequency is only really relevant when you want to convert the FFT bin index to a physical frequency. The FFT itself does not know or care about sample rate - you can just think of the frequency axis as being normalised to the range 0..Fs/2. See [this question](https://stackoverflow.com/a/4371627/253056). – Paul R May 01 '18 at 15:14
  • I have the same case like that question I mentioned I have x and y coordinates of some objects array is 2 by 2000. I want to convert FFT bins to physical Frequency but there is no clue of sampling frequency. What can we do in this case any idea please? – SAIP May 01 '18 at 15:20
  • It's not very clear what you are trying to achieve, but the FFT only works for uniformly sampled data. – Paul R May 01 '18 at 15:49
  • I want to achieve nothing complex but to know what is the frequency of the object, and all I have is their x y coordinates. – SAIP May 01 '18 at 15:58
  • If the objects are just arbitrary locations then you will probably need to define a uniform sampling grid with sufficient resolution and convert those locations to samples. In other words you would be creating a sampled image of your objects. Then you can just use a 2D FFT to get spatial frequency domain data. – Paul R May 01 '18 at 16:00
  • Are you referring something related to resample function? and yes the objects are just arbitrary locations. Secondly can you give me any related link for this kind of problem if there is any? or if you can just write something pseudo it would be very nice of you. Thanks – SAIP May 01 '18 at 16:06

0 Answers0