Note that there are some explanatory texts on larger screens.

plurals
  1. PODiscrete Fourier Transform (Not FFT) In Java
    text
    copied!<p>I'm doing an assignment for a CSE class in Java and am implementing a FFT and the direct DFT (with matrix calculations). My FFT works fine, but my direct DFT is not working. My Fourier matrix is not coming out with the right values, and I want to know if its a user error, or if the issue instead lies in the Complex class that I'm using (<a href="http://commons.apache.org/math/userguide/complex.html" rel="nofollow">org.apache.commons.math.complex</a>). With such a mainstream class, I imagine its just user error, so if someone could point it out, that would be great.</p> <p>My Fourier Matrix calculations works as follows:</p> <pre><code>Complex[][] fmatrix = new Complex[cvector.length][cvector.length]; // Initialize Matrix for(int k = 0; k &lt; 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 &lt; 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 } } </code></pre> <p>I have some of the items pulled out into variables for debugging purposes, but the code should all work from my understanding.</p> <p>The code above, for a n=4 length vector, however, comes up with the following matrix:</p> <pre><code> 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 ] </code></pre> <p>Any help is greatly appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload