added simple fft
This commit is contained in:
74
math/dsp/Convolution2D.h
Normal file
74
math/dsp/Convolution2D.h
Normal 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
|
||||
Reference in New Issue
Block a user