Created
November 16, 2015 16:49
-
-
Save jokamjohn/9bb32b08da48dcff7d80 to your computer and use it in GitHub Desktop.
Method two...Looks promising
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Created by jokamjohn on 11/16/2015. | |
| */ | |
| public final class Test { | |
| /* | |
| * Computes the discrete Fourier transform (DFT) of the given vector. | |
| * All the array arguments must have the same length. | |
| */ | |
| public static void computeDft(double[] inreal, double[] inimag, double[] outreal, double[] outimag) { | |
| int n = inreal.length; | |
| for (int k = 0; k < n; k++) { // For each output element | |
| double sumreal = 0; | |
| double sumimag = 0; | |
| for (int t = 0; t < n; t++) { // For each input element | |
| double angle = 2 * Math.PI * t * k / n; | |
| sumreal += inreal[t] * Math.cos(angle) + inimag[t] * Math.sin(angle); | |
| sumimag += -inreal[t] * Math.sin(angle) + inimag[t] * Math.cos(angle); | |
| } | |
| outreal[k] = sumreal; | |
| outimag[k] = sumimag; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment