快速傅里叶变换 (FFT) 在 C# 中的实现

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/170394/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 16:32:55  来源:igfitidea点击:

An implementation of the fast Fourier transform (FFT) in C#

c#signal-processingfft

提问by AnnaR

Where can I find a free, very quick, and reliable implementation of FFT in C#?

在哪里可以找到免费、快速且可靠的 C# FFT 实现?

That can be used in a product? Or are there any restrictions?

那可以用在产品上吗?或者有什么限制吗?

采纳答案by torial

AForge.netis a free (open-source) library with Fast Fourier Transform support. (See Sources/Imaging/ComplexImage.csfor usage, Sources/Math/FourierTransform.csfor implemenation)

AForge.net是一个免费(开源)库,支持快速傅立叶变换。(使用方法见 Sources/Imaging/ ComplexImage.cs,实现方法见 Sources/Math/ FourierTransform.cs

回答by pookleblinky

http://www.exocortex.org/dsp/is an open-source C# mathematics library with FFT algorithms.

http://www.exocortex.org/dsp/是一个带有 FFT 算法的开源 C# 数学库。

回答by Jacob

Math.NET's Iridium libraryprovides a fast, regularly updated collection of math-related functions, including the FFT. It's licensed under the LGPL so you are free to use it in commercial products.

Math.NET 的Iridium 库提供了一个快速、定期更新的数学相关函数集合,包括 FFT。它在 LGPL 下获得许可,因此您可以在商业产品中自由使用它。

回答by Jacob

The guy that did AForge did a fairly good job but it's not commercial quality. It's great to learn from but you can tell he was learning too so he has some pretty serious mistakes like assuming the size of an image instead of using the correct bits per pixel.

做 AForge 的人做得相当不错,但不是商业质量。学习很好,但你可以看出他也在学习,所以他有一些非常严重的错误,比如假设图像的大小而不是使用正确的每像素位数。

I'm not knocking the guy, I respect the heck out of him for learning all that and show us how to do it. I think he's a Ph.D now or at least he's about to be so he's really smart it's just not a commercially usable library.

我不是在敲这个人,我尊重他学习所有这些并向我们展示如何做到这一点。我认为他现在是一名博士,或者至少他即将成为一名博士,所以他真的很聪明,只是不是一个商业上可用的图书馆。

The Math.Net library has its own weirdness when working with Fourier transforms and complex images/numbers. Like, if I'm not mistaken, it outputs the Fourier transform in human viewable format which is nice for humans if you want to look at a picture of the transform but it's not so good when you are expecting the data to be in a certain format (the normal format). I could be mistaken about that but I just remember there was some weirdness so I actually went to the original code they used for the Fourier stuff and it worked much better. (ExocortexDSP v1.2 http://www.exocortex.org/dsp/)

Math.Net 库在处理傅立叶变换和复杂图像/数字时有其自身的怪异之处。就像,如果我没记错的话,它会以人类可见的格式输出傅立叶变换,如果您想查看变换的图片,这对人类来说很好,但是当您希望数据处于某个特定的格式时就不太好了格式(正常格式)。我可能会弄错,但我只记得有一些奇怪的地方,所以我实际上去了他们用于傅立叶东西的原始代码,它工作得更好。(ExocortexDSP v1.2 http://www.exocortex.org/dsp/

Math.net also had some other funkyness I didn't like when dealing with the data from the FFT, I can't remember what it was I just know it was much easier to get what I wanted out of the ExoCortex DSP library. I'm not a mathematician or engineer though; to those guys it might make perfect sense.

Math.net 在处理来自 FFT 的数据时也有一些我不喜欢的时髦,我不记得是什么我只知道从 ExoCortex DSP 库中获得我想要的东西要容易得多。不过,我不是数学家或工程师;对那些人来说,这可能是完全合理的。

So! I use the FFT code yanked from ExoCortex, which Math.Net is based on, without anything else and it works great.

所以!我使用从 ExoCortex 提取的 FFT 代码,它是 Math.Net 的基础,没有其他任何东西,而且效果很好。

And finally, I know it's not C#, but I've started looking at using FFTW (http://www.fftw.org/). And this guy already made a C# wrapper so I was going to check it out but haven't actually used it yet. (http://www.sdss.jhu.edu/~tamas/bytes/fftwcsharp.html)

最后,我知道它不是 C#,但我已经开始考虑使用 FFTW ( http://www.fftw.org/)。这个家伙已经做了一个 C# 包装器,所以我打算检查一下,但还没有真正使用它。( http://www.sdss.jhu.edu/~tamas/bytes/fftwcsharp.html)

OH! I don't know if you are doing this for school or work but either way there is a GREAT free lecture series given by a Stanford professor on iTunes University.

哦!我不知道你是为了学校还是工作这样做,但无论哪种方式,iTunes 大学的斯坦福大学教授都会提供一个很棒的免费讲座系列。

https://podcasts.apple.com/us/podcast/the-fourier-transforms-and-its-applications/id384232849

https://podcasts.apple.com/us/podcast/the-fourier-transforms-and-its-applications/id384232849

回答by Paul

For a multi-threaded implementation tuned for Intel processors I'd check out Intel's MKL library. It's not free, but it's afforable (less than $100) and blazing fast - but you'd need to call it's C dll's via P/Invokes. The Exocortex project stopped development 6 years ago, so I'd be careful using it if this is an important project.

对于针对英特尔处理器调整的多线程实现,我会查看英特尔的 MKL 库。它不是免费的,但它很实惠(不到 100 美元)并且速度很快——但是你需要通过 P/Invokes 调用它的 C dll。Exocortex 项目在 6 年前停止开发,所以如果这是一个重要项目,我会小心使用它。

回答by Hugh

Here's another; a C# port of the Ooura FFT. It's reasonably fast. The package also includes overlap/add convolution and some other DSP stuff, under the MIT license.

这是另一个; Ooura FFT 的 C# 端口。它相当快。该软件包还包括重叠/添加卷积和一些其他 DSP 内容,在 MIT 许可下。

https://github.com/hughpyle/inguz-DSPUtil/blob/master/Fourier.cs

https://github.com/hughpyle/inguz-DSPUtil/blob/master/Fourier.cs

回答by Gerry Beauregard

I see this is an old thread, but for what it's worth, I have a free (MIT License) 1-D power-of-2-length-only C# FFT implementation here: http://gerrybeauregard.wordpress.com/2011/04/01/an-fft-in-c/

我看到这是一个旧线程,但对于它的价值,我有一个免费的(MIT 许可证)1-D power-of-2-length-only C# FFT 实现:http: //gerrybeauregard.wordpress.com/2011 /04/01/an-fft-in-c/

I haven't compared its performance to other C# FFT implementations. I wrote it mainly to compare the performance of Flash/ActionScript and Silverlight/C#. The latter is much faster, at least for number crunching.

我没有将它的性能与其他 C# FFT 实现进行比较。我写它主要是为了比较 Flash/ActionScript 和 Silverlight/C# 的性能。后者要快得多,至少对于数字运算而言。

回答by Curt

The Numerical Recipes website (http://www.nr.com/) has an FFT if you don't mind typing it in. I am working on a project converting a Labview program to C# 2008, .NET 3.5 to acquire data and then look at the frequency spectrum. Unfortunately the Math.Net uses the latest .NET framework, so I couldn't use that FFT. I tried the Exocortex one - it worked but the results to match the Labview results and I don't know enough FFT theory to know what is causing the problem. So I tried the FFT on the numerical recipes website and it worked! I was also able to program the Labview low sidelobe window (and had to introduce a scaling factor).

Numerical Recipes 网站 (http://www.nr.com/) 有一个 FFT,如果你不介意输入它。我正在做一个项目,将 Labview 程序转换为 C# 2008、.NET 3.5 以获取数据和然后看频谱。不幸的是 Math.Net 使用最新的 .NET 框架,所以我不能使用那个 FFT。我尝试了 Exocortex 一个 - 它有效,但结果与 Labview 结果相匹配,我不知道足够的 FFT 理论来知道是什么导致了问题。所以我在数字食谱网站上尝试了 FFT,它奏效了!我还能够对 Labview 低旁瓣窗口进行编程(并且必须引入缩放因子)。

You can read the chapter of the Numerical Recipes book as a guest on thier site, but the book is so useful that I highly recomend purchasing it. Even if you do end up using the Math.NET FFT.

您可以在他们的网站上以访客身份阅读 Numerical Recipes 一书的章节,但这本书非常有用,我强烈建议您购买。即使您最终使用了 Math.NET FFT。

回答by Steve Hageman

An old question but it still shows up in Google results...

一个老问题,但它仍然出现在谷歌结果中......

A very un-restrictive MIT Licensed C# / .NET library can be found at,

可以在以下位置找到一个非常不受限制的 MIT 许可 C#/.NET 库,

https://www.codeproject.com/articles/1107480/dsplib-fft-dft-fourier-transform-library-for-net

https://www.codeproject.com/articles/1107480/dsplib-fft-dft-fourier-transform-library-for-net

This library is fast as it parallel threads on multiple cores and is very complete and ready to use.

这个库速度很快,因为它可以在多个内核上并行线程,并且非常完整且随时可用。