For learning use of the FFTW, i wrote a sample program,but campared with the result of Matlab,i find the ans are totally different. how can i solve this problem ? thank u! i'm looking forward for ur answer. The result of Matlab: a=[1 2 3 1 2 3 1 2]; ans = 15.0000 -1.0000 + 0.5858i -1.0000 + 2.0000i -1.0000 - 3.4142i -1.0000 -1.0000 + 3.4142i -1.0000 - 2.0000i -1.0000 - 0.5858i The result of FFTW is =============================== [0]real=0.000000 img=-1.000000 [1]real=-0.585786 img=-1.000000 [2]real=-2.000000 img=-1.000000 [3]real=3.414214 img=-1.000000 [4]real=0.000000 img=-6277438562204192500000000000000000000000000000000000000000 000000000.000000 [5]real=-6277438562204192500000000000000000000000000000000000000000000000000.000 000 img=-6277438562204192500000000000000000000000000000000000000000000000000.000 000 [6]real=-6277438562204192500000000000000000000000000000000000000000000000000.000 000 img=-6277438562204192500000000000000000000000000000000000000000000000000.000 000 [7]real=-6277438562204192500000000000000000000000000000000000000000000000000.000 000 img=-6277438562204192500000000000000000000000000000000000000000000000000.000 000 =============================== ====================================the program================== int main(int argc, char* argv[]) { fftw_complex *out; double in[]={1,2,3,1,2,3,1,2}; fftw_plan p; //in=(fftw_complex *)fftw_malloc(sizeof(fftw_complex)*8); out=(fftw_complex *)fftw_malloc(sizeof(fftw_complex)*10); p=fftw_plan_dft_r2c_1d(8,in,out,FFTW_ESTIMATE); fftw_execute(p); for(int i=0;i<8;i++) { printf("[%d]real=%f img=%f \n",i,out[i][1],out[i][2]); } }
Same input ,different ans? matlab Vs FFTW
Started by ●March 26, 2006
Reply by ●March 27, 20062006-03-27
"Vincent2046" <cui.z.w@gmx.net> wrote in message news:obWdnXUK6b2prbrZnZ2dnUVZ_vednZ2d@giganews.com...> For learning use of the FFTW, i wrote a sample program,but campared with > the result of Matlab,i find the ans are totally different. how can i solve > this problem ? thank u! i'm looking forward for ur answer. > > The result of Matlab: > a=[1 2 3 1 2 3 1 2]; > ans = > > 15.0000 > -1.0000 + 0.5858i > -1.0000 + 2.0000i > -1.0000 - 3.4142i > -1.0000 > -1.0000 + 3.4142i > -1.0000 - 2.0000i > -1.0000 - 0.5858i > > The result of FFTW is > =============================== > [0]real=0.000000 img=-1.000000 > [1]real=-0.585786 img=-1.000000 > [2]real=-2.000000 img=-1.000000 > [3]real=3.414214 img=-1.000000 > [4]real=0.000000 > img=-6277438562204192500000000000000000000000000000000000000000 > 000000000.000000 >[5]real=-6277438562204192500000000000000000000000000000000000000000000000000 .000> 000 >img=-6277438562204192500000000000000000000000000000000000000000000000000.000> 000 >[6]real=-6277438562204192500000000000000000000000000000000000000000000000000 .000> 000 >img=-6277438562204192500000000000000000000000000000000000000000000000000.000> 000 >[7]real=-6277438562204192500000000000000000000000000000000000000000000000000 .000> 000 >img=-6277438562204192500000000000000000000000000000000000000000000000000.000> 000 > =============================== > > > > > ====================================the program================== > int main(int argc, char* argv[]) > { > fftw_complex *out; > double in[]={1,2,3,1,2,3,1,2}; > fftw_plan p; > //in=(fftw_complex *)fftw_malloc(sizeof(fftw_complex)*8); > out=(fftw_complex *)fftw_malloc(sizeof(fftw_complex)*10); > > > p=fftw_plan_dft_r2c_1d(8,in,out,FFTW_ESTIMATE); > fftw_execute(p); > > for(int i=0;i<8;i++) > { > printf("[%d]real=%f img=%f \n",i,out[i][1],out[i][2]); > } > } > >Pick a simpler case where you can hand-calculate the answer. Eg take [1,0,1,0] or whatever. Tam
Reply by ●March 27, 20062006-03-27
Vincent2046 wrote:> For learning use of the FFTW, i wrote a sample program,but campared with > the result of Matlab,i find the ans are totally different. how can i solve > this problem ? thank u! i'm looking forward for ur answer./*snip*/> ====================================the program================== > int main(int argc, char* argv[]) > { > fftw_complex *out; > double in[]={1,2,3,1,2,3,1,2}; > fftw_plan p; > //in=(fftw_complex *)fftw_malloc(sizeof(fftw_complex)*8); > out=(fftw_complex *)fftw_malloc(sizeof(fftw_complex)*10); > > > p=fftw_plan_dft_r2c_1d(8,in,out,FFTW_ESTIMATE); > fftw_execute(p); > > for(int i=0;i<8;i++) > { > printf("[%d]real=%f img=%f \n",i,out[i][1],out[i][2]); > } > }In C (or C++) the indexing starts from 0. So you have to change your printing to for(int i=0;i<8;i++) { printf("[%d]real=%f img=%f \n",i,out[i][0],out[i][1]); } -- Jani Huhtanen Tampere University of Technology, Pori