fft.h
1.1 KB
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
#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