OpenWareLaboratory
FastFourierTransform.cpp
Go to the documentation of this file.
1 #include "FastFourierTransform.h"
2 #include "message.h"
3 #include "ProgramVector.h"
4 #include "ServiceCall.h"
5 
6 #ifdef ARM_CORTEX
8 
10  init(len);
11 }
12 
14 
15 void FastFourierTransform::init(size_t len){
16  ASSERT(len==32 || len ==64 || len==128 || len==256 || len==512 || len==1024 || len==2048 || len==4096, "Unsupported FFT size");
17  void* args[] = {(void*)&instance, (void*)&len};
18  int ret = getProgramVector()->serviceCall(OWL_SERVICE_ARM_RFFT_FAST_INIT_F32, args, 2);
19  ASSERT(ret == OWL_SERVICE_OK, "FFT init failed");
20  // arm_rfft_fast_init_f32(&instance, len);
21  // Supported FFT Lengths are 32, 64, 128, 256, 512, 1024, 2048, 4096.
22 }
23 
25  ASSERT(in.getSize() >= getSize(), "Input array too small");
26  ASSERT(out.getSize() >= getSize()/2, "Output array too small");
27  arm_rfft_fast_f32(&instance, (float*)in.getData(), (float*)out.getData(), 0);
28 }
29 
31  ASSERT(in.getSize() >= getSize()/2, "Input array too small");
32  ASSERT(out.getSize() >= getSize(), "Output array too small");
33  arm_rfft_fast_f32(&instance, (float*)in.getData(), (float*)out.getData(), 1);
34 }
35 
37  return instance.fftLenRFFT;
38 }
39 
40 #else /* ARM_CORTEX */
41 
43 
45  init(aSize);
46 }
47 
49  free(cfgfft);
50  free(cfgifft);
52 }
53 
54 void FastFourierTransform::init(size_t aSize){
55  ASSERT(aSize==32 || aSize ==64 || aSize==128 || aSize==256 || aSize==512 || aSize==1024 || aSize==2048 || aSize==4096, "Unsupported FFT size");
56  cfgfft = kiss_fft_alloc(aSize, 0 , 0, 0);
57  cfgifft = kiss_fft_alloc(aSize, 1,0, 0);
58  temp = ComplexFloatArray::create(aSize);
59 }
60 
62  ASSERT(input.getSize() >= getSize(), "Input array too small");
63  ASSERT(output.getSize() >= getSize(), "Output array too small");
64  for(size_t n=0; n<getSize(); n++){
65  temp[n].re=input[n];
66  temp[n].im=0;
67  }
68  kiss_fft(cfgfft, (kiss_fft_cpx*)(float*)temp.getData(), (kiss_fft_cpx*)(float*)output.getData());
69 }
70 
72  ASSERT(input.getSize() >= getSize(), "Input array too small");
73  ASSERT(output.getSize() >= getSize(), "Output array too small");
74  kiss_fft(cfgifft, (kiss_fft_cpx*)(float*)input.getData(), (kiss_fft_cpx*)(float*)temp.getData());
75  float scale=1.0f/getSize();
76  for(size_t n=0; n<getSize(); n++){
77  output[n]=temp[n].re*scale;
78  }
79 }
80 
82  return temp.getSize();
83 }
84 
85 #endif /* ifndef ARM_CORTEX */
86 
88  return new FastFourierTransform(blocksize);
89 }
90 
92  delete obj;
93 }
float im(const int i)
Get the imaginary part of an element of the array.
static void destroy(ComplexFloatArray)
Destroys a ComplexFloatArray created with the create() method.
static ComplexFloatArray create(size_t size)
Creates a new ComplexFloatArray.
float re(const int i)
Get the real part of an element of the array.
This class performs direct and inverse Fast Fourier Transform.
size_t getSize()
Get the size of the FFT.
void init(size_t aSize)
Initialize the instance.
void ifft(ComplexFloatArray input, FloatArray output)
Perform the inverse FFT.
static FastFourierTransform * create(size_t blocksize)
static void destroy(FastFourierTransform *obj)
FastFourierTransform()
Default constructor.
void fft(FloatArray input, ComplexFloatArray output)
Perform the direct FFT.
This class contains useful methods for manipulating arrays of floats.
Definition: FloatArray.h:12
size_t getSize() const
Definition: SimpleArray.h:31
T * getData()
Get the data stored in the Array.
Definition: SimpleArray.h:27
#define ASSERT(cond, msg)
Definition: message.h:16