ccrma / chuck

ChucK Music Programming Language
http://chuck.stanford.edu/
GNU General Public License v2.0
803 stars 128 forks source link

incorrect/missing FFT behavior and documentation #382

Open gewang opened 11 months ago

gewang commented 11 months ago

from discord (c/o rwixen) "The FFT unit analyzer appears to round up the FFT size to the next power of two. It would be nice if the documentation reflected this. It would also be nice if the documentation said that the output is half the size of the FFT, containing only the frequencies below the Nyquist frequency."

"The FFT unit analyzer's .cvals() array is always size 8 when I use the transform(float[] from), regardless of the FFT size. When I instead use upchuck(), the size of the .cvals() array is appropriately half of the (power-of-two) FFT size."

"The FFT unit analyzer seems to be giving an incorrect output for an impulse input, for which the expected output should be constant. Instead, the output has a larger value for DC than for other frequencies. The attached file surfaces the issue."

Impulse impulse => FFT fft => blackhole;
impulse => Flip flip => blackhole;

8 => int N;
N => fft.size;
N => flip.size;

impulse.next(1);
N::samp => now;
fft.upchuck();
flip.upchuck();

<<<"x[n]">>>;
for (0 => int i; i < N; 1 +=> i) {
    <<<i, flip.fval(i)>>>;
}

<<<"X[n]">>>;
for (0 => int i; i < N / 2; 1 +=> i) {
    <<<i, fft.fval(i)>>>;
}