c/c++语言开发共享关于实际数据序列的FFTW

我正在读一个原始的声音文件,我正试图在它上面运行fft,目的是让PSD结束,但我在开始时遇到一个我无法理解的错误,希望在这里得到一些帮助,代码是:

#include  #include  int main(){ char* fileName = "sound.raw"; FILE* inp = NULL; double* data = NULL; int index = 0; fftw_plan plan; fftw_complex* out; double r,i; int N = 8192; //Allocating the memory for the input data data = (double*) fftw_malloc(sizeof(double)*N); out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*N); plan = fftw_plan_dft_r2c_1d(N,data,out,FFTW_FORWARD); // opening the file for reading inp = fopen(fileName,"rb"); if(inp== NULL){ printf(" couldn't open the file n "); return -1; } while(!feof(inp)){ printf( " index %d",index); // just get where the program crashs if(index < N){ fread(&data[index],sizeof(short),1,inp); index = index +1; } else{ index = 0; fftw_execute(plan); printf("New Plan n"); printf(" Real t imag t Magn t n"); for(index = 0 ; index<N; index++){ r=out[index][0]; i =out[index][1]; printf("%lf t %lf t %lf t n",r,i,index); } index = 0 ; } } return 0 ; } 

index = 8106时程序崩溃,我确信该文件包含更多数据。 我得到的错误是:

 Segmentation fault (core dumped ) 

我知道错误与指针试图访问不允许的内存有关,我的问题是如何解决这个问题!

UPDATE

我再次检查了程序,错误完全符合要求:

 fftw_execute(plan) ; 

我希望能帮到更多!

提前致谢!

    找到它,错误是在计划function的参数:

     plan = fftw_plan_dft_r2c_1d(N,data,out,FFTW_FORWARD); // 

    应该是

     plan = fftw_plan_dft_r2c_1d(N,data,out,FFTW_MEASURE); 

    要么

     plan = fftw_plan_dft_r2c_1d(N,data,out,FFTW_ESTIMATE); 

    因为转换的方向隐含在函数的名称中!

    不管怎么说,还是要谢谢你 !

      以上就是c/c++开发分享关于实际数据序列的FFTW相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/c-cdevelopment/519022.html

      (0)
      上一篇 2020年12月5日
      下一篇 2020年12月5日

      精彩推荐