41 #define Swap(a,b) { nr_double_t t; t = a; a = b; b = t; }
43 using namespace fourier;
54 for (i = 0; i <
n; i += 2) {
56 Swap (data[j], data[i]);
57 Swap (data[j+1], data[i+1]);
60 while (m >= 2 && j >= m) {
69 nr_double_t wt, th, wr, wi, wpr, wpi,
ti, tr;
73 th = isign * (2 *
M_PI / mmax);
79 for (m = 1; m < mmax; m += 2) {
80 for (i = m; i <=
n; i += istep) {
82 tr = wr * data[j] - wi * data[j-1];
83 ti = wr * data[j-1] + wi * data[j];
84 data[j] = data[
i] - tr;
85 data[j-1] = data[i-1] -
ti;
89 wr = (wt = wr) * wpr - wi * wpi + wr;
90 wi = wi * wpr + wt * wpi + wi;
100 nr_double_t rep, rem, aip, aim;
101 n3 = 1 + (n2 = len + len);
104 for (j = 1; j <=
n2; j += 2) {
114 for (j = 2; j <= len; j += 2) {
116 rep = 0.5 * (r1[j] + r1[n2-j]);
117 rem = 0.5 * (r1[j] - r1[n2-j]);
118 aip = 0.5 * (r1[j+1] + r1[n3-j]);
119 aim = 0.5 * (r1[j+1] - r1[n3-j]);
123 r1[j] = r1[n2-j] = rep;
124 r2[j] = r2[n2-j] = aip;
135 int j, jj, nn = len + len;
138 for (j = 0, jj = 0; j < nn; j += 2) {
149 for (j = 0; j < nn; j += 2) {
151 r1[j+1] = r2[j+1] = 0.0;
164 while (size < len) size <<= 1;
168 data = (nr_double_t *) calloc (2 * size *
sizeof (nr_double_t), 1);
169 for (n = i = 0; i < len; i++, n += 2) {
170 data[
n] =
real (var (i)); data[n+1] =
imag (var (i));
178 for (n = i = 0; i < size; i++, n += 2) {
179 res (i) =
rect (data[n], data[n+1]);
180 if (isign < 0) res (i) /= size;
192 int k,
n, size = 2 * len *
sizeof (nr_double_t);
193 nr_double_t * res = (nr_double_t *) calloc (size, 1);
194 nr_double_t th,
c,
s;
195 for (n = 0; n < 2 * len; n += 2) {
196 th = n *
M_PI / 2 / len;
197 for (k = 0; k < 2 * len; k += 2) {
199 s = isign *
sin (k * th);
200 res[
n] += data[k] * c + data[k+1] *
s;
201 res[n+1] += data[k+1] * c - data[k] *
s;
204 memcpy (data, res, size);
214 for (n = 0; n < len; n++) {
215 nr_double_t th = - isign * 2 *
M_PI * n / len;
217 for (k = 0; k < len; k++)
218 val += var (k) *
polar (1.0, th * k);
219 res (n) = isign < 0 ? val / (nr_double_t) len : val;
244 int i, i1, i2, i3, i2rev, i3rev, ip1, ip2, ip3, ifp1, ifp2;
245 int ibit, k1, k2,
n, np, nr, nt;
248 for (nt = 1, i = 0; i < nd; i++) nt *= len[i];
251 for (np = 1, i = nd - 1; i >= 0; i--) {
259 for (i2rev = 1, i2 = 1; i2 <= ip2; i2 += ip1) {
261 for (i1 = i2; i1 <= i2 + ip1 - 2; i1 += 2) {
262 for (i3 = i1; i3 <= ip3; i3 += ip2) {
263 i3rev = i2rev + i3 - i2;
264 Swap (data[i3-1], data[i3rev-1]);
265 Swap (data[i3], data[i3rev]);
270 while (ibit >= ip1 && i2rev > ibit) {
278 nr_double_t
ti, tr, wt, th, wr, wi, wpi, wpr;
282 th = isign * 2 *
M_PI / (ifp2 / ip1);
284 wpr = -2.0 * wt * wt;
288 for (i3 = 1; i3 <= ifp1; i3 += ip1) {
289 for (i1 = i3; i1 <= i3 + ip1 - 2; i1 += 2) {
290 for (i2 = i1; i2 <= ip3; i2 += ifp2) {
293 tr = wr * data[k2-1] - wi * data[k2];
294 ti = wr * data[k2] + wi * data[k2-1];
295 data[k2-1] = data[k1-1] - tr;
296 data[k2] = data[k1] -
ti;
301 wr = (wt = wr) * wpr - wi * wpi + wr;
302 wi = wi * wpr + wt * wpi + wi;
320 for (i = 0; i < len / 2; i++) {
321 res (i) = var (n + i);
322 res (i + n) = var (i);