dsp.js icon indicating copy to clipboard operation
dsp.js copied to clipboard

Ensure RFFT spectrum is always positive

Open dy opened this issue 9 years ago • 3 comments

Hi @corbanbrook! The RFFT forward transform sometimes exhibits negative spectrum value for a static item. That is because of not really measuring the length of phasor as in the loop above, but supposition that zero frequency has positive value, which is not always true. e.g.

var N = 16;
var real = new Float32Array(N);
for (var i = 0; i < N; i++) {
    real[i] = Math.sin(10000 * (i / N) / (Math.PI * 2))
}

var dsp = require('dsp.js');
var fft = new dsp.RFFT(N, 44100);
fft.forward(real);
console.log(fft.spectrum);

gives

 Float32Array [
-0.2007274180650711,
0.29625651240348816,
0.6431688070297241,
0.628587007522583,
0.10844749957323074,
0.04224899411201477,
0.016048559918999672,
0.013186296448111534 ]

dy avatar May 14 '16 17:05 dy

@corbanbrook is there anything on that?

dy avatar Sep 25 '16 19:09 dy

Hi @dfcreative

I'm learning dsp and, since this library is now unmaintained, building my own dsp library taking parts from different projects. I would like to adopt rfft as the default FFT method (because of performance) but I found several issues. Take a look my comments to: https://github.com/corbanbrook/dsp.js/pull/5

Maybe you can give me some clues about that...

Thanks!

danigb avatar Jan 14 '17 09:01 danigb

@corbanbrook is there any chance it will be merged? If no, I suggest closing this PR

dy avatar Jun 21 '17 01:06 dy