fft.h 1.1 KB
#ifndef STIM_FFT_H
#define STIM_FFT_H

namespace stim{

	/*template<class T>
	void circshift(T *out, const T *in, size_t xdim, size_t ydim, size_t xshift, size_t yshift){
		size_t i, j, ii, jj;
		for (i =0; i < xdim; i++) {
			ii = (i + xshift) % xdim;
			for (j = 0; j < ydim; j++) {
				jj = (j + yshift) % ydim;
				out[ii * ydim + jj] = in[i * ydim + j];
			}
		}
	}*/

	template<typename T>
	void circshift(T *out, const T *in, int xdim, int ydim, int xshift, int yshift)
	{
	 for (int i =0; i < xdim; i++) {
	   int ii = (i + xshift) % xdim;
	   if (ii<0) ii = xdim + ii;
	   for (int j = 0; j < ydim; j++) {
	     int jj = (j + yshift) % ydim;
	     if (jj<0) jj = ydim + jj;
	     //out[ii * ydim + jj] = in[i * ydim + j];
	     out[jj * xdim + ii] = in[j * xdim + i];
	   }
	 }
	}

	template<typename T>
	void cpu_fftshift(T* out, T* in, size_t xdim, size_t ydim){
		circshift(out, in, xdim, ydim, std::floor(xdim/2), std::floor(ydim/2));
	}

	template<typename T>
	void cpu_ifftshift(T* out, T* in, size_t xdim, size_t ydim){
		circshift(out, in, xdim, ydim, std::ceil(xdim/2), std::ceil(ydim/2));
	}


}

#endif