Fast Fourier Transform (FFT) written in VB

Back in 2001, when I began working on DXVUMeter (an ActiveX control used to display audio in various formats) I wanted to implement the ability to display the monitored audio in the frequency domain, that is, be able to apply a Fast Fourier Transform over the sampled audio and display it.

[Again], I found a C and VB version of an FFT implementation done by no other than Murphy McCauley and if you look hard enough you can still find web sites hosting his original version.

The initial implementation of McCauley’s code worked well and did its job. Actually, DXVUMeterNETGDI, the latest version of this control, still uses a very similar version to do all its internal FFT calculations.

So what’s different in my (new) FFT implementation? Most importantly, the use of a new data type which allows all related FFT calculations to utilize complex numbers.
Also, my FFT module includes several additional functions such as:

So, if you are interested in using or simply peeking at this code, you can download the library from this link:
VB.NET FFT Library 3.2 [5.93 kB]

If you have no idea what I’m talking about or what this code does, I recommend you read this article: http://www.relisoft.com/science/Physics/sound.html

  • James Patla

    Hey, Thanks for the library… I look forward to using it, but have a couple of questions having already looked at the code. A little bit about the project I’m creating… basically I’m trying to perform a FFT on a bio signal I’ve extracted from a neurophysiology program. I’ve broken the signal down into the components required to perform the FFT on it… X(1024) which is time, in this case 1-1024ms and Y(1024) Amplitude of the wave in uV.

    My questions are
    1. What do you think is the best function to use in the library given the above?
    2. In the Complex Double array format, how do you parse through the results?

    I hope I’m not way off… but if I am, i’d appreciate your advice.

    THanks,
    James

    • Hello James,

      I’d suggest you always use the main method: “FourierTransform”.

      Other methods were implemented just to see if I could find some ways of improving (in terms of accuracy and performance) the main algorithm.
      So far, I haven’t found any advantages in using any of the other implemented algorithms.

      As for the ComplexDouble class:
      You should try to do all your computation using this type of number, to facilitate the use of the FFT function.

      So, when building your input data array, make sure you define it as an array of ComplexDouble and just supply the real part (since audio/data waveforms only have real parts).
      Then, when retrieving the results, use the preferred method for your solution to obtain the resulting FFT:

      (these are all functions available in the ComplexDouble class)

      – Abs() or Magnitude()
      – Power()
      – Power2()

      When calculating the FFT for an audio signal, it is most common to use Power(), which is defined as Real^2 + Imaginary^2.

      So, basically, you’ll run a loop cycle from 0 up to half the size of the array returned by the FourierTransform method and obtain your “Y” value from the Power() of each element.

      You may also want to consider applying a window to your values, which you can do by calling the ApplyWindow() function.

      Other things you may want to also consider, depending on your application of course, is to normalize the resulting “Y” values and apply an averaging function (to stabilize the resulting FFT).

      Although it’s not open source, I’d recommend you take a look at DXVUMeterNET: http://software.xfx.net/netcl/dxvunet/

      This is a control I developed, quite some time ago, and primarily used to display audio data in various formats. One of the formats if FFT; check the FFT Config window to see all the available options you can apply to your amplitude (Y) values, once obtained from the resulting ComplexDouble array.

  • Pingback: Music Identification (Fingerprinting) - When I'm Bored()

  • Pingback: SoftScope: A software based Oscilloscope / Vectorscope - When I'm Bored()