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

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

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

问题

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

// N->Array length, input->Input Array, output->Output Array
fftw_plan plan = fftw3_r2r_1d(N, input, output, FFTW_RODFT, FFTW_ESTIMATE);

fftw_execute(plan);

//使用output...

fftw_destroy_plan(plan);
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).

// N->Array length, input->Input Array, output->Output Array
fftw_plan plan = fftw3_r2r_1d(N, input, output, FFTW_RODFT, FFTW_ESTIMATE);

fftw_execute(plan);

//using output...

fftw_destroy_plan(plan);
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()函数慢(而我仍然不知道原因)。 让我简单解释一下我做了什么:

//x->第一个带有一些值的数组
//y->FFT输入数组
//z->FFT输出数组
//n->第一个数组(x)的大小

#define REAL 0
#define IMAG 1

function_Name(){
const int n = 1000;
double x[n][2];

//用一些值填充x
for(i){
x[i][REAL]=i+1;
x[i][IMAG]=0;
}

fftw_complex y[(n+1)*2];
fftw_complex z[(n+1)*2];

y[0][REAL]=0;
y[0][IMAG]=0;

for(){
//从第2个元素(y[1])开始将x添加到y
}

y[n+1][REAL]=0;
y[n+1][IMAG]=0;

for(){
//反转x并乘以"-",然后添加到y
}

fftw_plan plan = fftw_plan_dft_1d((n+1)*2, y, z, FFTW_FORWARD, FFTW_ESTIMATE);

fftw_execute(plan);

**//你可以使用z,但首先必须反转它(在MATLAB中使用fliplr),然后只取前n个元素和仅取IMAG部分**

fftw_destroy_plan(plan);
fftw_cleanup();

}

我知道这个算法不是完美的,但我正在努力优化它并使其更加清晰。MATLAB fft()函数和FFTW的FFT函数之间的速度差异仍然是一个问题。我将另外提出一个新的问题来讨论这个问题。

<details>
<summary>英文:</summary>

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:

    //x-&gt;Your first array with some values
    //y-&gt;FFT input array
    //z-&gt;FFT output array
    //n-&gt;First array(x) size

    #define REAL 0
    #define IMAG 1
    
    function_Name(){
    const int n = 1000;
    double x[n][2];
    
    //Fill x with some value
    for(i){
    x[i][REAL]=i+1;
    x[i][IMAG]=0;
    }
    
    fftw_complex y[(n+1)*2];
    fftw_complex z[(n+1)*2];
    
    y[0][REAL]=0;
    y[0][IMAG]=0;
    
    for(){
    //Add x to y from 2. element(y[1])
    }
    
    y[n+1][REAL]=0;
    y[n+1][IMAG]=0;
    
    for(){
    //Invert x and multiply by &quot;-&quot; and add to y
    }
    
    fftw_plan plan = fftw_plan_dft_1d((n+1)*2, y, z, FFTW_FORWARD, FFTW_ESTIMATE);
    
    fftw_execute(plan);
    
    **//You can use z but first you have to Invert (fliplr in MATLAB) it and take only first n elements and only IMAG parts.**
    
    fftw_destroy_plan(plan);
    fftw_cleanup();

    }

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.  

</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:

确定