added simple fft

This commit is contained in:
toni
2018-01-24 11:44:08 +01:00
parent 3591106b38
commit b207e5e0f2
10 changed files with 1657 additions and 1 deletions

74
math/dsp/Convolution2D.h Normal file
View File

@@ -0,0 +1,74 @@
#ifndef CONVOLUTION2D_H
#define CONVOLUTION2D_H
#ifndef __USE_SQUARE_BRACKETS_FOR_ELEMENT_ACCESS_OPERATOR
#define __USE_SQUARE_BRACKETS_FOR_ELEMENT_ACCESS_OPERATOR
#endif
#include "../../math/boxkde/Image2D.h"
#include "../../lib/simple_fft/fft.h"
namespace DSP {
template <typename Scalar> class Convolution2D {
public:
static inline Image2D<Scalar> convolve(Image2D<Scalar> signal, Image2D<Scalar> kernel){
RealArray2D signalReal;
ComplexArray2D signalSpectrum;
RealArray2D kernelReal;
ComplexArray2D kernelSpectrum;
signal.data().data
//convert image2d single vector to 2d vector, just use pointers
int signal_x = signal.width;
int signal_y = signal.height;
int kernel_x = kernel.width;
int kernel_y = kernel.height;
//check if power of 2, if not fill with zeros
while(!isPowerOfTwo(signal_x)){
}
if(!isPowerOfTwo(kernel.size)){
}
//calculate FFT for both
simple_fft::FFT();
//multiplay the results pointwise
//IFFT
simple_fft::IFFT();
//profit?
}
private:
typedef std::vector<std::vector<complex_type> > ComplexArray2D;
typedef std::vector<std::vector<real_type> > RealArray2D;
bool isPowerOfTwo (unsigned int x)
{
return ((x != 0) && !(x & (x - 1)));
}
};
}
#endif // CONVOLUTION_H