Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 快速傅里叶变换(FFT)的C语言实现_C#_Signal Processing_Fft - Fatal编程技术网

C# 快速傅里叶变换(FFT)的C语言实现

C# 快速傅里叶变换(FFT)的C语言实现,c#,signal-processing,fft,C#,Signal Processing,Fft,在哪里可以找到一个免费、非常快速、可靠的FFT C实现 可以在产品中使用吗?或者有什么限制吗?是一个免费的开源库,支持快速傅立叶变换。参见Sources/Imaging/了解用法,Sources/Math/了解实现是一个带有FFT算法的开源C数学库。Math.NET提供了快速、定期更新的数学相关函数集合,包括FFT。它是根据LGPL获得许可的,因此您可以在商业产品中自由使用它。制作Forge的人做得相当不错,但这不是商业品质。从中学习很好,但你可以看出他也在学习,所以他犯了一些相当严重的错误,比

在哪里可以找到一个免费、非常快速、可靠的FFT C实现


可以在产品中使用吗?或者有什么限制吗?

是一个免费的开源库,支持快速傅立叶变换。参见Sources/Imaging/了解用法,Sources/Math/了解实现

是一个带有FFT算法的开源C数学库。

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

制作Forge的人做得相当不错,但这不是商业品质。从中学习很好,但你可以看出他也在学习,所以他犯了一些相当严重的错误,比如假设图像的大小,而不是使用正确的每像素位

我不是在打那个家伙,我非常尊重他,因为他学到了所有这些,并告诉我们如何去做。我认为他现在是博士,或者至少他即将成为博士,所以他真的很聪明。这不是一个商业上可用的图书馆

当使用傅里叶变换和复杂的图像/数字时,Math.Net库有它自己的怪异之处。比如,如果我没有弄错的话,它以人类可查看的格式输出傅里叶变换,这对人类来说很好,如果你想看变换的图片,但是当你期望数据以某种格式,即正常格式时,它就不那么好了。我可能弄错了,但我只记得有一些奇怪的地方,所以我实际上去了他们用于傅里叶变换的原始代码,它工作得更好。ExocortexDSP v1.2

在处理FFT数据时,Math.net还有一些我不喜欢的有趣之处,我记不起它是什么了,我只知道从ExoCortex DSP库中得到我想要的东西要容易得多。我不是数学家或工程师;对那些家伙来说,这可能是完全有道理的

所以!我使用的FFT代码是从ExoCortex中提取出来的,Math.Net就是基于它的,没有其他任何东西,它工作得很好

最后,我知道它不是C,但我已经开始考虑使用FFTW。这家伙已经做了一个C包装,所以我打算去看看,但实际上还没有用过

哦!!我不知道你这样做是为了上学还是为了工作,但不管怎样,都有一个很棒的免费系列讲座,由一位斯坦福大学教授在iTunes大学举办


对于针对英特尔处理器的多线程实现,我会查看英特尔的MKL库。它不是免费的,但它的价格不到100美元,而且速度非常快,但您需要通过P/Invokes调用它的C dll。Exocortex项目6年前就停止了开发,所以如果这是一个重要的项目,我会小心使用它;Ooura FFT的C端口。它相当快。该软件包还包括重叠/添加卷积和一些其他DSP的东西,在麻省理工学院的许可下


我看到这是一个旧线程,但值得一提的是,这里有一个免费的MIT许可证1-D 2次方长度的C FFT实现,我在2010年写的

我还没有将其性能与其他C FFT实现进行比较。我写这篇文章主要是为了比较Flash/ActionScript和Silverlight/C的性能。后者要快得多,至少在数字运算方面是如此

/**
 * Performs an in-place complex FFT.
 *
 * Released under the MIT License
 *
 * Copyright (c) 2010 Gerald T. Beauregard
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */
public class FFT2
{
    // Element for linked list in which we store the
    // input/output data. We use a linked list because
    // for sequential access it's faster than array index.
    class FFTElement
    {
        public double re = 0.0;     // Real component
        public double im = 0.0;     // Imaginary component
        public FFTElement next;     // Next element in linked list
        public uint revTgt;         // Target position post bit-reversal
    }

    private uint m_logN = 0;        // log2 of FFT size
    private uint m_N = 0;           // FFT size
    private FFTElement[] m_X;       // Vector of linked list elements

    /**
     *
     */
    public FFT2()
    {
    }

    /**
     * Initialize class to perform FFT of specified size.
     *
     * @param   logN    Log2 of FFT length. e.g. for 512 pt FFT, logN = 9.
     */
    public void init(
        uint logN )
    {
        m_logN = logN;
        m_N = (uint)(1 << (int)m_logN);

        // Allocate elements for linked list of complex numbers.
        m_X = new FFTElement[m_N];
        for (uint k = 0; k < m_N; k++)
            m_X[k] = new FFTElement();

        // Set up "next" pointers.
        for (uint k = 0; k < m_N-1; k++)
            m_X[k].next = m_X[k+1];

        // Specify target for bit reversal re-ordering.
        for (uint k = 0; k < m_N; k++ )
            m_X[k].revTgt = BitReverse(k,logN);
    }

    /**
     * Performs in-place complex FFT.
     *
     * @param   xRe     Real part of input/output
     * @param   xIm     Imaginary part of input/output
     * @param   inverse If true, do an inverse FFT
     */
    public void run(
        double[] xRe,
        double[] xIm,
        bool inverse = false )
    {
        uint numFlies = m_N >> 1;   // Number of butterflies per sub-FFT
        uint span = m_N >> 1;       // Width of the butterfly
        uint spacing = m_N;         // Distance between start of sub-FFTs
        uint wIndexStep = 1;        // Increment for twiddle table index

        // Copy data into linked complex number objects
        // If it's an IFFT, we divide by N while we're at it
        FFTElement x = m_X[0];
        uint k = 0;
        double scale = inverse ? 1.0/m_N : 1.0;
        while (x != null)
        {
            x.re = scale*xRe[k];
            x.im = scale*xIm[k];
            x = x.next;
            k++;
        }

        // For each stage of the FFT
        for (uint stage = 0; stage < m_logN; stage++)
        {
            // Compute a multiplier factor for the "twiddle factors".
            // The twiddle factors are complex unit vectors spaced at
            // regular angular intervals. The angle by which the twiddle
            // factor advances depends on the FFT stage. In many FFT
            // implementations the twiddle factors are cached, but because
            // array lookup is relatively slow in C#, it's just
            // as fast to compute them on the fly.
            double wAngleInc = wIndexStep * 2.0*Math.PI/m_N;
            if (inverse == false)
                wAngleInc *= -1;
            double wMulRe = Math.Cos(wAngleInc);
            double wMulIm = Math.Sin(wAngleInc);

            for (uint start = 0; start < m_N; start += spacing)
            {
                FFTElement xTop = m_X[start];
                FFTElement xBot = m_X[start+span];

                double wRe = 1.0;
                double wIm = 0.0;

                // For each butterfly in this stage
                for (uint flyCount = 0; flyCount < numFlies; ++flyCount)
                {
                    // Get the top & bottom values
                    double xTopRe = xTop.re;
                    double xTopIm = xTop.im;
                    double xBotRe = xBot.re;
                    double xBotIm = xBot.im;

                    // Top branch of butterfly has addition
                    xTop.re = xTopRe + xBotRe;
                    xTop.im = xTopIm + xBotIm;

                    // Bottom branch of butterly has subtraction,
                    // followed by multiplication by twiddle factor
                    xBotRe = xTopRe - xBotRe;
                    xBotIm = xTopIm - xBotIm;
                    xBot.re = xBotRe*wRe - xBotIm*wIm;
                    xBot.im = xBotRe*wIm + xBotIm*wRe;

                    // Advance butterfly to next top & bottom positions
                    xTop = xTop.next;
                    xBot = xBot.next;

                    // Update the twiddle factor, via complex multiply
                    // by unit vector with the appropriate angle
                    // (wRe + j wIm) = (wRe + j wIm) x (wMulRe + j wMulIm)
                    double tRe = wRe;
                    wRe = wRe*wMulRe - wIm*wMulIm;
                    wIm = tRe*wMulIm + wIm*wMulRe;
                }
            }

            numFlies >>= 1;     // Divide by 2 by right shift
            span >>= 1;
            spacing >>= 1;
            wIndexStep <<= 1;   // Multiply by 2 by left shift
        }

        // The algorithm leaves the result in a scrambled order.
        // Unscramble while copying values from the complex
        // linked list elements back to the input/output vectors.
        x = m_X[0];
        while (x != null)
        {
            uint target = x.revTgt;
            xRe[target] = x.re;
            xIm[target] = x.im;
            x = x.next;
        }
    }

    /**
     * Do bit reversal of specified number of places of an int
     * For example, 1101 bit-reversed is 1011
     *
     * @param   x       Number to be bit-reverse.
     * @param   numBits Number of bits in the number.
     */
    private uint BitReverse(
        uint x,
        uint numBits)
    {
        uint y = 0;
        for (uint i = 0; i < numBits; i++)
        {
            y <<= 1;
            y |= x & 0x0001;
            x >>= 1;
        }
        return y;
    }

}数字配方网站http://www.nr.com/ 如果你不介意的话,它有一个FFT。我正在进行一个项目,将Labview程序转换为C 2008、.NET 3.5,以获取数据,然后查看频谱。不幸的是,Math.Net使用了最新的.Net框架,所以我无法使用该FFT。我尝试了外皮的一个-它工作,但结果与Labview的结果相匹配,我不知道足够的FFT理论来知道是什么导致了这个问题。所以我在数字食谱网站上尝试了FFT,它成功了!我还能够编程Labview低副瓣窗口,并且必须引入一个比例因子


你可以作为客人在他们的网站上阅读《数字食谱》一章,但这本书非常有用,我强烈建议你购买它。即使你最终使用Math.NET FFT。

这是一个老问题,但它仍然会出现在谷歌搜索结果中

一个非常不受限制的MIT许可C/.NET库可以在


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

我想了解更多关于Math.NET Iridium fft实现中的奇怪之处的详细信息-因此我们可以修复它;。它与处理复数的方式有关吗?不知道你说的人类可视格式是什么意思。示例:fftw有某种有问题的许可证;检查这个:FFTW的非免费许可证也可以使用,允许不同于GPL的使用条款。这是Mike Bethany的问题。我正在努力学习如何将数据从时域转换到频域。你的外皮质连接方式正确吗
cortext在.net4上抛出系统超出范围异常,但没有附加信息。不工作。仅限于几个变换大小。+1。NET铱星非常适合将使用Apache commons Math的Java代码翻译成.NET,这要感谢每个类和方法之间的密切对应关系。95%的时间你只需要更改类和方法名称,一切都会正常工作。截至2013年6月,单用户价格为499美元。截至2015年10月,composer edition为699美元,这不是免费的“社区许可”计划吗?使用数值公式中的任何代码都要小心。代码没有问题,问题出在许可证上。您必须付费才能使用该代码,非商业或科学应用也不例外。更多信息,请参阅此。由于链接没有指向任何地方,此答案现在完全无用…对此表示抱歉。几年前我删除了我的博客,因为它吸引了太多的垃圾邮件。不幸的是,代码太大了,无法在这里添加注释。请在g.@ieee.org上给我留言,我很乐意将代码发送给您。您可以更新答案,添加代码并删除死链接。通过私人渠道共享代码将违背Stack Overflow.Done的精神。几天前我试着把它放在评论里,但它太大了。我没有想到评论和答案的大小限制会有所不同。