forked from SvenDeSmet/ESTL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFFT.h
86 lines (69 loc) · 2.79 KB
/
FFT.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* The information in this file is
* Copyright (C) 2011, Sven De Smet <[email protected]>
* and is subject to the terms and conditions of the
* GNU Lesser General Public License Version 2.1
* The license text is available from
* http://www.gnu.org/licenses/lgpl.html
*/
#ifndef FFT_H
#define FFT_H
#include "Complex.h"
#include <stdio.h>
#include <string>
#include <DataInterface.h>
typedef std::string streng;
template <class D> class FFT {
protected:
public:
typedef D DataType;
DataInterface<D>* dataInterface;
int size, batchCount;
FFT(int iSize, int iBatchCount) : dataInterface(NULL), size(iSize), batchCount(iBatchCount) { }
virtual ~FFT() { delete dataInterface; }
static int getMaxBatchSize(int n) { return 1; }
inline void setData(int index, Complex<D> value, int batchIndex = 0) { dataInterface->setElement(batchIndex*size + index, value); }
inline Complex<D> getData(int index, int batchIndex = 0) { return dataInterface->getElement(batchIndex*size + index); }
virtual void execute() = 0;
};
template <class D> class FFTFactory {
public:
virtual streng getName() = 0;
virtual int getVersion() { return 0; }
virtual FFT<D>* newFFT(int n, bool forward = true, int batchSize = 1) = 0;
virtual int getMaxBatchSize(int n) { return 1; }
};
template <class FFTClass> class FFTFactorySpecific : public FFTFactory<typename FFTClass::DataType> {
typedef typename FFTClass::DataType D;
public:
virtual streng getName() { return FFTClass::getName(); }
virtual int getMaxBatchSize(int n) { return FFTClass::getMaxBatchSize(n); }
virtual FFT<D>* newFFT(int n, bool forward = true, int batchSize = 1) { return (FFT<D>*) new FFTClass(n, forward, batchSize); }
};
template <class D> class FFT2D {
public:
Complex<D> *data;
int xDim, yDim;
FFTFactory<D>* fftFactory;
bool forward;
FFT2D(int iXDim, int iYDim, FFTFactory<D>* iFFTFactory, bool iForward = true) : xDim(iXDim), yDim(iYDim), fftFactory(iFFTFactory), forward(iForward) {
data = new Complex<D>[xDim*yDim];
}
virtual void execute() {
FFT<D>* fftX = fftFactory->newFFT(xDim, forward);
for (int y = 0; y < yDim; ++y) {// if ((y & 0x3FF) == 0) printf("%i:", y);
for (int x = 0; x < xDim; ++x) fftX->setData(x, data[y*xDim + x]);
fftX->execute();
for (int x = 0; x < xDim; ++x) data[y*xDim + x] = fftX->getData(x);
}
delete fftX;
FFT<D>* fftY = fftFactory->newFFT(yDim, forward);
for (int x = 0; x < xDim; ++x) {
for (int y = 0; y < yDim; ++y) fftY->setData(y, data[y*xDim + x]);
fftY->execute();
for (int y = 0; y < yDim; ++y) data[y*xDim + x] = fftY->getData(y);
}
delete fftY;
}
~FFT2D() { delete [] data; }
};
#endif // FFT_H