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_3) (const BASE in[],
27 const TYPE(gsl_complex) twiddle1[],
28 const TYPE(gsl_complex) twiddle2[])
32 const size_t factor = 3;
33 const size_t m = n / factor;
34 const size_t q = n / product;
35 const size_t product_1 = product / factor;
37 const ATOMIC tau = sqrt (3.0) / 2.0;
39 for (k1 = 0; k1 < q; k1++)
41 const size_t from0 = k1 * product_1;
42 const size_t from1 = from0 + m;
43 const size_t from2 = from1 + m;
45 const ATOMIC z0_real = VECTOR(in,istride,from0);
46 const ATOMIC z1_real = VECTOR(in,istride,from1);
47 const ATOMIC z2_real = VECTOR(in,istride,from2);
49 const ATOMIC t1 = z1_real + z2_real;
51 const ATOMIC x0_real = z0_real + t1;
52 const ATOMIC x1_real = z0_real - t1 / 2.0;
53 const ATOMIC x1_imag = -tau * (z1_real - z2_real);
55 const size_t to0 = product * k1;
56 const size_t to1 = to0 + 2 * product_1 - 1;
58 VECTOR(out,ostride,to0) = x0_real;
59 VECTOR(out,ostride,to1) = x1_real;
60 VECTOR(out,ostride,to1 + 1) = x1_imag;
66 for (k = 1; k < (product_1 + 1) / 2; k++)
68 const ATOMIC w1_real = GSL_REAL(twiddle1[k - 1]);
69 const ATOMIC w1_imag = -GSL_IMAG(twiddle1[k - 1]);
70 const ATOMIC w2_real = GSL_REAL(twiddle2[k - 1]);
71 const ATOMIC w2_imag = -GSL_IMAG(twiddle2[k - 1]);
73 for (k1 = 0; k1 < q; k1++)
75 const size_t from0 = k1 * product_1 + 2 * k - 1;
76 const size_t from1 = from0 + m;
77 const size_t from2 = from1 + m;
79 const ATOMIC f0_real = VECTOR(in,istride,from0);
80 const ATOMIC f0_imag = VECTOR(in,istride,from0 + 1);
81 const ATOMIC f1_real = VECTOR(in,istride,from1);
82 const ATOMIC f1_imag = VECTOR(in,istride,from1 + 1);
83 const ATOMIC f2_real = VECTOR(in,istride,from2);
84 const ATOMIC f2_imag = VECTOR(in,istride,from2 + 1);
86 const ATOMIC z0_real = f0_real;
87 const ATOMIC z0_imag = f0_imag;
88 const ATOMIC z1_real = w1_real * f1_real - w1_imag * f1_imag;
89 const ATOMIC z1_imag = w1_real * f1_imag + w1_imag * f1_real;
90 const ATOMIC z2_real = w2_real * f2_real - w2_imag * f2_imag;
91 const ATOMIC z2_imag = w2_real * f2_imag + w2_imag * f2_real;
93 /* compute x = W(3) z */
96 const ATOMIC t1_real = z1_real + z2_real;
97 const ATOMIC t1_imag = z1_imag + z2_imag;
100 const ATOMIC t2_real = z0_real - t1_real / 2;
101 const ATOMIC t2_imag = z0_imag - t1_imag / 2;
103 /* t3 = (+/-) sin(pi/3)*(z1 - z2) */
104 const ATOMIC t3_real = -tau * (z1_real - z2_real);
105 const ATOMIC t3_imag = -tau * (z1_imag - z2_imag);
108 const ATOMIC x0_real = z0_real + t1_real;
109 const ATOMIC x0_imag = z0_imag + t1_imag;
112 const ATOMIC x1_real = t2_real - t3_imag;
113 const ATOMIC x1_imag = t2_imag + t3_real;
116 const ATOMIC x2_real = t2_real + t3_imag;
117 const ATOMIC x2_imag = t2_imag - t3_real;
119 /* apply twiddle factors */
121 const size_t to0 = k1 * product + 2 * k - 1;
122 const size_t to1 = to0 + 2 * product_1;
123 const size_t to2 = 2 * product_1 - 2 * k + k1 * product - 1;
126 VECTOR(out,ostride,to0) = x0_real;
127 VECTOR(out,ostride,to0 + 1) = x0_imag;
130 VECTOR(out,ostride,to1) = x1_real;
131 VECTOR(out,ostride,to1 + 1) = x1_imag;
134 VECTOR(out,ostride,to2) = x2_real;
135 VECTOR(out,ostride,to2 + 1) = -x2_imag;
139 if (product_1 % 2 == 1)
142 for (k1 = 0; k1 < q; k1++)
144 const size_t from0 = k1 * product_1 + product_1 - 1;
145 const size_t from1 = from0 + m;
146 const size_t from2 = from1 + m;
148 const ATOMIC z0_real = VECTOR(in,istride,from0);
149 const ATOMIC z1_real = VECTOR(in,istride,from1);
150 const ATOMIC z2_real = VECTOR(in,istride,from2);
152 const ATOMIC t1 = z1_real - z2_real;
153 const ATOMIC x0_real = z0_real + t1 / 2.0;
154 const ATOMIC x0_imag = -tau * (z1_real + z2_real);
155 const ATOMIC x1_real = z0_real - t1;
157 const size_t to0 = k1 * product + product_1 - 1;
158 const size_t to1 = to0 + 2 * product_1;
160 VECTOR(out,ostride,to0) = x0_real;
161 VECTOR(out,ostride,to0 + 1) = x0_imag;
162 VECTOR(out,ostride,to1) = x1_real;