,這裏是我的實現代碼它FFT計算算法從這裏描述的快速傅立葉變換算法MIT書(介紹算法)
#include <iostream>
#include<complex>
#include<math.h>
#include<vector>
#include<iterator>
#include<complex>
using namespace std;
#define E 2.718
#define PI 3.14
#define n 8
void FFT(vector<float>&a){
vector<float>::iterator it;
const double pi = std::acos(-1.0);
const std::complex<double> i(0,1);
complex<double> wn =std::exp((2*pi*i)/8.0);
vector<float>y;
vector<float>y0;
vector<float>y1;
int omega=1;
vector<float>a0;
vector<float>a1;
for (int i=0;i<n-1;i+=2)
a0[i]=a[i];
for (int i=1;i<n;i+=2)
a1[i]=a[1];
y0=FFT(a0);
y1=FFT(a1);
for (int k=0;k<n/2-1;k++){
y[0]=y0[k]+omega*y1[k];
y[k+n/2]=y0[k]-omega*y1[k];
omega=omega*imag(wn);
}
for(it=y.begin();it!=y.end();it++){
cout<<*it<<" ";
}
}
int main(){
vector<int>a;
a.push_back(2);
a.push_back(3);
a.push_back(5);
a.push_back(1);
a.push_back(100);
a.push_back(200);
a.push_back(300);
a.push_back(400);
cout<<FFT(a)<<endl;
return 0;
}
,但它爲我的錯誤列表
Error 1 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion) c:\users\datuashvili\documents\visual studio 2010\projects\fft\fft\fft.cpp 28 1 FFT
Error 2 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion) c:\users\datuashvili\documents\visual studio 2010\projects\fft\fft\fft.cpp 29 1 FFT
Warning 3 warning C4244: '=' : conversion from 'double' to 'int', possible loss of data c:\users\datuashvili\documents\visual studio 2010\projects\fft\fft\fft.cpp 35 1 FFT
Error 4 error C2664: 'FFT' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'std::vector<_Ty> &' c:\users\datuashvili\documents\visual studio 2010\projects\fft\fft\fft.cpp 56 1 FFT
5 IntelliSense: no operator "=" matches these operands c:\users\datuashvili\documents\visual studio 2010\projects\fft\fft\fft.cpp 28 7 FFT
6 IntelliSense: no operator "=" matches these operands c:\users\datuashvili\documents\visual studio 2010\projects\fft\fft\fft.cpp 29 7 FFT
7 IntelliSense: a reference of type "std::vector<float, std::allocator<float>> &" (not const-qualified) cannot be initialized with a value of type "std::vector<int, std::allocator<int>>" c:\users\datuashvili\documents\visual studio 2010\projects\fft\fft\fft.cpp 56 12 FFT
更新: 這裏是我更新的代碼
#include <iostream>
#include<complex>
#include<math.h>
#include<vector>
#include<iterator>
#include<complex>
using namespace std;
#define E 2.718
#define PI 3.14
#define n 8
vector<float>FFT(vector<double>a)
{
vector<float>::iterator it;
const double pi = std::acos(-1.0);
const std::complex<double> i(0,1);
complex<double> wn =std::exp((2*pi*i)/8.0);
vector<double>y;
vector<double>y0;
vector<double>y1;
double omega=1;
vector<double>a0;
vector<double>a1;
for (int i=0;i<n-1;i+=2)
a0[i]=a[i];
for (int i=1;i<n;i+=2)
a1[i]=a[1];
FFT(a0);
y0=a0;
FFT(a1);
y1=a1;
for (int k=0;k<n/2-1;k++){
y[0]=y0[k]+omega*y1[k];
y[k+n/2]=y0[k]-omega*y1[k];
omega=omega*imag(wn);
}
return y;
}
int main(){
vector<double>a;
a.push_back(2);
a.push_back(3);
a.push_back(5);
a.push_back(1);
a.push_back(100);
a.push_back(200);
a.push_back(300);
a.push_back(400);
FFT(a);
return 0;
}
,但它顯示我的錯誤又
Error 1 error C2664: 'std::vector<_Ty>::vector(const std::vector<_Ty> &)' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'const std::vector<_Ty> &' c:\users\datuashvili\documents\visual studio 2010\projects\fft\fft\fft.cpp 42 1 FFT
2 IntelliSense: no suitable user-defined conversion from "std::vector<double, std::allocator<double>>" to "std::vector<float, std::allocator<float>>" exists c:\users\datuashvili\documents\visual studio 2010\projects\fft\fft\fft.cpp 42 11 FFT
請幫我傢伙
我認爲編譯器錯誤應該足夠清楚。 –