fft.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. ESP32 FFT
  3. =========
  4. This provides a vanilla radix-2 FFT implementation and a test example.
  5. Author
  6. ------
  7. This code was written by [Robin Scheibler](http://www.robinscheibler.org) during rainy days in October 2017.
  8. License
  9. -------
  10. Copyright (c) 2017 Robin Scheibler
  11. Permission is hereby granted, free of charge, to any person obtaining a copy
  12. of this software and associated documentation files (the "Software"), to deal
  13. in the Software without restriction, including without limitation the rights
  14. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15. copies of the Software, and to permit persons to whom the Software is
  16. furnished to do so, subject to the following conditions:
  17. The above copyright notice and this permission notice shall be included in all
  18. copies or substantial portions of the Software.
  19. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  25. SOFTWARE.
  26. */
  27. #ifndef __FFT_H__
  28. #define __FFT_H__
  29. typedef enum
  30. {
  31. FFT_REAL,
  32. FFT_COMPLEX
  33. } fft_type_t;
  34. typedef enum
  35. {
  36. FFT_FORWARD,
  37. FFT_BACKWARD
  38. } fft_direction_t;
  39. #define FFT_OWN_INPUT_MEM 1
  40. #define FFT_OWN_OUTPUT_MEM 2
  41. typedef struct
  42. {
  43. int size; // FFT size
  44. float *input; // pointer to input buffer
  45. float *output; // pointer to output buffer
  46. float *twiddle_factors; // pointer to buffer holding twiddle factors
  47. fft_type_t type; // real or complex
  48. fft_direction_t direction; // forward or backward
  49. unsigned int flags; // FFT flags
  50. } fft_config_t;
  51. fft_config_t *fft_init(int size, fft_type_t type, fft_direction_t direction, float *input, float *output);
  52. void fft_destroy(fft_config_t *config);
  53. void fft_execute(fft_config_t *config);
  54. void fft(float *input, float *output, float *twiddle_factors, int n);
  55. void ifft(float *input, float *output, float *twiddle_factors, int n);
  56. void rfft(float *x, float *y, float *twiddle_factors, int n);
  57. void irfft(float *x, float *y, float *twiddle_factors, int n);
  58. void fft_primitive(float *x, float *y, int n, int stride, float *twiddle_factors, int tw_stride);
  59. void split_radix_fft(float *x, float *y, int n, int stride, float *twiddle_factors, int tw_stride);
  60. void ifft_primitive(float *input, float *output, int n, int stride, float *twiddle_factors, int tw_stride);
  61. void fft8(float *input, int stride_in, float *output, int stride_out);
  62. void fft4(float *input, int stride_in, float *output, int stride_out);
  63. #endif // __FFT_H__