Code Monkey home page Code Monkey logo

jsfft's People

Contributors

dntj avatar hughrawlinson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsfft's Issues

ToDo in fft.js

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...

Support lts/argon (Node v4)

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.

FFT vs InvFFT issue.

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
euler
DFTvsIFT

Bundling jsfft with Higgs?

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,

  • Max

Doesn't work as expected (I think?)

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.

How to apply InvFFT to image?

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)

Some types

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;
  }
}

How to install jsfft

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

Scale and Sign of the real and imaginary parts

Greetings!

I'm comparing the output of fft.js with MATLAB fft implementation and there are two issues worth nothing:

  • The imaginary part sign, in fft.js, is always different from the "golden standard" (MATLAB).
  • The scale of both imaginary and real parts, in fft.js, appears to be already scaled by (1/sampleRate).

Take a look at this example: http://pastiebin.com/54c3d0ae2e413

Example not working, missing bundle.js

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

Use Case for FFT in JavaScript?

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!

amplitude spectrum distribution

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

sine
hmmm

Cheers!

Different results compare to Matlab's fft

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

fft doesn't seem accurate compared to other libs

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.