FFT magnitude

Discussion in 'Math' started by jut, Jun 29, 2011.

  1. jut

    Thread Starter Senior Member

    Aug 25, 2007
    224
    2
    I wrote some code in Matlab to do a simple FFT on a sine wave. How does one interpret the amplitude?

    [​IMG]

    Code ( (Unknown Language)):
    1. % FFT
    2. fs=10     % sampling frequency
    3. x=sin(2*pi*[0:1/fs:10]);      % frequency of signal is 1Hz
    4. N=131072
    5. X = abs(fft(x,N));
    6. F = fs*[0:N-1]/N;
    7. figure
    8. plot(F,X)
    9. xlabel('Hz')
    10. ylabel('I never remember what the magnitude in a FFT means...ehh')
    11. legend(sprintf('sampling frequency = %d Hz',fs))
    12. axis([0 fs/2 0 max(X)*1.1])
     
  2. kevinarms

    New Member

    Jun 29, 2011
    6
    2
    The FFT is a way of breaking down a signal into its frequency components. So if you created individual sinusoidal waves of each frequency present in the FFT, and each had an amplitude and phase shift given by the FFT for that frequency, then you could sum them up to get your original signal (which is basically what a fourier series is).

    Basically, the magnitude of the FFT is the amplitude of the associated frequency component.

    When you're using the FFT function in MATLAB you probably also want to use the fftshift function to center the results around 0.

    Hope that helps.
     
  3. MrChips

    Moderator

    Oct 2, 2009
    12,414
    3,353
    Here are some points to note:

    In your example, your input is not a sine wave. Because N = 131072 is larger than the number of points in x, this is a windowed sine.

    Your magnitude is 50 because you are forgetting to normalise the result of the FFT, i.e. you should divide by N. For a full sinewave your amplitue would be 0.5

    Why 0.5?

    Because you are plotting only one half of the spectrum. Don't forget the negative frequencies!
     
    Last edited: Jun 29, 2011
  4. jut

    Thread Starter Senior Member

    Aug 25, 2007
    224
    2
    If I divide 50 by 131072, that would be tiny! 0.0003814! My input sine wave has a magnitude of 1.
     
  5. MrChips

    Moderator

    Oct 2, 2009
    12,414
    3,353
    But 50 divided by 100 is 0.5
    The explanation is contained in my previous post.
     
  6. davebee

    Well-Known Member

    Oct 22, 2008
    539
    46
    The Fourier transform (and the fft) break a signal down into phase as well as frequency.

    The term magnitude usually means the square root of the sum of the squares of both the sine (real) part and the cosine (imaginary) parts.

    This will be equivalent to the amplitude of the sine part if the imaginary part is zero, but it would not really be correct to consider just the sine part of a signal to be the magnitude.
     
  7. Barnaby Walters

    Member

    Mar 2, 2011
    103
    4
    I have never understood how a FFT shows phase (all I have ever used them for is tuning a circuit to a particular frequency) — could someone explain please?

    Also, am I right in thinking that the FFT of a 'pure' sine wave would only have one peak, i.e. no harmonics?

    Thanks,
    Barnaby
     
  8. MrChips

    Moderator

    Oct 2, 2009
    12,414
    3,353
    Please do not hijack someone else's post. Your question is a new topic.
    For now I will oblige and answer your questions.

    The FFT converts the time signal into its frequency components (in our context, but note that the FFT can be used for many other applications other than electrical signals).

    The results of the FFT will contain two components, the sine component and the cosine component. Another way of looking at this is it is a complex number consisting of a real component and an imaginary component such as x + iy. (Electrical Engineers use x +jy).

    The ratio of the two components (y/x) gives you the phase angle of that sine wave, i.e. tan(phase angle) = y/x.

    Hope this helps.

    Yes, a 'pure' sinewave would have one peak.

    (Sorry, I just noticed that other posters brought up the point about "phase".
    If you wish to continue discussing the Original Post I would be happy to respond.)
     
    Last edited: Jul 2, 2011
  9. Barnaby Walters

    Member

    Mar 2, 2011
    103
    4
    Yep, sorry about that. If others hadn't mentioned phase shift I would not have known that FFTs showed it.

    Thanks,
    Barnaby
     
Loading...