Skip to content

Instantly share code, notes, and snippets.

@kaizhu256
Created June 1, 2012 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaizhu256/2853690 to your computer and use it in GitHub Desktop.
Save kaizhu256/2853690 to your computer and use it in GitHub Desktop.
javscript naive discrete fourier transform
//// naive O(n^2) algorithm for verifying fft algorithm
my.Complex2.prototype.dft = function(mode) {
var ee, ii2, ll2, tmp;
ll2 = this[0].ll2; ee = my.Complex2(1, ll2); tmp = ee.copy();
ee[1].set(my.Array2.range(ll2)).mul(-2 * Math.PI / ll2); if(mode === 'reverse') {ee.neg();}
if(mode === 'reverse') {this.mul(1 / ll2);}
this.each1(
function(slice) {
tmp.set([0, 0]);
for(ii2 = 0; ii2 < ll2; ii2 += 1) {
tmp.slice(null, null, ii2, ii2 + 1).dot2(
ee.copy().mul(ii2).exp2(),
slice
);
}
slice.set(tmp);
}
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment