【发布时间】:2013-12-11 16:50:54
【问题描述】:
我正在执行 radix-2 dif 逆 fft。我正在使用共轭和缩放的属性来返回结果。我对输入向量进行共轭,执行常规 radix-2 fft(不是 ifft),对结果进行共轭,然后按 1.0/N 缩放。但是,我没有得到正确的结果:
int main(){
const int n = 4;
complex<double> x[n];
// Test signal
x[0] = complex<double>(10,0);
x[1] = complex<double>(-2,0);
x[2] = complex<double>(-2,2);
x[3] = complex<double>(-2,-2);
print(x,n);
fft_inverse(x,n);
print(x,n);
}
//dif fft. works
void fft(complex<double> X[], int N){
if(N == 1){return;}
complex<double> *temp = new complex<double>[N];
for(int i=0; i<N; i++){
temp[i]=X[i];
}
for(int i = 0; i<N/2; i++){
complex<double> tw(cos(-2*M_PI*i/N),sin(-2*M_PI*i/N));
X[i] = temp[i] + temp[i+N/2];
X[i+N/2] = temp[i]-temp[i+N/2];
X[i+N/2] = X[i+N/2]*tw;
}
fft(X,N/2);
fft(X+N/2,N/2);
}
void fft_inverse(complex<double> X[], int N){
//conjugate
for(int i = 0; i<N;i++){
X[i] = conj(X[i]);
}
//perform fft
fft(X,N);
//conjugate again
for(int i = 0; i<N;i++){
X[i] = conj(X[i]);
}
//scale by 1.0/N
double norm_N = 1.0/N;
for(int i = 0; i<N;i++){
X[i] *= norm_N;
}
}
这是我的结果: 输入:
(10,0) (-2,0) (-2,2) (-2,-2)
输出:
(1,-0) (3,1) (2.5,-0.5) (3.5,-0.5)
输出应该是:
(1,0) (2,0) (3,0) (4,0)
发生了什么事?我已经测试了我的fft 的输出应该是什么并收到了正确的结果,所以我不确定问题是什么。
【问题讨论】: