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_real,pass_n) (const BASE in[],
28 const TYPE(gsl_complex) twiddle[])
32 const size_t m = n / factor;
33 const size_t q = n / product;
34 const size_t product_1 = product / factor;
38 const double d_theta = 2.0 * M_PI / ((double) factor);
39 const ATOMIC cos_d_theta = cos (d_theta);
40 const ATOMIC sin_d_theta = sin (d_theta);
42 for (k1 = 0; k1 < q; k1++)
44 /* compute x = W(factor) z, for z real */
46 ATOMIC dw_real = 1.0, dw_imag = 0.0;
48 for (e1 = 0; e1 <= factor - e1; e1++)
50 ATOMIC sum_real = 0.0;
51 ATOMIC sum_imag = 0.0;
53 ATOMIC w_real = 1.0, w_imag = 0.0;
57 ATOMIC tmp_real = dw_real * cos_d_theta + dw_imag * sin_d_theta;
58 ATOMIC tmp_imag = -dw_real * sin_d_theta + dw_imag * cos_d_theta;
63 for (e2 = 0; e2 < factor; e2++)
65 ATOMIC z_real = VECTOR(in,istride,k1 * product_1 + e2 * m);
69 ATOMIC tmp_real = dw_real * w_real - dw_imag * w_imag;
70 ATOMIC tmp_imag = dw_real * w_imag + dw_imag * w_real;
75 sum_real += w_real * z_real;
76 sum_imag += w_imag * z_real;
81 const size_t to0 = product * k1;
82 VECTOR(out,ostride,to0) = sum_real;
84 else if (e1 < factor - e1)
86 const size_t to0 = k1 * product + 2 * e1 * product_1 - 1;
87 VECTOR(out,ostride,to0) = sum_real;
88 VECTOR(out,ostride,to0 + 1) = sum_imag;
90 else if (e1 == factor - e1)
92 const size_t to0 = k1 * product + 2 * e1 * product_1 - 1;
93 VECTOR(out,ostride,to0) = sum_real;
102 for (k = 1; k < (product_1 + 1) / 2; k++)
104 for (k1 = 0; k1 < q; k1++)
107 ATOMIC dw_real = 1.0, dw_imag = 0.0;
109 for (e1 = 0; e1 < factor; e1++)
111 ATOMIC sum_real = 0.0, sum_imag = 0.0;
113 ATOMIC w_real = 1.0, w_imag = 0.0;
117 const ATOMIC tmp_real = dw_real * cos_d_theta + dw_imag * sin_d_theta;
118 const ATOMIC tmp_imag = -dw_real * sin_d_theta + dw_imag * cos_d_theta;
123 for (e2 = 0; e2 < factor; e2++)
126 int tskip = (product_1 + 1) / 2 - 1;
127 const size_t from0 = k1 * product_1 + 2 * k + e2 * m - 1;
128 ATOMIC tw_real, tw_imag;
129 ATOMIC z_real, z_imag;
138 const size_t t_index = (k - 1) + (e2 - 1) * tskip;
139 tw_real = GSL_REAL(twiddle[t_index]);
140 tw_imag = -GSL_IMAG(twiddle[t_index]);
144 const ATOMIC f0_real = VECTOR(in,istride,from0);
145 const ATOMIC f0_imag = VECTOR(in,istride,from0 + 1);
147 z_real = tw_real * f0_real - tw_imag * f0_imag;
148 z_imag = tw_real * f0_imag + tw_imag * f0_real;
153 const ATOMIC tmp_real = dw_real * w_real - dw_imag * w_imag;
154 const ATOMIC tmp_imag = dw_real * w_imag + dw_imag * w_real;
159 sum_real += w_real * z_real - w_imag * z_imag;
160 sum_imag += w_real * z_imag + w_imag * z_real;
163 if (e1 < factor - e1)
165 const size_t to0 = k1 * product - 1 + 2 * e1 * product_1 + 2 * k;
166 VECTOR(out,ostride,to0) = sum_real;
167 VECTOR(out,ostride,to0 + 1) = sum_imag;
171 const size_t to0 = k1 * product - 1 + 2 * (factor - e1) * product_1 - 2 * k;
172 VECTOR(out,ostride,to0) = sum_real;
173 VECTOR(out,ostride,to0 + 1) = -sum_imag;
181 if (product_1 % 2 == 1)
185 double tw_arg = M_PI / ((double) factor);
186 ATOMIC cos_tw_arg = cos (tw_arg);
187 ATOMIC sin_tw_arg = -sin (tw_arg);
189 for (k1 = 0; k1 < q; k1++)
191 ATOMIC dw_real = 1.0, dw_imag = 0.0;
193 for (e1 = 0; e1 < factor; e1++)
195 ATOMIC z_real, z_imag;
197 ATOMIC sum_real = 0.0;
198 ATOMIC sum_imag = 0.0;
200 ATOMIC w_real = 1.0, w_imag = 0.0;
201 ATOMIC tw_real = 1.0, tw_imag = 0.0;
205 ATOMIC t_real = dw_real * cos_d_theta + dw_imag * sin_d_theta;
206 ATOMIC t_imag = -dw_real * sin_d_theta + dw_imag * cos_d_theta;
211 for (e2 = 0; e2 < factor; e2++)
216 ATOMIC tmp_real = tw_real * cos_tw_arg - tw_imag * sin_tw_arg;
217 ATOMIC tmp_imag = tw_real * sin_tw_arg + tw_imag * cos_tw_arg;
224 ATOMIC tmp_real = dw_real * w_real - dw_imag * w_imag;
225 ATOMIC tmp_imag = dw_real * w_imag + dw_imag * w_real;
232 const size_t from0 = k1 * product_1 + 2 * k + e2 * m - 1;
233 const ATOMIC f0_real = VECTOR(in,istride,from0);
234 z_real = tw_real * f0_real;
235 z_imag = tw_imag * f0_real;
238 sum_real += w_real * z_real - w_imag * z_imag;
239 sum_imag += w_real * z_imag + w_imag * z_real;
242 if (e1 + 1 < factor - e1)
244 const size_t to0 = k1 * product - 1 + 2 * e1 * product_1 + 2 * k;
245 VECTOR(out,ostride,to0) = sum_real;
246 VECTOR(out,ostride,to0 + 1) = sum_imag;
248 else if (e1 + 1 == factor - e1)
250 const size_t to0 = k1 * product - 1 + 2 * e1 * product_1 + 2 * k;
251 VECTOR(out,ostride,to0) = sum_real;
255 const size_t to0 = k1 * product - 1 + 2 * (factor - e1) * product_1 - 2 * k;
256 VECTOR(out,ostride,to0) = sum_real;
257 VECTOR(out,ostride,to0 + 1) = -sum_imag;