Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to find the bug(s) in your code. My test code appears to work just fine.</p> <p>Complex-valued forward FFT with floats:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;math.h&gt; #include "kiss_fft.h" #ifndef M_PI #define M_PI 3.14159265358979324 #endif #define N 16 void TestFft(const char* title, const kiss_fft_cpx in[N], kiss_fft_cpx out[N]) { kiss_fft_cfg cfg; printf("%s\n", title); if ((cfg = kiss_fft_alloc(N, 0/*is_inverse_fft*/, NULL, NULL)) != NULL) { size_t i; kiss_fft(cfg, in, out); free(cfg); for (i = 0; i &lt; N; i++) printf(" in[%2zu] = %+f , %+f " "out[%2zu] = %+f , %+f\n", i, in[i].r, in[i].i, i, out[i].r, out[i].i); } else { printf("not enough memory?\n"); exit(-1); } } int main(void) { kiss_fft_cpx in[N], out[N]; size_t i; for (i = 0; i &lt; N; i++) in[i].r = in[i].i = 0; TestFft("Zeroes (complex)", in, out); for (i = 0; i &lt; N; i++) in[i].r = 1, in[i].i = 0; TestFft("Ones (complex)", in, out); for (i = 0; i &lt; N; i++) in[i].r = sin(2 * M_PI * 4 * i / N), in[i].i = 0; TestFft("SineWave (complex)", in, out); return 0; } </code></pre> <p>Output:</p> <pre><code>Zeroes (complex) in[ 0] = +0.000000 , +0.000000 out[ 0] = +0.000000 , +0.000000 in[ 1] = +0.000000 , +0.000000 out[ 1] = +0.000000 , +0.000000 in[ 2] = +0.000000 , +0.000000 out[ 2] = +0.000000 , +0.000000 in[ 3] = +0.000000 , +0.000000 out[ 3] = +0.000000 , +0.000000 in[ 4] = +0.000000 , +0.000000 out[ 4] = +0.000000 , +0.000000 in[ 5] = +0.000000 , +0.000000 out[ 5] = +0.000000 , +0.000000 in[ 6] = +0.000000 , +0.000000 out[ 6] = +0.000000 , +0.000000 in[ 7] = +0.000000 , +0.000000 out[ 7] = +0.000000 , +0.000000 in[ 8] = +0.000000 , +0.000000 out[ 8] = +0.000000 , +0.000000 in[ 9] = +0.000000 , +0.000000 out[ 9] = +0.000000 , +0.000000 in[10] = +0.000000 , +0.000000 out[10] = +0.000000 , +0.000000 in[11] = +0.000000 , +0.000000 out[11] = +0.000000 , +0.000000 in[12] = +0.000000 , +0.000000 out[12] = +0.000000 , +0.000000 in[13] = +0.000000 , +0.000000 out[13] = +0.000000 , +0.000000 in[14] = +0.000000 , +0.000000 out[14] = +0.000000 , +0.000000 in[15] = +0.000000 , +0.000000 out[15] = +0.000000 , +0.000000 Ones (complex) in[ 0] = +1.000000 , +0.000000 out[ 0] = +16.000000 , +0.000000 in[ 1] = +1.000000 , +0.000000 out[ 1] = +0.000000 , +0.000000 in[ 2] = +1.000000 , +0.000000 out[ 2] = +0.000000 , +0.000000 in[ 3] = +1.000000 , +0.000000 out[ 3] = +0.000000 , +0.000000 in[ 4] = +1.000000 , +0.000000 out[ 4] = +0.000000 , +0.000000 in[ 5] = +1.000000 , +0.000000 out[ 5] = +0.000000 , +0.000000 in[ 6] = +1.000000 , +0.000000 out[ 6] = +0.000000 , +0.000000 in[ 7] = +1.000000 , +0.000000 out[ 7] = +0.000000 , +0.000000 in[ 8] = +1.000000 , +0.000000 out[ 8] = +0.000000 , +0.000000 in[ 9] = +1.000000 , +0.000000 out[ 9] = +0.000000 , +0.000000 in[10] = +1.000000 , +0.000000 out[10] = +0.000000 , +0.000000 in[11] = +1.000000 , +0.000000 out[11] = +0.000000 , +0.000000 in[12] = +1.000000 , +0.000000 out[12] = +0.000000 , +0.000000 in[13] = +1.000000 , +0.000000 out[13] = +0.000000 , +0.000000 in[14] = +1.000000 , +0.000000 out[14] = +0.000000 , +0.000000 in[15] = +1.000000 , +0.000000 out[15] = +0.000000 , +0.000000 SineWave (complex) in[ 0] = +0.000000 , +0.000000 out[ 0] = +0.000000 , +0.000000 in[ 1] = +1.000000 , +0.000000 out[ 1] = +0.000000 , +0.000000 in[ 2] = +0.000000 , +0.000000 out[ 2] = +0.000000 , +0.000000 in[ 3] = -1.000000 , +0.000000 out[ 3] = +0.000000 , +0.000000 in[ 4] = +0.000000 , +0.000000 out[ 4] = +0.000000 , -8.000000 in[ 5] = +1.000000 , +0.000000 out[ 5] = +0.000000 , +0.000000 in[ 6] = +0.000000 , +0.000000 out[ 6] = +0.000000 , +0.000000 in[ 7] = -1.000000 , +0.000000 out[ 7] = +0.000000 , +0.000000 in[ 8] = +0.000000 , +0.000000 out[ 8] = +0.000000 , +0.000000 in[ 9] = +1.000000 , +0.000000 out[ 9] = +0.000000 , +0.000000 in[10] = +0.000000 , +0.000000 out[10] = +0.000000 , +0.000000 in[11] = -1.000000 , +0.000000 out[11] = +0.000000 , +0.000000 in[12] = +0.000000 , +0.000000 out[12] = +0.000000 , +8.000000 in[13] = +1.000000 , +0.000000 out[13] = +0.000000 , +0.000000 in[14] = +0.000000 , +0.000000 out[14] = +0.000000 , +0.000000 in[15] = -1.000000 , +0.000000 out[15] = +0.000000 , +0.000000 </code></pre> <p>Real-valued forward FFT with floats:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;math.h&gt; #include "kiss_fftr.h" #ifndef M_PI #define M_PI 3.14159265358979324 #endif #define N 16 void TestFftReal(const char* title, const kiss_fft_scalar in[N], kiss_fft_cpx out[N / 2 + 1]) { kiss_fftr_cfg cfg; printf("%s\n", title); if ((cfg = kiss_fftr_alloc(N, 0/*is_inverse_fft*/, NULL, NULL)) != NULL) { size_t i; kiss_fftr(cfg, in, out); free(cfg); for (i = 0; i &lt; N; i++) { printf(" in[%2zu] = %+f ", i, in[i]); if (i &lt; N / 2 + 1) printf("out[%2zu] = %+f , %+f", i, out[i].r, out[i].i); printf("\n"); } } else { printf("not enough memory?\n"); exit(-1); } } int main(void) { kiss_fft_scalar in[N]; kiss_fft_cpx out[N / 2 + 1]; size_t i; for (i = 0; i &lt; N; i++) in[i] = 0; TestFftReal("Zeroes (real)", in, out); for (i = 0; i &lt; N; i++) in[i] = 1; TestFftReal("Ones (real)", in, out); for (i = 0; i &lt; N; i++) in[i] = sin(2 * M_PI * 4 * i / N); TestFftReal("SineWave (real)", in, out); return 0; } </code></pre> <p>Output:</p> <pre><code>Zeroes (real) in[ 0] = +0.000000 out[ 0] = +0.000000 , +0.000000 in[ 1] = +0.000000 out[ 1] = +0.000000 , +0.000000 in[ 2] = +0.000000 out[ 2] = +0.000000 , +0.000000 in[ 3] = +0.000000 out[ 3] = +0.000000 , +0.000000 in[ 4] = +0.000000 out[ 4] = +0.000000 , +0.000000 in[ 5] = +0.000000 out[ 5] = +0.000000 , +0.000000 in[ 6] = +0.000000 out[ 6] = +0.000000 , +0.000000 in[ 7] = +0.000000 out[ 7] = +0.000000 , +0.000000 in[ 8] = +0.000000 out[ 8] = +0.000000 , +0.000000 in[ 9] = +0.000000 in[10] = +0.000000 in[11] = +0.000000 in[12] = +0.000000 in[13] = +0.000000 in[14] = +0.000000 in[15] = +0.000000 Ones (real) in[ 0] = +1.000000 out[ 0] = +16.000000 , +0.000000 in[ 1] = +1.000000 out[ 1] = +0.000000 , +0.000000 in[ 2] = +1.000000 out[ 2] = +0.000000 , +0.000000 in[ 3] = +1.000000 out[ 3] = +0.000000 , +0.000000 in[ 4] = +1.000000 out[ 4] = +0.000000 , +0.000000 in[ 5] = +1.000000 out[ 5] = +0.000000 , +0.000000 in[ 6] = +1.000000 out[ 6] = +0.000000 , +0.000000 in[ 7] = +1.000000 out[ 7] = +0.000000 , +0.000000 in[ 8] = +1.000000 out[ 8] = +0.000000 , +0.000000 in[ 9] = +1.000000 in[10] = +1.000000 in[11] = +1.000000 in[12] = +1.000000 in[13] = +1.000000 in[14] = +1.000000 in[15] = +1.000000 SineWave (real) in[ 0] = +0.000000 out[ 0] = +0.000000 , +0.000000 in[ 1] = +1.000000 out[ 1] = +0.000000 , +0.000000 in[ 2] = +0.000000 out[ 2] = +0.000000 , +0.000000 in[ 3] = -1.000000 out[ 3] = +0.000000 , +0.000000 in[ 4] = +0.000000 out[ 4] = +0.000000 , -8.000000 in[ 5] = +1.000000 out[ 5] = +0.000000 , +0.000000 in[ 6] = +0.000000 out[ 6] = +0.000000 , +0.000000 in[ 7] = -1.000000 out[ 7] = +0.000000 , +0.000000 in[ 8] = +0.000000 out[ 8] = +0.000000 , +0.000000 in[ 9] = +1.000000 in[10] = +0.000000 in[11] = -1.000000 in[12] = +0.000000 in[13] = +1.000000 in[14] = +0.000000 in[15] = -1.000000 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload