FFT是数字信号处理中的重要算法,在matlab中可以直接调用fft()函数,本文是C++版的FFT算法,用递归方式进行实现。
//==================================
//Signal_Process_FFT_v1.cpp
//==================================
#include<iostream>
#include<vector>
#include<complex>
#include<cmath>
using namespace std;
//----------------------------------
class Signal {
vector<complex<double> > xt;
void init() {};
const double PI=3.141592653;
complex<double> W(int N, int k);
void fft(vector<complex<double> >& x,int N);
public:
Signal(complex<double> x[],int xLength);
void display();
void FFT();
};//--------------------------------
Signal::Signal(complex<double> x[], int xLength) {
if (nullptr==x || xLength <= 0) {
cerr << "Input signal illegal.";
exit(0);
}
xt.assign(x, x + xLength);
init();//若信号长度不是2的幂次,需要进行补0,此处略
}//---------------------------------
void Signal::display() {
cout << "[";
for