Home

Awesome

fft.hpp

Public-domain single-header library implementing radix-2 decimation-in-time FFT (i.e. FFT for powers of 2)

This software is dual-licensed to the public domain and under the following license: you are granted a perpetual, irrevocable license to copy, modify, publish, and distribute this file as you see fit.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

fft_core

(in_real[], in_imag[], size, gap, out_real[], out_imag[], forwards)

For a 8-sample input, the FFT's last three bins contain "negative" frequencies. (So, the last (size/2)-1 bins.) They are only meaningful for complex inputs.

Only does the hard part, which means that the output will be louder if you keep applying this recursively.

fft

(<same as fft_core, sans [gap] and [forwards]>)

ifft

(<same as fft_core, sans [gap] and [forwards]>)

normalize_fft

(in_real[], in_imag[], size)

half_normalize_fft

(in_real[], in_imag[], size)

You may want to normalize by sqrt(size), but if so, that's up to you. Just copy the code or make your own.

sanitize_fft

(in_real[], in_imag[], size)

unsanitize_fft

(in_real[], in_imag[], size)