Ensure RFFT spectrum is always positive
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 ]
@corbanbrook is there anything on that?
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!
@corbanbrook is there any chance it will be merged? If no, I suggest closing this PR