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_halfcomplex,pass_n) (const BASE in[],
28 const TYPE(gsl_complex) twiddle[])
33 const size_t m = n / factor;
34 const size_t q = n / product;
35 const size_t product_1 = product / factor;
39 const double d_theta = 2.0 * M_PI / ((double) factor);
40 const ATOMIC cos_d_theta = cos (d_theta);
41 const ATOMIC sin_d_theta = sin (d_theta);
43 for (k1 = 0; k1 < product_1; k1++)
45 /* compute z = W(factor) x, for x halfcomplex */
47 ATOMIC dw_real = 1.0, dw_imag = 0.0;
49 for (e1 = 0; e1 < factor; e1++)
51 ATOMIC sum_real = 0.0;
52 ATOMIC w_real = 1.0, w_imag = 0.0;
56 ATOMIC tmp_real = dw_real * cos_d_theta - dw_imag * sin_d_theta;
57 ATOMIC tmp_imag = dw_real * sin_d_theta + dw_imag * cos_d_theta;
62 for (e2 = 0; e2 <= factor - e2; e2++)
64 ATOMIC z_real, z_imag;
68 ATOMIC tmp_real = dw_real * w_real - dw_imag * w_imag;
69 ATOMIC tmp_imag = dw_real * w_imag + dw_imag * w_real;
76 size_t from_idx = factor * k1 * q;
77 z_real = VECTOR(in,istride,from_idx);
79 sum_real += w_real * z_real - w_imag * z_imag;
81 else if (e2 == factor - e2)
83 size_t from_idx = factor * q * k1 + 2 * e2 * q - 1;
84 z_real = VECTOR(in,istride,from_idx);
86 sum_real += w_real * z_real;
90 size_t from_idx = factor * q * k1 + 2 * e2 * q - 1;
91 z_real = VECTOR(in,istride,from_idx);
92 z_imag = VECTOR(in,istride,from_idx + 1);
93 sum_real += 2 * (w_real * z_real - w_imag * z_imag);
99 const size_t to_idx = q * k1 + e1 * m;
100 VECTOR(out,ostride,to_idx) = sum_real;
108 for (k = 1; k < (q + 1) / 2; k++)
110 for (k1 = 0; k1 < product_1; k1++)
113 ATOMIC dw_real = 1.0, dw_imag = 0.0;
115 for (e1 = 0; e1 < factor; e1++)
117 ATOMIC z_real, z_imag;
118 ATOMIC sum_real = 0.0;
119 ATOMIC sum_imag = 0.0;
120 ATOMIC w_real = 1.0, w_imag = 0.0;
124 ATOMIC t_real = dw_real * cos_d_theta - dw_imag * sin_d_theta;
125 ATOMIC t_imag = dw_real * sin_d_theta + dw_imag * cos_d_theta;
130 for (e2 = 0; e2 < factor; e2++)
135 ATOMIC tmp_real = dw_real * w_real - dw_imag * w_imag;
136 ATOMIC tmp_imag = dw_real * w_imag + dw_imag * w_real;
141 if (e2 < factor - e2)
143 const size_t from0 = factor * k1 * q + 2 * k + 2 * e2 * q - 1;
144 z_real = VECTOR(in,istride,from0);
145 z_imag = VECTOR(in,istride,from0 + 1);
149 const size_t from0 = factor * k1 * q - 2 * k + 2 * (factor - e2) * q - 1;
150 z_real = VECTOR(in,istride,from0);
151 z_imag = -VECTOR(in,istride,from0 + 1);
154 sum_real += w_real * z_real - w_imag * z_imag;
155 sum_imag += w_real * z_imag + w_imag * z_real;
158 if (k == 0 || e1 == 0)
165 size_t tskip = (q + 1) / 2 - 1;
166 w_real = GSL_REAL(twiddle[k - 1 + tskip * (e1 - 1)]);
167 w_imag = GSL_IMAG(twiddle[k - 1 + tskip * (e1 - 1)]);
171 const size_t to0 = k1 * q + 2 * k + e1 * m - 1;
172 VECTOR(out,ostride,to0) = w_real * sum_real - w_imag * sum_imag;
173 VECTOR(out,ostride,to0 + 1) = w_real * sum_imag + w_imag * sum_real;
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 < product_1; k1++)
192 ATOMIC dw_real = 1.0, dw_imag = 0.0;
193 ATOMIC tw_real = 1.0, tw_imag = 0.0;
195 for (e1 = 0; e1 < factor; e1++)
197 ATOMIC w_real, w_imag, z_real, z_imag;
199 ATOMIC sum_real = 0.0;
203 ATOMIC tmp_real = tw_real * cos_tw_arg - tw_imag * sin_tw_arg;
204 ATOMIC tmp_imag = tw_real * sin_tw_arg + tw_imag * cos_tw_arg;
214 ATOMIC t_real = dw_real * cos_d_theta - dw_imag * sin_d_theta;
215 ATOMIC t_imag = dw_real * sin_d_theta + dw_imag * cos_d_theta;
220 for (e2 = 0; e2 <= factor - e2 - 1; e2++)
225 ATOMIC tmp_real = dw_real * w_real - dw_imag * w_imag;
226 ATOMIC tmp_imag = dw_real * w_imag + dw_imag * w_real;
232 if (e2 == factor - e2 - 1)
234 const size_t from0 = factor * k1 * q + q + 2 * e2 * q - 1;
235 z_real = VECTOR(in,istride,from0);
237 sum_real += w_real * z_real - w_imag * z_imag;
241 const size_t from0 = factor * k1 * q + q + 2 * e2 * q - 1;
242 z_real = VECTOR(in,istride,from0);
243 z_imag = VECTOR(in,istride,from0 + 1);
244 sum_real += 2 * (w_real * z_real - w_imag * z_imag);
250 const size_t to0 = k1 * q + q + e1 * m - 1;
251 VECTOR(out,ostride,to0) = sum_real;