Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

快速傅里叶变换(FFT)

$
0
0

贴过来做个模板。

C为复数类,newArr和at为内存池。

void FFT(int n, C *x)
{
    C W = C(cos(2 * M_PI / n), sin(2 * M_PI / n)), w = C(1), 
        *u = newArr(n >> 1), *v = newArr(n >> 1);
    for (int i = 0; i < n >> 1; ++i)
        u[i] = x[i << 1], v[i] = x[i << 1 | 1];
    if (n > 1) FFT(n >> 1, u), FFT(n >> 1, v);
    for (int i = 0; i < n >> 1; ++i, w *= W)
        x[i] = u[i] + w * v[i], x[i + (n >> 1)] = u[i] - w * v[i];
    at -= n + 5;
}


作者:JerryDung 发表于2013-5-4 20:03:38 原文链接
阅读:61 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>