3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 FUNCTION(fft_complex,pass_n) (BASE in[],
25 const gsl_fft_direction sign,
29 const TYPE(gsl_complex) twiddle[])
34 const size_t m = n / factor;
35 const size_t q = n / product;
36 const size_t p_1 = product / factor;
37 const size_t jump = (factor - 1) * p_1;
41 for (i = 0; i < m; i++)
43 REAL(out,ostride,i) = REAL(in,istride,i);
44 IMAG(out,ostride,i) = IMAG(in,istride,i);
47 for (e = 1; e < (factor - 1) / 2 + 1; e++)
49 for (i = 0; i < m; i++)
51 const size_t idx = i + e * m;
52 const size_t idxc = i + (factor - e) * m;
53 REAL(out,ostride,idx) = REAL(in,istride,idx) + REAL(in,istride,idxc);
54 IMAG(out,ostride,idx) = IMAG(in,istride,idx) + IMAG(in,istride,idxc);
55 REAL(out,ostride,idxc) = REAL(in,istride,idx) - REAL(in,istride,idxc);
56 IMAG(out,ostride,idxc) = IMAG(in,istride,idx) - IMAG(in,istride,idxc);
64 REAL(in,istride,i) = REAL(out,ostride,i);
65 IMAG(in,istride,i) = IMAG(out,ostride,i);
68 for (e1 = 1; e1 < (factor - 1) / 2 + 1; e1++)
70 for (i = 0; i < m; i++)
72 REAL(in,istride,i) += REAL(out,ostride,i + e1*m) ;
73 IMAG(in,istride,i) += IMAG(out,ostride,i + e1*m) ;
77 for (e = 1; e < (factor-1)/2 + 1; e++)
80 const size_t idx_step = e * q ;
81 ATOMIC w_real, w_imag ;
83 const size_t em = e * m ;
84 const size_t ecm = (factor - e) * m ;
86 for (i = 0; i < m; i++)
88 REAL(in,istride,i+em) = REAL(out,ostride,i) ;
89 IMAG(in,istride,i+em) = IMAG(out,ostride,i) ;
90 REAL(in,istride,i+ecm) = REAL(out,ostride,i) ;
91 IMAG(in,istride,i+ecm) = IMAG(out,ostride,i) ;
94 for (e1 = 1; e1 < (factor - 1) / 2 + 1; e1++)
100 if (sign == gsl_fft_forward) {
101 w_real = GSL_REAL(twiddle[idx - 1]) ;
102 w_imag = GSL_IMAG(twiddle[idx - 1]) ;
104 w_real = GSL_REAL(twiddle[idx - 1]) ;
105 w_imag = -GSL_IMAG(twiddle[idx - 1]) ;
109 for (i = 0; i < m; i++)
111 const ATOMIC xp_real = REAL(out,ostride,i + e1 * m);
112 const ATOMIC xp_imag = IMAG(out,ostride,i + e1 * m);
113 const ATOMIC xm_real = REAL(out,ostride,i + (factor - e1) *m);
114 const ATOMIC xm_imag = IMAG(out,ostride,i + (factor - e1) *m);
116 const ATOMIC ap = w_real * xp_real ;
117 const ATOMIC am = w_imag * xm_imag ;
119 ATOMIC sum_real = ap - am;
120 ATOMIC sumc_real = ap + am;
122 const ATOMIC bp = w_real * xp_imag ;
123 const ATOMIC bm = w_imag * xm_real ;
125 ATOMIC sum_imag = bp + bm;
126 ATOMIC sumc_imag = bp - bm;
128 REAL(in,istride,i + em) += sum_real;
129 IMAG(in,istride,i + em) += sum_imag;
130 REAL(in,istride,i + ecm) += sumc_real;
131 IMAG(in,istride,i + ecm) += sumc_imag;
142 for (k1 = 0; k1 < p_1; k1++)
144 REAL(out,ostride,k1) = REAL(in,istride,k1);
145 IMAG(out,ostride,k1) = IMAG(in,istride,k1);
148 for (e1 = 1; e1 < factor; e1++)
150 for (k1 = 0; k1 < p_1; k1++)
152 REAL(out,ostride,k1 + e1 * p_1) = REAL(in,istride,k1 + e1 * m) ;
153 IMAG(out,ostride,k1 + e1 * p_1) = IMAG(in,istride,k1 + e1 * m) ;
160 for (k = 1; k < q; k++)
162 for (k1 = 0; k1 < p_1; k1++)
164 REAL(out,ostride,j) = REAL(in,istride,i);
165 IMAG(out,ostride,j) = IMAG(in,istride,i);
175 for (k = 1; k < q; k++)
177 for (k1 = 0; k1 < p_1; k1++)
179 for (e1 = 1; e1 < factor; e1++)
181 ATOMIC x_real = REAL(in, istride,i + e1 * m);
182 ATOMIC x_imag = IMAG(in, istride,i + e1 * m);
184 ATOMIC w_real, w_imag ;
185 if (sign == gsl_fft_forward) {
186 w_real = GSL_REAL(twiddle[(e1-1)*q + k-1]) ;
187 w_imag = GSL_IMAG(twiddle[(e1-1)*q + k-1]) ;
189 w_real = GSL_REAL(twiddle[(e1-1)*q + k-1]) ;
190 w_imag = -GSL_IMAG(twiddle[(e1-1)*q + k-1]) ;
193 REAL(out,ostride,j + e1 * p_1) = w_real * x_real - w_imag * x_imag;
194 IMAG(out,ostride,j + e1 * p_1) = w_real * x_imag + w_imag * x_real;