Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input type #7

Open
RogerMito opened this issue Jul 13, 2018 · 2 comments
Open

Input type #7

RogerMito opened this issue Jul 13, 2018 · 2 comments

Comments

@RogerMito
Copy link

Hello guys.

I'm tryng use the lib with an array containing vibration values (mm/s or g).
For example, I have the following input:
[10, 0.8285441, 0.69100095, 1.0226318, 0.7041154, 1.51439095] ...
But when I try to do:

let fft2 = require('fft-js').fft;
let y = fft2(signal);
console.log(y);

Nothing happens (there is no output). I guess that the library isn't working for me.
I found into README.md file the following: "The following code assumes a complex number is
an array: [real, imaginary]", that way, I'll need to get the real and imaginay parts of my original input?

Could you help me?

Thanks and congratulations by the project.

@borodadada
Copy link

borodadada commented May 12, 2020

yes, i try use value from -1 to 1,

let signal = []
for (let i = 1; i < 100; i++) {
    signal.push( Math.sin( i/10 ) )
}

const phasors = fft(signal)

node_modules\fft-js\src\complex.js:24
    return [(a[0] * b[0] - a[1] * b[1]),

TypeError: Cannot read property '0' of undefined

@TeHMoroS
Copy link

TeHMoroS commented Jun 12, 2020

That's because almost all implementation of FFT in JavaScript I came across have an assumption that everyone is working with integers (DSP anyone?). That very assumption makes people implement bit shifting using bit operators, which clearly don't work well with floating point numbers.

FFT requires that samples be arranged in a specific way (by bit reversal), but reversing bits isn't the only way to accomplish that. A floating-friendly way is bit reversal sorting only through simple index manipulation (it requires that the amount of items to sort is always a power of 2).
A BASIC example of FFT with that bit reversal sorting is shown here (I've already reimplemented it in JS and it works nicely with floats): http://www.dspguide.com/graphics/T_12_4.gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants