Mercurial > hg > batch-feature-extraction-tool
annotate Source/FFTW.h @ 14:636c989477e7
XML changes for Public.
author | Geogaddi\David <d.m.ronan@qmul.ac.uk> |
---|---|
date | Wed, 04 May 2016 11:02:59 +0100 |
parents | fdc592312a96 |
children | 585caf503ef5 |
rev | line source |
---|---|
d@14 | 1 /* |
d@14 | 2 ============================================================================== |
d@1 | 3 |
d@14 | 4 FFTW.cpp |
d@14 | 5 Created: 29 Oct 2014 6:30:26pm |
d@14 | 6 Author: david.ronan |
d@1 | 7 |
d@14 | 8 ============================================================================== |
d@14 | 9 */ |
d@0 | 10 #pragma once |
d@0 | 11 |
d@0 | 12 #include "fftw3.h" |
d@8 | 13 #include <vector> |
d@14 | 14 |
d@0 | 15 |
d@0 | 16 |
d@0 | 17 |
d@0 | 18 class FFTW |
d@0 | 19 { |
d@0 | 20 |
d@0 | 21 public: |
d@0 | 22 fftwf_plan m_plan; |
d@0 | 23 unsigned m_iFFTSize; |
d@0 | 24 |
d@1 | 25 FFTW(); |
d@0 | 26 FFTW( unsigned fftLength ) |
d@0 | 27 { |
d@0 | 28 m_iFFTSize = fftLength; |
d@0 | 29 |
d@4 | 30 std::vector<float> tempInput = std::vector<float>(fftLength, 0); |
d@4 | 31 std::vector<float> tempReal = std::vector<float>(fftLength, 0); |
d@4 | 32 std::vector<float> tempImag = std::vector<float>(fftLength, 0); |
d@4 | 33 |
d@4 | 34 |
d@0 | 35 fftwf_iodim dim; |
d@0 | 36 dim.n = fftLength; |
d@0 | 37 dim.is = 1; |
d@0 | 38 dim.os = 1; |
d@4 | 39 m_plan = fftwf_plan_guru_split_dft_r2c( 1, &dim, 0, nullptr, tempInput.data(), tempReal.data(), tempImag.data(), FFTW_ESTIMATE ); |
d@0 | 40 } |
d@0 | 41 |
d@0 | 42 |
d@0 | 43 ~FFTW() |
d@0 | 44 { |
d@3 | 45 if(m_plan != nullptr) |
d@0 | 46 { |
d@0 | 47 fftwf_destroy_plan( m_plan ); |
d@0 | 48 } |
d@0 | 49 } |
d@0 | 50 |
d@0 | 51 |
d@4 | 52 void process(std::vector<float> input, std::vector<float> &realPart, std::vector<float> &imagPart) |
d@0 | 53 { |
d@4 | 54 |
d@4 | 55 fftwf_execute_split_dft_r2c( m_plan, input.data(), realPart.data(), imagPart.data()); |
d@0 | 56 |
d@0 | 57 //Multiply results by 2 to match the iOS output |
d@0 | 58 for(size_t i = 0; i < m_iFFTSize; i++) |
d@1 | 59 { |
d@0 | 60 realPart[i] *= 2.f; |
d@0 | 61 imagPart[i] *= 2.f; |
d@0 | 62 } |
d@0 | 63 } |
d@0 | 64 |
d@0 | 65 }; |
d@0 | 66 |