2
我正在爲Java中的CSE類做一個分配,並正在實施FFT和直接DFT(使用矩陣計算)。我的FFT工作正常,但我的直接DFT不起作用。我的傅立葉矩陣不會出現正確的值,我想知道它是否出現用戶錯誤,或者問題出在我正在使用的Complex類(org.apache.commons.math.complex)上。有了這樣一個主流的課堂,我想它只是用戶的錯誤,所以如果有人能指出,那會很好。在Java中使用離散傅里葉變換(不是FFT)
我的傅立葉矩陣計算的工作原理如下:
Complex[][] fmatrix = new Complex[cvector.length][cvector.length]; // Initialize Matrix
for(int k = 0; k < n; k++) {
double val = -2.0 * k * Math.PI/n; // Calculate exponential value
Complex w = new Complex(0.0,val); // Store that in a Complex value and set imaginary piece to the exponential value
for (int l = 0; l < n; l++) {
Complex powerof = new Complex((double) (k*l),0.0); // Calculate the power to take it to
fmatrix[k][l] = w.exp().pow(powerof); // Take the exponent, then raise it to powerof
}
}
我有一些項目拉出到變量進行調試,但代碼應該從我的理解所有的工作。
上面的代碼,對於n = 4的長度矢量,但是,想出了下面的矩陣:
Mine Desired
[ 1, 1, 1, 1 [ 1, 1, 1, 1
1, -j, -1, j 1, -j, -1, j
1, 1, 1, 1 =/= 1, -1, 1, -1
1, -j, -1, j ] 1, j, -1, -j ]
任何幫助不勝感激。
就是這樣。非常感謝你。我只是混合了我的FFT和DFT方程。 – Ktash 2011-03-04 17:51:16