为什么FFTW3的DST Type-1(离散正弦变换)函数运行缓慢?

huangapple go评论114阅读模式
英文:

Why FFTW3's DST Type-1 (discrete sine transform) function is slow?

问题

我使用了fftw3的FFTW_RODFT00函数,但它非常慢(正如他们在文档中提到的fftw3 2.5.2 Real even/odd DFTs)。

  1. // N->Array length, input->Input Array, output->Output Array
  2. fftw_plan plan = fftw3_r2r_1d(N, input, output, FFTW_RODFT, FFTW_ESTIMATE);
  3. fftw_execute(plan);
  4. //使用output...
  5. fftw_destroy_plan(plan);
  6. fftw_cleanup();

我尝试手动转换dst函数,但它是O(n^2)算法,所以也很慢。

如何使用FFT算法快速计算离散正弦变换,而不使用DST Type-1函数?

英文:

I used fftw3 s FFTW_RODFT00 function, but it's very slow (as they mentioned in documents. fftw3 2.5.2 Real even/odd DFTs).

  1. // N->Array length, input->Input Array, output->Output Array
  2. fftw_plan plan = fftw3_r2r_1d(N, input, output, FFTW_RODFT, FFTW_ESTIMATE);
  3. fftw_execute(plan);
  4. //using output...
  5. fftw_destroy_plan(plan);
  6. fftw_cleanup();

I tried to convert dst function manually but it O(n^2) algorithms so it's slow either.

How can i calculate fast discrete sine transfrom with using FFT algorithm, not using DST Type-1 Funciton?

答案1

得分: 1

我找到了一种使用FFTW3的FFT库函数计算离散正弦变换(Discrete Sine Transform)的方法。但我必须说它仍然比MATLAB的dst()函数慢(而我仍然不知道原因)。 让我简单解释一下我做了什么:

  1. //x->第一个带有一些值的数组
  2. //y->FFT输入数组
  3. //z->FFT输出数组
  4. //n->第一个数组(x)的大小
  5. #define REAL 0
  6. #define IMAG 1
  7. function_Name(){
  8. const int n = 1000;
  9. double x[n][2];
  10. //用一些值填充x
  11. for(i){
  12. x[i][REAL]=i+1;
  13. x[i][IMAG]=0;
  14. }
  15. fftw_complex y[(n+1)*2];
  16. fftw_complex z[(n+1)*2];
  17. y[0][REAL]=0;
  18. y[0][IMAG]=0;
  19. for(){
  20. //从第2个元素(y[1])开始将x添加到y
  21. }
  22. y[n+1][REAL]=0;
  23. y[n+1][IMAG]=0;
  24. for(){
  25. //反转x并乘以"-",然后添加到y
  26. }
  27. fftw_plan plan = fftw_plan_dft_1d((n+1)*2, y, z, FFTW_FORWARD, FFTW_ESTIMATE);
  28. fftw_execute(plan);
  29. **//你可以使用z,但首先必须反转它(在MATLAB中使用fliplr),然后只取前n个元素和仅取IMAG部分**
  30. fftw_destroy_plan(plan);
  31. fftw_cleanup();
  32. }
  33. 我知道这个算法不是完美的,但我正在努力优化它并使其更加清晰。MATLAB fft()函数和FFTWFFT函数之间的速度差异仍然是一个问题。我将另外提出一个新的问题来讨论这个问题。
  34. <details>
  35. <summary>英文:</summary>
  36. I found a way to calculate Discrete Sine Transform with FFTW3&#39;s FFT library function. **But i should say it still slower than MATLAB dst() function (and i still don&#39;t know why)**. Let me simply explain what i did:
  37. //x-&gt;Your first array with some values
  38. //y-&gt;FFT input array
  39. //z-&gt;FFT output array
  40. //n-&gt;First array(x) size
  41. #define REAL 0
  42. #define IMAG 1
  43. function_Name(){
  44. const int n = 1000;
  45. double x[n][2];
  46. //Fill x with some value
  47. for(i){
  48. x[i][REAL]=i+1;
  49. x[i][IMAG]=0;
  50. }
  51. fftw_complex y[(n+1)*2];
  52. fftw_complex z[(n+1)*2];
  53. y[0][REAL]=0;
  54. y[0][IMAG]=0;
  55. for(){
  56. //Add x to y from 2. element(y[1])
  57. }
  58. y[n+1][REAL]=0;
  59. y[n+1][IMAG]=0;
  60. for(){
  61. //Invert x and multiply by &quot;-&quot; and add to y
  62. }
  63. fftw_plan plan = fftw_plan_dft_1d((n+1)*2, y, z, FFTW_FORWARD, FFTW_ESTIMATE);
  64. fftw_execute(plan);
  65. **//You can use z but first you have to Invert (fliplr in MATLAB) it and take only first n elements and only IMAG parts.**
  66. fftw_destroy_plan(plan);
  67. fftw_cleanup();
  68. }
  69. I know this algorithm isn&#39;t perfect but I&#39;m working on it to speed up and to make a clean. For speed difference between MATLAB fft() function and FFTW&#39;s FFT function is still a problem. I will open a new question about it.
  70. </details>

huangapple
  • 本文由 发表于 2023年3月8日 17:26:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75671309.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定