Created
June 1, 2012 17:10
-
-
Save kaizhu256/2853690 to your computer and use it in GitHub Desktop.
javscript naive discrete fourier transform
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
//// 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