View Single Post
Old 12-07-2015, 02:46 PM   #4
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,652
Default

Quote:
Originally Posted by clepsydrae View Post
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?
JSFX's fft(buf, n) takes n complex pairs as input, and also produces n complex pairs. If you want to input a real signal, then you need to convert it to complex first by setting the imaginary part to 0:

Code:
i = 0;
loop(n,
  complex_buf[2*i] = real_buf[i];
  complex_buf[2*i+1] = 0;
  i += 1;
);

fft(complex_buf, n);
fft_permute(complex_buf, n);
Quote:
Originally Posted by clepsydrae View Post
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?
Yeah, that sounds about right.

Quote:
Originally Posted by clepsydrae View Post
And magnitude would be sqrt(results[2*i]^2 + results[2*i+1]^2), and would range from 0 to 1?
Yes, except I think its range is 0 to +inf.

Quote:
Originally Posted by clepsydrae View Post
maybe fft() returns the values as <imaginary, real> ?
Nope, re=buf[2*i], im=buf[2*i+1].
Tale is offline   Reply With Quote