基-2 FFT算法的C++程序
2016-05-19 21:34
239 查看
基-2 FFT算法的C++程序,按时间抽选、输入倒位序、输出自然顺序,N=2LN=2^L
看了几天的其他资料,才慢慢清醒,教科书上的代码~~呵呵
有助于对基-2 FFT算法的理解和掌握,对以后的时域/频域处理大有裨益。
有问题的代码,需要继续修改
.〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓.
复数z=a+bi,可用点Z(a,b)表示z=a+bi,可用点Z(a,b)表示
.〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓.
FFT倒位序算法
看了几天的其他资料,才慢慢清醒,教科书上的代码~~呵呵
#include <complex> //教科书无该行代码 using namespace std; //教科书int fft(complex *a,int l) int fft(complex<double> *a,int l) { const double pai = 3.141592653589793; complex<double> u,w,t; unsigned n=1,nv2,nm1,k,le,lei,ip; unsigned i,j,m; double tmp; n<<= 1; nv2=n>>1; nm1=n-1; j = 0; //教科书 i = 0; for (i = 0; i < nm1; i++) { if (i < j) { t = a[j]; a[j] = a[i]; a[i] = t; } k = nv2; while (k <= j) { j-=k; k>>=1; }; j+=k; }; le=1; for (m = 1; m <= 1; m++) { lei = le; le <<= 1; u = complex<double>(1, 0); tmp = pai / lei; w = complex<double>(cos(tmp), -sin(tmp)); for (j = 0; j < lei; j++) { for (i = j;i<n;i+=le) { ip = i + lei; t = a[ip] * u; a[ip] = a[i] - t; a[i] += t; } u *= w; } } return 0; }
有助于对基-2 FFT算法的理解和掌握,对以后的时域/频域处理大有裨益。
有问题的代码,需要继续修改
#include <complex> #include <iostream> using namespace std; int fft(complex<double> *a,int l) { const double pai = 3.141592653589793; complex<double> u,w,t; unsigned n=1,nv2,nm1,k,le,lei,ip; unsigned i,j,m; double tmp; n<<= 1; nv2=n>>1; nm1=n-1; j = 0; for (i = 0; i < nm1; i++) { if (i < j) { t = a[j]; a[j] = a[i]; a[i] = t; } k = nv2; while (k <= j) { j-=k; k>>=1; }; j+=k; }; le=1; for (m = 1; m <= 1; m++) { lei = le; le <<= 1; u = complex<double>(1, 0); tmp = pai / lei; w = complex<double>(cos(tmp), -sin(tmp)); for (j = 0; j < lei; j++) { for (i = j;i<n;i+=le) { ip = i + lei; t = a[ip] * u; a[ip] = a[i] - t; a[i] += t; } u *= w; } } return 0; } //int main() //{ //complex<double> a[8] = {0,1,2,3,4,5,6,7}; //complex<double> *p; //p = a; //int fft(complex<double> *a, int l); //fft( p,3); //cout << "End" <<endl; //return 0; //system("pause"); }
.〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓.
复数z=a+bi,可用点Z(a,b)表示z=a+bi,可用点Z(a,b)表示
// complex constructor example #include <iostream> // std::cout #include <complex> // std::complex using namespace std; int main() { complex<double> first(2.0, 2.0); complex<double> second(first); complex<long double> third(second); cout << "first= " << first << endl; cout << "second= " << second << endl; cout << "third= " << third << endl; system ("pause"); system ("cmd"); return 0; }
.〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓.
FFT倒位序算法
#include <iostream> using namespace std; int main() { int array[8]={0,1,2,3,4,5,6,7}; int i,j,k; int N = 8; int temp; j = 0; for(i = 0; i < N -1; i ++) { if(i < j) { temp = array[i]; array[i] = array[j]; array[j] = temp; } k = N >> 1; while( k <= j) { j = j - k; k >>= 1; } j = j + k; } for( i = 0; i < N; i ++) printf("%d ",array[i]); printf("\n"); return 0; }
相关文章推荐
- 2015级C++第13周实践项目 多态性和实现
- Box2D C++ 教程-简介
- 深入分析C++中声明与定义的区别
- C语言按要求打印数组
- 【C语言】C语言储存类型关键字详细解析
- 深入理解C++的动态绑定和静态绑定
- L1-005. 考试座位号(C++)
- C++类型安全
- C++STL中的tuple 与 pair (piecewise construction)
- c语言总结
- MFC——工厂模式——计算器
- 【C程序设计语言(第二版)学习】++ndigit[c-'0']理解
- VS2010对C++11的支持列表(感觉大部分都不支持)
- C++ 实现反射机制
- 基于贝叶斯学习的自适应中文词组的联想输入原理及C++实现
- L1-003. 个位数统计(C++)
- 使用VS开发人员命令提示符查看C++虚函数表及类内存分布
- 回顾:C++开篇课堂
- C++之引用
- C语言链表各种操作