Lianqing
03-30-2006, 07:44 PM
Hi,
I find that the reverse transform code in realft() does not always yield correct result. Here is my testing code:
//////////////////////
const int N = 8;
Vec_DP data1(N), data2(N);
// Prepare test data
for ( int i = 0; i < N; i ++ ) {
data[i] = sin(1.0*i);
data2[i] = 1.0*i;
}
// run FFT
NR::realft(data1, 1);
// result (it's correct)
//No. 0: 0.553733 - 0.807574 i
// No. 1: 2.39465 + 2.09701 i
// No. 2: -1.38668 - 0.91556 i
//No. 3: -0.881042 - 0.280414 i
NR::realft(data1, -1);
// result (it's wrong)
// 0, 0.262406, 1.48836, 0.14112, -0.756802,
// -0.379859,-0.858481,0.656987
NR::realft(data2, 1);
// result (it's correct)
//No. 0: 28 - 4 i
//No. 1: -4 - 9.65685 i
//No. 2: -4 - 4 i
//No. 3: -4 - 1.65685 i
NR::realft(data2, -1);
// result (it' correct for this test dataset!) 0,1,2,3,4,5,6,7
I also try different data sets such as cos, exp and so on and the reverse transform results are wrong.
I type the routine code of this chapter and am sure there is no type errors in the code as I've tested the routines in this chapter with different datasets. Everything is OK except the one I mentioned above.
I am blindly guessing that the issue may result from the special structure in which the complex data is stored after forward transform, i.e. the first element of the complex array contains the real part of first (0 frequency) and middle (Niquist frequency) values of the transformed array.
Anyway, is there anyone who's got the same experience? Any help will be greatly appreciated!
Lianqing
3/31/2006
I find that the reverse transform code in realft() does not always yield correct result. Here is my testing code:
//////////////////////
const int N = 8;
Vec_DP data1(N), data2(N);
// Prepare test data
for ( int i = 0; i < N; i ++ ) {
data[i] = sin(1.0*i);
data2[i] = 1.0*i;
}
// run FFT
NR::realft(data1, 1);
// result (it's correct)
//No. 0: 0.553733 - 0.807574 i
// No. 1: 2.39465 + 2.09701 i
// No. 2: -1.38668 - 0.91556 i
//No. 3: -0.881042 - 0.280414 i
NR::realft(data1, -1);
// result (it's wrong)
// 0, 0.262406, 1.48836, 0.14112, -0.756802,
// -0.379859,-0.858481,0.656987
NR::realft(data2, 1);
// result (it's correct)
//No. 0: 28 - 4 i
//No. 1: -4 - 9.65685 i
//No. 2: -4 - 4 i
//No. 3: -4 - 1.65685 i
NR::realft(data2, -1);
// result (it' correct for this test dataset!) 0,1,2,3,4,5,6,7
I also try different data sets such as cos, exp and so on and the reverse transform results are wrong.
I type the routine code of this chapter and am sure there is no type errors in the code as I've tested the routines in this chapter with different datasets. Everything is OK except the one I mentioned above.
I am blindly guessing that the issue may result from the special structure in which the complex data is stored after forward transform, i.e. the first element of the complex array contains the real part of first (0 frequency) and middle (Niquist frequency) values of the transformed array.
Anyway, is there anyone who's got the same experience? Any help will be greatly appreciated!
Lianqing
3/31/2006