Created
July 21, 2015 18:33
-
-
Save jbeuckm/85dafabc11c4135f68f3 to your computer and use it in GitHub Desktop.
Using the `fft` library from `npm`.
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
var FFT = require('fft'); | |
FFT_SIZE = 8; | |
var fft = new FFT.complex(FFT_SIZE, false); | |
var ifft = new FFT.complex(FFT_SIZE, true); | |
var inBuffer = new Float32Array([0,.5,1,.5,0,-.5,-1,-.5]); | |
var outBuffer = new Float32Array(2 * FFT_SIZE); | |
var outBuffer2 = new Float32Array(2 * FFT_SIZE); | |
console.log('inBuffer...'); | |
console.log(Array.prototype.slice.call(inBuffer)); | |
fft.simple(outBuffer, inBuffer, 'real'); | |
console.log('outBuffer...'); | |
console.log(Array.prototype.slice.call(outBuffer)); | |
ifft.simple(outBuffer2, outBuffer); | |
console.log('outBuffer2...'); | |
console.log(Array.prototype.slice.call(outBuffer2)); | |
var realOut = []; | |
for (var i=0; i<FFT_SIZE; i++) { | |
realOut[i] = outBuffer2[2*i] / FFT_SIZE; | |
} | |
console.log('realOut...'); | |
console.log(realOut); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment