Skip to content

Instantly share code, notes, and snippets.

@jokamjohn
Created November 16, 2015 16:49
Show Gist options
  • Select an option

  • Save jokamjohn/9bb32b08da48dcff7d80 to your computer and use it in GitHub Desktop.

Select an option

Save jokamjohn/9bb32b08da48dcff7d80 to your computer and use it in GitHub Desktop.
Method two...Looks promising
/**
* 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