dntj / jsfft Goto Github PK
View Code? Open in Web Editor NEWSmall, efficient Javascript FFT implementation
License: MIT License
Small, efficient Javascript FFT implementation
License: MIT License
There's a todo in the recursive transform. Can you possibly apply the multiplier while computing the output.real and output.imag values, then just swap them over to the input arrays (somehow)? Perhaps just ref the output arrays? input.real = output.real, etc...
Node 4 is still in lts (codenamed "argon") and should be supported on npm.
(see Node's LTS release schedule)
It's pretty much as simple as adding babel-preset-es2015
to the dev dependencies and adding "presets": ["es2015"]
to .babelrc
.
I'd make a PR for this myself, but I'm not entirely sure how to handle the test scripts and src for < v6.
Maybe they can also be transpiled before the tests run if < v6? It's a decision to discuss if you decide to support v4.
Thanks.
Hello,
I am using your JS library for my application, and for me it is GREAT, but I found little problem :(.
I would compare your implementation between Matlab and Python Numpy implementation of FFT calculating.
For FFT magnitude and Real/Imag constellation of FFT it is not possible to find this issue. It was possible only when I try to compute angle of FFT. After comparison with Python and Matlab I think that your FFT and InvFFT methods are swapped. Problem is in line 119 and 157 in (1) +/- sign. I uploaded patch with problem solution, because I don't have access rights to repo.
Regards
Jedrzej
Attachments:
patch.txt
Hi Nick,
I wasn't able to find any contact information for you. I just wanted to ask if you'd be OK with me including a (potentially modified) version of your jsfft library with the Higgs JavaScript VM I'm building. The license you provided would of course be preserved.
We've got a few libraries under the lib directory. We're trying to make this batteries included. Recently I've been playing with sound synthesis and I thought it would be useful to have an FFT lib in there. Might also make a useful benchmark for the performance of Higgs.
Let me know if you're OK with this :)
Have a great day,
I've been trying to use FFT/IFFT to create a spectral drone but haven't had any luck so far. I was inspired by Mammut, a program that allows for whole-sound FFT computation. One of the features of the program is the ability to randomize the phase data, and the output of such randomization is a beautiful drone consisting of all the frequencies smeared together.
I wanted to attempt such an operation in Javascript, and I was hoping your library would do the trick. Here is my initial attempt:
original sample: http://matt-diamond.com/samples/sufjan.wav
experiment: http://matt-diamond.com/fft.html (takes a moment to load)
script: http://matt-diamond.com/js/fft.js
As you can see, the mapping function passed to the frequencyMap
method sets the imaginary component to a random number. I have it dividing that number by 100 because otherwise the output is full of noise (not sure why). As you can hear, the output is kind of weird (partially reversed?) but it isn't the drone I was hoping for.
I was hoping to e-mail you for assistance but didn't see your contact info anyway, so I'm leaving this note here. Maybe I'm just fundamentally misunderstanding FFT/IFFT or what your library does. If you have any advice/pointers on how to achieve the effect I'm looking for, any help would be appreciated.
Hello @dntj,
I am trying to use your package on npm, but there is no code in it haha.
When I build it from your repository and then sneak the dist folder into the module it works fine.
FYI this is breaking meyda @hughrawlinson
Thank you for your sharing。
I apply FFT to image like this:
var afterFFT=fft.FFTImageDataRGBA(imgdata.data,img.width, img.height);
I got imgdata
from a canvas,imgdata.data is consist of rgba(not ComplexArray)。
Then,I got result(ComplexArray with real and imag),it seems right。
I want to apply INVFFT to the result, I try like this:
var beforeFFT=fft.FFTImageDataRGBA(afterFFT, img.width, img.height, 1);
But I got a wrong result:all of value are 0.
How can I apply InvFFT to the afterFFT ?
I reform the fft.FFTImageDataRGBA = function(data, nx, ny)
to:
fft.FFTImageDataRGBA = function(data, nx, ny, isInverse)
Can be closed, I`ve solved the issue
In case someone needs types. There are some unknown parts which I did not have time to explore
declare module "jsfft" {
type Frequency = { real: number; imag: number };
type InputValue = ComplexArray | number[] | number;
type Filterer = (frequency: Frequency, i: number, n: number) => void;
function FFT(input: InputValue): ComplexArray;
function InvFFT(input: InputValue): ComplexArray;
function frequencyMap(input: InputValue, filterer: Filterer): ComplexArray;
class ComplexArray {
constructor(input: InputValue);
length: number;
real: Float32Array;
imag: Float32Array;
ArrayType(args: unknown): Float32Array;
FFT(): ComplexArray;
InvFFT(): ComplexArray;
frequencyMap(filterer: Filterer): ComplexArray;
conjugate(): unknown;
forEach(iterator: Filterer): unknown;
magnitude(): Float32Array;
map(mapper: Filterer): ComplexArray;
toString(): string;
}
}
Hi,
Excuse my ignorance I am new to JavaScript. I am trying to install the jsfft library. I tried using npm install jsfft but I got an error that jsfft cannot be a dependency of itself. Do you know what is going on here or what I could do differently to get this library to install?
Thanks,
Daniel Haverporth
Greetings!
I'm comparing the output of fft.js with MATLAB fft implementation and there are two issues worth nothing:
Take a look at this example: http://pastiebin.com/54c3d0ae2e413
When trying to start the provided example in the browser, the bundle.js referenced in the index.html is missing.
Console Output is:
GET file:///Users/paul.kerspe/Downloads/jsfft-master/example/bundle.js net::ERR_FILE_NOT_FOUND
If you don't mind my asking, how are using FFT in JavaScript?
By way of explanation, I stumbled on your FFT implementation in JavaScript out of curiosity related to another project's interesting use of HTML5 audio capabilities: cobookman/HTML5.MicIO/issues/2
I'm excited to see your work here on GitHub!
Hey there, I'm trying to test this and understand FFTs better, but I am a little stumped. I am generating 1 second of data for a sine wave at 256Hz and 8192 sps, and when I map the result to a -N/2 : N/2, it is is apparently giving me the results in reverse where the peaks are shown at 3840Hz or N/2 - 256. What am I missing here?
var sineWave = [];
var t = [];
var fs = 8192; // Sample rate
var freq = 256; // Generate this frequency
var increment = 1/fs; //x-axis time increment based on sample rate
var sec = 2; //Seconds of data to generate
document.getElementById("freq").innerHTML = freq + " Hz, at "+fs+" samples per sec";
for (var ti = 0; ti < sec-increment; ti+=increment){ //200 sps, 3 sec
var amplitude = Math.sin(2*Math.PI*freq*ti);
//amplitude += Math.sin(2*Math.PI*300*ti); //Add 300Hz interference
sineWave.push(amplitude);
t.push(ti);
}
var fftdata = new ComplexArray(sineWave.length);
fftdata.frequencyMap((value,i) => {
value.real = sineWave[i];
});
console.info(fftdata);
var amplitudeSpectrum = fftdata.magnitude();
var freqDist = [];
for(var i=(-N/2); i<(N/2); i++) {
var freq = i*df;
freqDist.push(freq);
}
// Then plot freqDist vs amplitudeSpectrum
Cheers!
Hey,
Comparing the results with what you can obtain with matlab, I noticed some artifacts in the fft output. For example, it is the case for a 65536 points signal with a rectangular signal of 1/10th of the total width. Some "butterfly" shaped artifacts are visible at high frequencies. Do you have an idea where it is coming from?
Thanks,
Xavier
Hi,
Something I do in python all the time is:
import numpy
signal = [ 1, 1, 1, 1, 0, 0, 0, 0 ]
mags = abs(numpy.fft.fft(signal))[0:len(signal)//2]
print(mags)
# array([ 4. , 2.61312593, 0. , 1.0823922 ])
I'm trying to figure out how to do this here. I've managed to get this to work, but I'm not sure why I have to do it like this.
const fft = require('./dist/fft')
const signal = [ 1, 1, 1, 1, 0, 0, 0, 0 ]
const mags = new fft.ComplexArray(signal.length)
.map((value, index) => {
value.real = signal[index] * 2
value.imag = signal[index] * 2
})
.FFT()
.magnitude()
.slice(0, signal.length / 2)
console.log(mags)
// [ 4, 2.613126039505005, 0, 1.0823922157287598 ]
Why do I have multiply everything by 2? or, needing to set both real / imag components seems wrong too.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.