fourier.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*============================================================================
  2. fourier.h - Don Cross <dcross@intersrv.com>
  3. http://www.intersrv.com/~dcross/fft.html
  4. Contains definitions for doing Fourier transforms
  5. and inverse Fourier transforms.
  6. ============================================================================*/
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. /*
  11. ** fft() computes the Fourier transform or inverse transform
  12. ** of the complex inputs to produce the complex outputs.
  13. ** The number of samples must be a power of two to do the
  14. ** recursive decomposition of the FFT algorithm.
  15. ** See Chapter 12 of "Numerical Recipes in FORTRAN" by
  16. ** Press, Teukolsky, Vetterling, and Flannery,
  17. ** Cambridge University Press.
  18. **
  19. ** Notes: If you pass ImaginaryIn = NULL, this function will "pretend"
  20. ** that it is an array of all zeroes. This is convenient for
  21. ** transforming digital samples of real number data without
  22. ** wasting memory.
  23. */
  24. void fft_double (
  25. unsigned NumSamples, /* must be a power of 2 */
  26. int InverseTransform, /* 0=forward FFT, 1=inverse FFT */
  27. double *RealIn, /* array of input's real samples */
  28. double *ImaginaryIn, /* array of input's imag samples */
  29. double *RealOut, /* array of output's reals */
  30. double *ImaginaryOut ); /* array of output's imaginaries */
  31. void fft_float (
  32. unsigned NumSamples, /* must be a power of 2 */
  33. int InverseTransform, /* 0=forward FFT, 1=inverse FFT */
  34. float *RealIn, /* array of input's real samples */
  35. float *ImaginaryIn, /* array of input's imag samples */
  36. float *RealOut, /* array of output's reals */
  37. float *ImaginaryOut ); /* array of output's imaginaries */
  38. int IsPowerOfTwo ( unsigned x );
  39. unsigned NumberOfBitsNeeded ( unsigned PowerOfTwo );
  40. unsigned ReverseBits ( unsigned index, unsigned NumBits );
  41. /*
  42. ** The following function returns an "abstract frequency" of a
  43. ** given index into a buffer with a given number of frequency samples.
  44. ** Multiply return value by sampling rate to get frequency expressed in Hz.
  45. */
  46. double Index_to_frequency ( unsigned NumSamples, unsigned Index );
  47. #ifdef __cplusplus
  48. }
  49. #endif
  50. /*--- end of file fourier.h ---*/