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

DFT example

  1. Aug 26, 2013 #1
    ok this is the best example i could find of DFT

    example 1)
    this is what I am trying to do...
    however it did not work for the guy...

    f[1] should be the only one with an value
    but it was a j0.5 and he got that for ever N-3..

    DFT should only return the frequency of the signal right???
    so it should only return 1...
    so why did it not work?
    is he doing someone wrong in Example one ?
  2. jcsd
  3. Aug 27, 2013 #2


    User Avatar
    Gold Member

    The spectrum repeats (aliases) about the sample rate. The basic DFT is from -2 to +2 and has a value in the +1 and -1 bins. If you only look at the -2,-1,0,+1,+2 bins you see what you'd expect.

    His first example was pretty clean.
  4. Aug 27, 2013 #3
    ok I get what you are saying however I do not understand the " You wee what you'd expect" .

    Wiki " In mathematics, the discrete Fourier transform (DFT) converts a finite list of equally spaced samples of a function into the list of coefficients of a finite combination of complex sinusoids, ordered by their frequencies, that has those same sample values. It can be said to convert the sampled function from its original domain (often time or position along a line) to the frequency domain."

    so I would expect to see f[1] having a coefficients with a right number and the other to be 0.

    ok I am very new to this. so what am I missing ?

    also he has f[r] = 1/N Ʃ x(k) e^((-j2πfK)/n) for example 1 but for example 2 he does not have the 1/N.. when do you need the 1/N part?
  5. Aug 27, 2013 #4


    User Avatar
    Gold Member

    The 1/N part is always confusing. You sometimes need to normalize. I can't easily explain it. Remember how you got 16 on a 16 sample sine wave? The 1/N would have made it 1. Some derivations use 1/sqrtN on both DFT and IDFT, some use 1/N on DFT, maybe some do 1/N on IDFT. A DSP expert could explain it better. It is just a scaling factor.

    This example has both positive and negative frequency, so there is energy in both the +1 and -1 bins. (it reflects around 0)

    I really reccommend watching some lectures on DSP that address the fundamentals of discrete signals.
  6. Aug 28, 2013 #5
    what happened if you add two signals with the same frequency together ?
  7. Sep 3, 2013 #6
    If you add two signals with same frequency f1 ,Y[t]=A1*sin(2*pi*f1*t)+A2*sin(2*pi*f1*t) then when you compute the DFT, you get the max of the spectrum as the sum of theirs amplitudes A1+A2 at frequency f1 such f1 in [0, Fs] .
  8. Sep 3, 2013 #7
    could you do the math and post it ?
    because I am really starting to think that the DFT does not work..
    I have see many examples online and none return the right frequency
  9. Sep 3, 2013 #8
    what software are you using, ? here is an example using Matrix Laboratory :

    plot(freq(1:end/2), abs(fy(1:end/2)))
  10. Sep 3, 2013 #9
    I am write my on code in c# and I am going it by hand

    so this is from math lab
    x[n] = {1 –1 1 –1}

    >> x = [1 -1 1 -1];
    >> X = fft(x)
    X =
    0 0 4 0

    4 0 0 0

    but that is Wrong!!!
    Math lab is wrong!!

    I did it by hand I got this
    i used
    F[r] = Ʃ F[K]ε ^(-j 2πKr)/N
    F[0] = 1 -1 +1 -1 = 0
    F[1] = 1 + j +1 - J = 2
    F[2] = 1 -1 -1 -1 = -2
    f[3] = 1 +j +1 - j = 2
    I do not understand
    what is wrong with math lab ???

    what it math lab doing ?
  11. Sep 3, 2013 #10
    I do not have Matrix Laboratory
    can you do it by hand and post it that way?
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook