title: FFT outptut for a signal with 2 cosf() cycles
body: <p>I am transforming a signal using the <a href="https://github.com/adafruit/Adafruit_ZeroFFT" rel="nofollow noreferrer">ZeroFFT</a> library. The results I get from it, are not what I would intuitively expect.</p>
  <p>As a test, I feed the FFT algorithm with a buffer that contains two full cycles of cosine:</p>
  <p><a href="https://i.stack.imgur.com/C3TNj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C3TNj.png" alt="enter image description here" /></a></p>
  <p>Which is sampled over 512 samples.</p>
  <p>Which are fed as <code>int16_t</code> values. What I expected to get back, is 256 amplitudes, with the values <code>[ 0, 4095, 0, 0, ..., 0 ]</code>.</p>
  <p>Instead, this is the result:
  <code>2 2052 4086 2053 0 2 2 2 1 2 2 2 4 4 3 4...</code></p>
  <p>And it gets weirder! If I feed it the <strong>same signal, but shifted</strong> (so <code>sinf()</code> over 0 .. 4*pi instead of <code>cosf()</code> function) I get a completely different result: <code>4 10 2 16 2 4 4 4 2 2 2 3 2 4 3 4</code></p>
  <p>This throws up the questions:</p>
  <p><strong>1</strong>. Doesn't a sine signal and cosine signal with same period, contain exactly the same frequencies?</p>
  <p><strong>2</strong>. If I feed it a buffer with exactly 2 cycles of cosine, wouldn't the Fourier transform result in all zeros, except for 1 frequency?</p>
  <p>I generate my test signal as:</p>
  <pre><code>static void setup_reference(void)
  {
    for (int i=0; i&lt;CAPTURESZ; ++i)
    {
      const float phase = 2 * 3.14159f * i / (256.0f);
      reference_wave[i] = (int16_t) (cosf(phase) * 0x7fff);
    }
  }
  </code></pre>
  <p>And call the <a href="https://github.com/adafruit/Adafruit_ZeroFFT/blob/master/Adafruit_ZeroFFT.h#L56" rel="nofollow noreferrer">ZeroFFT function</a> as:</p>
  <pre><code>ZeroFFT(reference_Wave, CAPTURESZ);
  </code></pre>
  <p>Note: the ZeroFFT docs state that a Hanning window is applied.</p>