+ Reply to Thread
Results 1 to 8 of 8

Fast Fourier Transform (FFT) in VBA

  1. #1
    Registered User
    Join Date
    10-03-2012
    Location
    St. Louis, Missouri
    MS-Off Ver
    MS 2013, 64Bit, 8 Cores, 20GB
    Posts
    18

    Fast Fourier Transform (FFT) in VBA

    Can someone post the VBA code for the Fast Fourier Transform (FFT).
    I need to rewrite it to do datasets larger than 4096 (Excel FFT is limited).
    Looking for the same complex outputs that the built-in function provides.

    Thanks in advance
    Last edited by gth826a; 09-18-2017 at 11:09 AM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,656

    Re: FFT in VBA

    Want to get your question answered quickly?
    • Ensure your question is not too vague. Don't assume anyone is familiar with your problem. While you can upload small attachments, describe your problem in the body of the post. We are fortunate to have several Excel gurus, but few mind-readers.
    • On the other hand, skip irrelevant details. Be descriptive and concise. Short, direct, and to-the-point questions with apt thread titles are almost always answered promptly.
    • Keep the scope reasonably narrow. Questions like, "How do I set up an accounting system in Excel?" might be a long time waiting.
    • Explain what you've already tried. ("Calculation is set to automatic, but formulas still don't compute") so helpers don't waste your time or theirs.
    • Post a WORKBOOK. Nobody wants to type data from a picture or paste text from your post into a spreadsheet as a prelude to helping. To attach a file, push the button with the paperclip (or scroll down to the Manage Attachments button), browse to the required file, and then push the Upload button.
    • If your question has not been answered within a day, consider adding another post with any additional information you believe is relevant. If you think your post is good as is, just reply to your own thread with the words "Bump no response", which will bring it to the top of the forum.
    Ben Van Johnson

  3. #3
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Fast Fourier Transform (FFT) iin VBA

    Google gave me this

    https://stackoverflow.com/questions/...ing-excels-vba

    i didn't look at the detail - but he seems to be asking for the same reason and have found a solution that he was happy with at the bottom.
    If you want something done right... find a forum and ask an online expert.

    Time flies like an arrow. Fruit flies like a banana.

  4. #4
    Registered User
    Join Date
    10-03-2012
    Location
    St. Louis, Missouri
    MS-Off Ver
    MS 2013, 64Bit, 8 Cores, 20GB
    Posts
    18

    Re: Fast Fourier Transform (FFT) iin VBA

    Quote Originally Posted by scottiex View Post
    Google gave me this

    https://stackoverflow.com/questions/...ing-excels-vba

    i didn't look at the detail - but he seems to be asking for the same reason and have found a solution that he was happy with at the bottom.

    The above link from the Google search shows coding that uses WorkSheetFunctions (.Complex, .ImSum, .ImProduct, etc.)...
    I'm looking for some version of raw code where every calculation is done within the same macro/script.
    Or, I would settle for some code/psuedo code that walks me through the "real" & "imaginary" calculations as computed by Excel.
    I have created the following code:

    Please Login or Register  to view this content.
    Where FnCmplx is a 2D array of size (N-1,1) ... since the indexing starts at 0, and the array base is 0
    i.e. for frequency kk=0, FnCmplx(0,0) = real number and FnCmplx(0,1) = imaginary number

    However, when testing the script on a 4096 point data range - I have been unable to replicated the values that Excel produces.

    I realize that my code above is not the FFT version of O(Nlog(N)) computations, but is instead the DFT expanded O(N^2) computations version...
    But, the outputs should still be the same, correct??
    Last edited by gth826a; 09-18-2017 at 10:26 AM.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Fast Fourier Transform (FFT) iin VBA

    If you are amenable to a formula-based solution, see attached. I expect it will get painfully slow with that many points.
    Attached Files Attached Files
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Registered User
    Join Date
    10-03-2012
    Location
    St. Louis, Missouri
    MS-Off Ver
    MS 2013, 64Bit, 8 Cores, 20GB
    Posts
    18

    Fourier Transform (DFT) in VBA [SOLVED]

    I have yet to look at the file shg provided, but I was able to find the solution (below) using the slower DFT variation.
    I was incorrect to multiply the summations by (1/N), and [although I didn't computer how big of a difference it made overall] VBA was miscalculating the Cos(2*pi*k*n/N) in some instances by .0000132262629816138 for integer-values of Pi.
    The miscalculation was rectified by using the Round() function, and the comparison to Excel outputs was done using an N=4096 dataset.


    Please Login or Register  to view this content.
    As shg alluded to, the computation [on a Surface Pro3] takes several seconds at N=4096.
    However, since my data sampling is logged on an interval of every 15 seconds - the calculation time for the DFT method is acceptable.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Fourier Transform (DFT) in VBA [SOLVED]

    Quote Originally Posted by gth826a View Post
    VBA was miscalculating the Cos(2*pi*k*n/N) in some instances by .0000132262629816138 for integer-values of Pi.
    Maybe you should use a more accurate representation of pi than

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-03-2012
    Location
    St. Louis, Missouri
    MS-Off Ver
    MS 2013, 64Bit, 8 Cores, 20GB
    Posts
    18

    Re: Fourier Transform (DFT) in VBA [SOLVED]

    Touche, Sir! Touche.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Passing a variable range into fourier transform
    By waciavarra in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-14-2015, 02:29 PM
  2. "Reference is not Valid" when calling fast fourier transform
    By JacksonRJones in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-08-2006, 09:10 AM
  3. [SOLVED] referring to worksheets by name in a vba fourier transform
    By JacksonRJones in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-03-2006, 03:40 PM
  4. Fast Fourier Transform routine in Tools add-in menu
    By Tutorguy in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-23-2006, 12:55 PM
  5. [SOLVED] Fourier Analysis
    By Gary's Student in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 09-06-2005, 05:05 PM
  6. Fourier Analysis
    By jordon in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 07:05 AM
  7. [SOLVED] Fast Fourier Transform
    By Ad Pronk in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-12-2005, 07:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1