OpenWareLaboratory
ShortFastFourierTransform.cpp
Go to the documentation of this file.
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 ShortFastFourierTransform::init(int aSize){
16  len = aSize;
17  ASSERT(len==32 || len ==64 || len==128 || len==256 || len==512 || len==1024 || len==2048 || len==4096, "Unsupported FFT size");
18  // Supported FFT Lengths are 32, 64, 128, 256, 512, 1024, 2048, 4096.
19 }
20 
22  ASSERT(in.getSize() >= getSize(), "Input array too small");
23  ASSERT(out.getSize() >= getSize(), "Output array too small");
24  arm_rfft_init_q15(&instance, len, 0, 1);
25  arm_rfft_q15(&instance, (int16_t*)in.getData(), (int16_t*)out.getData());
26 }
27 
29  ASSERT(in.getSize() >= getSize(), "Input array too small");
30  ASSERT(out.getSize() >= getSize(), "Output array too small");
31  arm_rfft_init_q15(&instance, len, 1, 1);
32  arm_rfft_q15(&instance, (int16_t*)in.getData(), (int16_t*)out.getData());
33 }
34 
36  return len;
37 }
38 
39 #else /* ARM_CORTEX */
40 
42 
44  init(aSize);
45 }
46 
48  ASSERT(false, "TODO");
50 }
51 
53  ASSERT(aSize==32 || aSize ==64 || aSize==128 || aSize==256 || aSize==512 || aSize==1024 || aSize==2048 || aSize==4096, "Unsupported FFT size");
54  cfgfft = kiss_fft_alloc(aSize, 0 , 0, 0);
55  cfgifft = kiss_fft_alloc(aSize, 1,0, 0);
57 }
58 
60  ASSERT(input.getSize() >= getSize(), "Input array too small");
61  ASSERT(output.getSize() >= getSize(), "Output array too small");
62  for(size_t n=0; n<getSize(); n++){
63  temp[n].re=input[n];
64  temp[n].im=0;
65  }
66  kiss_fft(cfgfft, (kiss_fft_cpx*)(int16_t*)temp.getData(), (kiss_fft_cpx*)(int16_t*)output.getData());
67 }
68 
70  ASSERT(input.getSize() >= getSize(), "Input array too small");
71  ASSERT(output.getSize() >= getSize(), "Output array too small");
72  kiss_fft(cfgifft, (kiss_fft_cpx*)(int16_t*)input.getData(), (kiss_fft_cpx*)(int16_t*)temp.getData());
73  float scale=1.0f/getSize();
74  for(size_t n=0; n<getSize(); n++){
75  output[n]=temp[n].re*scale;
76  }
77 }
78 
80  return temp.getSize();
81 }
82 
83 #endif /* ifndef ARM_CORTEX */
int16_t im(const int i)
The imaginary part of an element of the array.
static ComplexShortArray create(unsigned int size)
Creates a new ComplexShortArray.
static void destroy(ComplexShortArray)
Destroys a ComplexShortArray created with the create() method.
int16_t re(const int i)
The real part of an element of the array.
This class contains useful methods for manipulating arrays of int16_ts.
Definition: ShortArray.h:12
size_t getSize()
Get the size of the FFT.
void ifft(ComplexShortArray input, ShortArray output)
Perform the inverse FFT.
ShortFastFourierTransform()
Default constructor.
void init(int aSize)
Initialize the instance.
void fft(ShortArray input, ComplexShortArray output)
Perform the direct FFT.
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