Click here to Skip to main content
14,700,043 members
Articles » Platforms, Frameworks & Libraries » .NET Framework » General
Posted 14 May 2016

Tagged as


18 bookmarked

Comparison of FFT Implementations for .NET

Rate me:
Please Sign up or sign in to vote.
4.95/5 (19 votes)
13 Jun 2016CPOL
Comparison and benchmark of Fast Fourier Transform implementations for the .NET platform


In this short article, we will compare a couple of Fast Fourier Transform (FFT) implementations for the .NET platform. The contestants are:

  Accord AForge DSPLib Exocortex Math.NET NAudio Lomont FFTW
Version: 3.8.0 - 1.03.1 1.2 4.5.1 1.8.4 1.1 3.3.5
Assemblies: 3 - - 1 1 1 - 1+1
Size: 3.6 MB - - - 1.5 MB 0.5 MB - 2.3 MB
Nuget: yes yes no no yes yes no no


  • Accord.NET is an extension to AForge.NET and the original AForge code is part of the Accord assembly, so the AForge assemblies weren't tested separately.
  • The Exocortex project was created in the early .NET 1.0 days. The copy provided with this article was updated to target .NET 4.6.2 and to use the Complex type of the System.Numerics namespace.
  • NAudio uses a custom Complex type implementation with single precision real and imaginary part.
  • FFTW is a popular, native FFT implementation. It is probably the fastest open source implementation one can find on the internet, so comparison with the managed code is a bit unfair. Still, I thought it might be interesting to see how the code competes.

The FFTW binaries are not distributed with this article. If you want FFTW to be included in the benchmark, go to and copy libfftw3-3.dll and libfftw3f-3.dll to the application directory.


I was particularly interested in 1D FFTs for real valued input (audio processing). The following interface is used for all tests. If you have your own FFT implementation, it should be easy to incorporate it into the benchmark by implementing this interface and instantiate the test in the Util.LoadTests() method.

interface ITest
    bool Enabled {get; set; }

    /// <summary>
    /// Prepare the real valued data for FFT processing.
    /// </summary>
    /// <param name="data">The samples array.</param>
    void Initialize(double[] data);

    /// <summary>
    /// Apply FFT to data.
    /// </summary>
    /// <param name="forward">If false, apply inverse FFT.</param>
    void FFT(bool forward);

    // Ignore for benchmark (used only for 'FFT Explorer', see next section)
    double[] Spectrum(double[] input, bool scale);

Take a look at the different tests in the FFTBench.Benchmark namespace to see how to implement the interface properly.

Exocortex, Lomont and FFTW have specialised implementations for real valued data and the code can be expected to be about twice as fast as the standard complex implementation.

Accord.NET, Math.NET and FFTW support input arrays of any size (i.e., the size doesn't have to be a power of 2). Since AForge, Exocortex, NAudio and Lomont support radix 2 only, the benchmark uses arrays with sizes that are a power of 2.

The following table shows the total execution time (and the average) in milliseconds for FFTs of increasing size:

FFT size 1024 2048 4096 8192
Accord       332     0.03       658     0.07       1522     0.15       2947     0.29
AForge 335 0.03 731 0.07 1572 0.16 4065 0.41
Math.NET 390 0.04 773 0.08 1474 0.15 3461 0.35
NAudio 135 0.01 296 0.03 646 0.06 1435 0.14
DSPLib 151 0.02 341 0.03 726 0.07 1853 0.19
Exocortex 185 0.02 409 0.04 920 0.09 2743 0.27
Lomont 126 0.01 274 0.03 614 0.06 2465 0.25
Exocortex (real) 79 0.01 171 0.02 370 0.04 788 0.08
Lomont (real) 76 0.01 163 0.02 355 0.04 777 0.08
FFTW 29 - 65 0.01 163 0.02 662 0.07
FFTW (real) 16 - 35 - 81 0.01 221 0.02
FFTWF (real) 11 - 23 - 55 0.01 120 0.01

In the above table, each FFT is actually called 10000 times (the repeat value from the user interface was chosen as 200, and it is multiplied by 50 inner iterations). The benchmark was run on an AMD Phenom II X2 550 processor (3.1 GHz).

The next chart shows the benchmark result for the different FFTs of size 2048, 4096 and 8192:

Image 1

Interpreting FFT Results

The benchmark application contains a util called FFT Explorer. You can open it by clicking on the leftmost icon of the benchmark window.

The FFT Explorer lets you select the FFT implementation, an input signal and the FFT size. Three graphs will display the input signal, the spectrum computed by the selected FFT and the signal computed by the inverse FFT.

Let's have a look at an example signal of the SignalGenerator class. The generated signal is a simple sine wave with frequency 1.0 Hz and amplitude 20.0:

public static double[] Sine(int n)
    const int FS = 64; // sampling rate

    return MathNet.Numerics.Generate.Sinusoidal(n, FS, 1.0, 20.0);

Let the FFT frame size be n = 256. With a sampling rate of 64 Hz, our periodic signal will be repeated exactly four times over the selected window. Be aware that all values are chosen to have an exact match between signal period, sampling rate and FFT size. This way, we won't have to deal with spectral leakage.

Each bin of the FFT output is spaced by the frequency resolution (sampling rate) / (FFT size), which in our case is 64 / 256 = 0.25. So we expect a peek corresponding to our 1.0 Hz signal to be in bin number 4 (since 1.0 = 4 * 0.25).

Image 2

Due to the nature of the DFT, the spectrum of the signal will get scaled by n = 256, so if no further scaling is done, we expect the value to be 20.0 * 256 / 2 = 2560. We divide by 2, since the amplitude is distributed across two bins. The second bin is located at index 256 - 4 = 252 and will have the same magnitude, because, for real valued input signals, the FFT output is (conjugate) symmetric (across n/2, the bin corresponding to the Nyquist frequency).

The actual values of the peek won't be consistent between FFT implementations, since there's no common scaling convention. If the FFT size is n, then some implementations scale the FFT by 1/n, some scale the inverse FFT by 1/n and some scale both by 1/sqrt(n). Some don't scale at all (like FFTW).

The following table shows the amplitudes computed by the different FFTs for the above example:

  Accord.NET AForge.NET Exocortex.DSP Math.NET Numerics NAudio Lomont FFTW
Value: 2560 10 2560 160 10 160 2560

You can see that AForge.NET and NAudio scale by 1/n and that Math.NET and Lomont scale by 1/sqrt(n) (both Math.NET and Lomont allow the user to change scaling conventions; the values computed above and used in the benchmark represent the default settings).


Obviously and not completely unexpected, FFTW is the clear winner. So, if using a native DLL is an option for you, go for it. Looking at the managed code, both Exocortex and Lomont seem to be a good choice. For complex valued data, Lomont is slightly faster. For real valued signals, both perform the same. NAudio also performs pretty well, but uses a custom Complex type and does not support real valued input.


  • 2016-05-15 - Initial version
  • 2016-06-14 - Add information requested in the comments
  • 2018-09-02 - Update libraries, include DSPLib and fix benchmark (thanks to I'm Chris, see comments)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Studied math and computer science at the university of Dortmund.

MCTS .NET Framework 4, Windows Applications

Comments and Discussions

QuestionError Code Pin
Member 1362292326-Nov-19 14:53
MemberMember 1362292326-Nov-19 14:53 
AnswerRe: Error Code Pin
Christian Woltering26-Nov-19 23:31
MemberChristian Woltering26-Nov-19 23:31 
QuestionMy benchmarks, with some newer FFT implementations. Also, beware the NAudio FFT. Pin
bobasaurus21-Aug-19 7:29
Memberbobasaurus21-Aug-19 7:29 
AnswerRe: My benchmarks, with some newer FFT implementations. Also, beware the NAudio FFT. Pin
Christian Woltering22-Aug-19 12:51
MemberChristian Woltering22-Aug-19 12:51 
GeneralRe: My benchmarks, with some newer FFT implementations. Also, beware the NAudio FFT. Pin
bobasaurus26-Aug-19 9:42
Memberbobasaurus26-Aug-19 9:42 
QuestionSharpfftw.dll Pin
Member 1326462215-Oct-18 10:34
MemberMember 1326462215-Oct-18 10:34 
AnswerRe: Sharpfftw.dll Pin
Christian Woltering3-Nov-18 2:09
MemberChristian Woltering3-Nov-18 2:09 
SuggestionMath.NET Intel MKL builds Pin
basarugur21-Mar-18 2:00
Memberbasarugur21-Mar-18 2:00 
BugBad rounding leads to incorrect results? Pin
I'm Chris4-Mar-18 1:45
professionalI'm Chris4-Mar-18 1:45 
GeneralRe: Bad rounding leads to incorrect results? Pin
Eric Ouellet20-Mar-18 8:20
professionalEric Ouellet20-Mar-18 8:20 
Great remark. I think it is very important to do like you said (using tick) otherwise it could lead to false results. It makes results less reliable to me... D'Oh! | :doh:
GeneralRe: Bad rounding leads to incorrect results? Pin
Christian Woltering1-Sep-18 13:53
MemberChristian Woltering1-Sep-18 13:53 
QuestionIt would be helpful to expand FFT abbreviation at least once at the beginning of the article. Pin
Roman Ivantsov13-Jun-16 19:46
professionalRoman Ivantsov13-Jun-16 19:46 
QuestionNumber of repeats Pin
Gwannoes6-Jun-16 5:44
MemberGwannoes6-Jun-16 5:44 
AnswerRe: Number of repeats Pin
Christian Woltering6-Jun-16 8:05
MemberChristian Woltering6-Jun-16 8:05 
GeneralRe: Number of repeats Pin
Gwannoes6-Jun-16 21:50
MemberGwannoes6-Jun-16 21:50 
QuestionMix Radix Pin
Mark C. Malburg16-May-16 6:15
MemberMark C. Malburg16-May-16 6:15 
AnswerRe: Mix Radix Pin
Christian Woltering16-May-16 9:45
MemberChristian Woltering16-May-16 9:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.