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

Dft of cos function

  1. Oct 2, 2012 #1
    i have typed some code in matlab to find the 5 point fft of cos function of frequency 100hz but in answer i am not geting the answer at 100 hz.may i know where the things going wrong. the code is as this one


    the answer is
    5 0 0 0 0

    thanks in advance
  2. jcsd
  3. Oct 2, 2012 #2


    User Avatar
    Science Advisor

    Hi amaresh92. Tell me what you know about the Nyquist sampling theorem.
  4. Oct 7, 2012 #3
    dont know why it has to be true
  5. Oct 7, 2012 #4


    User Avatar
    Science Advisor

    Ok. The problem is that your single is at 100Hz, but you are only sampling at at 4 Hz (4 samples per second). Sampling theory says that we have to sample at at-least twice the highest frequency component of the signal, so greater than 200 Hz in this case. What this means is that your "t" spacing must be less than 0.005.
    Last edited: Oct 7, 2012
  6. Oct 7, 2012 #5


    User Avatar
    Science Advisor

    Hi amaresh92, if you want a simple 5 point example then try this code and see if the results make more sense. :smile:

    Code (Text):

    n = 5                    # Specify the number of points to sample.
    fs = 500                 # Specify the sample frequency.
    dt=1/fs                  # Calculate the inter-sample interval.

    t = [0:n-1]*dt           # Create the sample vector.
    x = cos(2*pi*100*t)      # Create the signal vector.
    xm = abs(fft(x))         # Compute the fft magnitude.

    df = fs/n                # Calculate the frequency increment of the fft.
    ascale = n/2             # Amplitude scale factor.

                             # Plot fft magnetude. Note "reflection" about fs/2.
    Last edited: Oct 7, 2012
  7. Oct 10, 2012 #6
    thanks a lot
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook