Thread: Having issues with my FFT

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743

    Having issues with my FFT

    I coded up an FFT, and I'm having issues with it. I can't figure out what the problem is. It's not the 1st time I've coded the FFT, and I've compared my new FFT code (in C++) to a previous time I coded the FFT (in C#), and I don't personally see any mistakes in the way I've coded it (although the two implementations have some minor semantic differences).

    Here is the graph of the signal I am sending into the function:

    Attachment 9674

    Here is the graph I should get as output:

    Attachment 9672

    And here is what I really am getting as output:

    Attachment 9673

    The output off the fft looks oddly like the sync function...which shouldn't be the result for a simple sine wave...

    Here is my code:
    Code:
    std::vector < std::complex<double> > InternalFastFourierTransform (std::vector < std::complex<double> > input)
    {
        static std::complex<double> i = std::complex<double>(0, 1);
        static std::complex<double> NegativeTwoPiI = -2.0 * PI * i;
    
        int N = (int)input.size();
        int halfN = N / 2;
    
        if (N == 1)
        {
            return input;
        }
        else
        {
            //Recurse and get evens/odds
            std::vector< std::complex<double> > evens = InternalFastFourierTransform( GetVectorRange(input, 0, N, 2) );
            std::vector< std::complex<double> > odds = InternalFastFourierTransform( GetVectorRange(input, 1, N, 2) );
    
            //Combine
            std::vector< std::complex<double> > result = std::vector< std::complex<double> > (N);
            for(int k = 0; k < halfN; k++)
            {
                std::complex<double> exponent = std::exp(NegativeTwoPiI * double(k / N));
                result[k] = evens[k] + exponent * odds[k];
                result[k + halfN] = evens[k] - exponent * odds[k];
            }
    
            return result;
        }
    }
    Do you guys see anything wrong? The only thing that I could see is that possibly my function GetVectorRange which takes a slice of a vector from some starting index to some ending index at a stride of 2 could be functiong incorrectly...I haven't thoroughly tested that function...but is that really the problem, or do you think it could be some math mistake based off of the graph output?
    Last edited by DavidP; 04-05-2010 at 10:03 AM. Reason: grammatical correction
    My Website

    "Circular logic is good because it is."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I hate pointers or Pointer Issues
    By bolivartech in forum C Programming
    Replies: 9
    Last Post: 11-14-2009, 11:48 AM
  2. FFT and convolution
    By DavidP in forum General Discussions
    Replies: 7
    Last Post: 07-03-2009, 09:31 AM
  3. FFT returning values in wrong order
    By DavidP in forum C# Programming
    Replies: 3
    Last Post: 10-25-2007, 01:15 PM
  4. hexdump issues
    By daluu in forum C Programming
    Replies: 2
    Last Post: 03-04-2003, 09:01 PM
  5. FFT discussion, anyone?
    By Sebastiani in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 12-26-2002, 04:06 AM