Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

FFT zero padding issue

  1. May 5, 2012 #1
    Hello,
    I have a simple cosine f = 50Hz. When I generate Matlab code to produce 1/2 second of this signal and take the FFT, the response correctly shows a spike at 50 Hz. However, when I bracket the signal with 1/2 seconds of zeros on either side, the frequency response is showing a spike at 75 Hz. Does anyone know why this might occur, and how might one rectify it?

    Thanks so much!
     
  2. jcsd
  3. May 6, 2012 #2

    I like Serena

    User Avatar
    Homework Helper

    Welcome to PF, palex! :smile:

    I see 3 possibilities:

    1. It's an extra peak caused by aliasing of discretely sampled data (DFT aliasing).
      In this case the peak of 50 Hz should still be there.
      Is it?
    2. Your data is sampled at an insufficient frequency.
      To correctly sample data for an FFT the sample rate has to be at least twice as high as the frequency you are sampling (Nyquist–Shannon sampling theorem).
      What is your sampling rate? Is it the same as before?
    3. Your frequency scale has changed due to the extra sample data, and 75 Hz is actually 50 Hz (the frequency scale depends on the sampling rate and on the number of samples).
      Can you be sure that 75 Hz is actually 75 Hz?
     
  4. May 6, 2012 #3
    Thanks for the reply!
    The cosine is sampled well above the Nyquist limit.
    I think it may have to do with the frequency scale, though I don't quite see it. The Matlab code is:

    fs = 0.0001;
    t = 0:fs:0.5;
    y = cos(50*2*pi.*t);
    t = 0:fs:1.5;
    y = [zeros(1,0.5/fs), y, zeros(1,0.5/fs)];
    stem(abs(fft(y)))


    Thanks again!
     
  5. May 6, 2012 #4

    I like Serena

    User Avatar
    Homework Helper

    The highest frequency you get is your sampling rate (10 kHz).
    The lowest frequency you get corresponds to your time interval (originally 2 Hz, now 2/3 Hz).

    Originally your 50 Hz peak would be at index 25 (since 25 x 2 Hz = 50 Hz).
    Now your 50 Hz peak would be at index 75 (since 75 x 2/3 Hz = 50 Hz).

    Does this match your results?
     
  6. May 6, 2012 #5
    Yes, this is matching what I am getting. I guess my point of confusion is why these peaks are changing. The dominant frequency is 50 Hz in all three cases. Does Matlab interpret the x axis scaling in a strange way?
     
  7. May 6, 2012 #6

    I like Serena

    User Avatar
    Homework Helper

    If you put more samples in, you get a higher resolution in the frequency spectrum.
    The peak is not changing - there are more elements in the result (3 times as many).
    So the corresponding index of the 50 Hz peak increases with a factor 3.

    Matlab has nothing to do with it.
    It is how the FFT works.
    The index is not the frequency.
    You have to divide the index with the duration of the entire time interval to get the corresponding frequency.
     
  8. May 6, 2012 #7

    rbj

    User Avatar

    small potatoes but remember that MATLAB adds 1 to the index. they don't know how to count from 0 at The Math Works. so they assign the index 1 to DC with the FFT.
     
  9. May 6, 2012 #8
    Cool... thanks again for your help. It's starting to make sense realizing the initial output are indices rather than Hz.

    Regards.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: FFT zero padding issue
  1. Reverse FFT (Replies: 1)

  2. FFT question (Replies: 6)

  3. Phase of FFT (Replies: 4)

Loading...