comparison data/fft/FFTapi.h @ 1091:bdebff3265ae simple-fft-model

Simplest naive FFTModel implementation (+ fill in tests)
author Chris Cannam
date Fri, 12 Jun 2015 18:08:57 +0100
parents 7c53640bb9ba
children 44b079427b36
comparison
equal deleted inserted replaced
1090:420fc961c0c4 1091:bdebff3265ae
48 #define FFTW_ESTIMATE 0 48 #define FFTW_ESTIMATE 0
49 #define FFTW_MEASURE 0 49 #define FFTW_MEASURE 0
50 50
51 #endif 51 #endif
52 52
53 #include <vector>
54 #include <complex>
55
56 class FFTForward // with fft shift but not window
57 {
58 public:
59 FFTForward(int size) :
60 m_size(size),
61 m_input((float *)fftf_malloc(size * sizeof(float))),
62 m_output((fftf_complex *)fftf_malloc((size/2 + 1) * sizeof(fftf_complex))),
63 m_plan(fftf_plan_dft_r2c_1d(size, m_input, m_output, FFTW_MEASURE))
64 { }
65
66 ~FFTForward() {
67 fftf_destroy_plan(m_plan);
68 fftf_free(m_input);
69 fftf_free(m_output);
70 }
71
72 std::vector<std::complex<float> > process(std::vector<float> in) const {
73 const int hs = m_size/2;
74 for (int i = 0; i < hs; ++i) {
75 m_input[i] = in[i + hs];
76 m_input[i + hs] = in[i];
77 }
78 fftf_execute(m_plan);
79 std::vector<std::complex<float> > result;
80 result.reserve(hs + 1);
81 for (int i = 0; i <= hs; ++i) {
82 result[i] = { m_output[i][0], m_output[i][1] };
83 }
84 return result;
85 }
86
87 private:
88 int m_size;
89 float *m_input;
90 fftf_complex *m_output;
91 fftf_plan m_plan;
92 };
93
53 #endif 94 #endif
54 95