So, trying to wrap my head around FFT.
A basic DFT takes n samples and converts to n complex result values, where the frequency represented by each slot is given by n/windowsize*srate, and with an audio input signal it only makes sense to look up to result slot n/2 as the values above would not be useful... right?
So, do I understand correctly that a series of real values as input (e.g. audio signal) still generates a series of complex values on output, but that in audio we don't generally care about the upper half of the output values?
If so, is it the case that the JS function that reaper provides -- fft() -- takes n real samples and produces n/2 pairs of result values in the same buffer, where the first is the real component and the second is the imaginary?
Thus after calling fft_permute, the 0'th pair (indices 0 and 1) is <dc_component, 0> and thereafter the i'th pair (indices 2*i and 2*i+1) where i goes from 1 to windowsize/2 - 1 is the <real, imaginary> FFT value of the signal at frequency i/windowsize*srate ? No fencepost errors there?
And magnitude would be sqrt(results[2*i]^2 + results[2*i+1]^2), and would range from 0 to 1?
I have read that phase is inverse_tan(imag/real), but in the JS I see
ang= -atan2(aa,bb);
where aa is the first results value and bb is the second... i assume the negation is just there for screen drawing purposes, but I would have expected (bb,aa) -- maybe fft() returns the values as <imaginary, real> ? Actually, it's looking increasingly like a bug in the JS.
Update: yep, pretty sure; afaict -atan2(bb,aa) would be correct there. And yes, the - sign is just for drawing.
Last one: arctan only ranges from -pi/2 to pi/2, but you'd need a total of 2*pi range (+/- 1*pi) to express all possible phase shifting... I would guess that when the real part is < 0 I need to add pi to the result to get the actual phase? So that would properly be something like:
ang = atan2(bb,aa) + (aa < 0 ? 3.1415926 : 0);
Yeah?
Thanks in advance for any help!