| 1 |
/* fft/real_pass_3.c |
| 2 |
* |
| 3 |
* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough |
| 4 |
* |
| 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. |
| 9 |
* |
| 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. |
| 14 |
* |
| 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. |
| 18 |
*/ |
| 19 |
|
| 20 |
static void |
| 21 |
FUNCTION(fft_real,pass_3) (const BASE in[], |
| 22 |
const size_t istride, |
| 23 |
BASE out[], |
| 24 |
const size_t ostride, |
| 25 |
const size_t product, |
| 26 |
const size_t n, |
| 27 |
const TYPE(gsl_complex) twiddle1[], |
| 28 |
const TYPE(gsl_complex) twiddle2[]) |
| 29 |
{ |
| 30 |
size_t k, k1; |
| 31 |
|
| 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; |
| 36 |
|
| 37 |
const ATOMIC tau = sqrt (3.0) / 2.0; |
| 38 |
|
| 39 |
for (k1 = 0; k1 < q; k1++) |
| 40 |
{ |
| 41 |
const size_t from0 = k1 * product_1; |
| 42 |
const size_t from1 = from0 + m; |
| 43 |
const size_t from2 = from1 + m; |
| 44 |
|
| 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); |
| 48 |
|
| 49 |
const ATOMIC t1 = z1_real + z2_real; |
| 50 |
|
| 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); |
| 54 |
|
| 55 |
const size_t to0 = product * k1; |
| 56 |
const size_t to1 = to0 + 2 * product_1 - 1; |
| 57 |
|
| 58 |
VECTOR(out,ostride,to0) = x0_real; |
| 59 |
VECTOR(out,ostride,to1) = x1_real; |
| 60 |
VECTOR(out,ostride,to1 + 1) = x1_imag; |
| 61 |
} |
| 62 |
|
| 63 |
if (product_1 == 1) |
| 64 |
return; |
| 65 |
|
| 66 |
for (k = 1; k < (product_1 + 1) / 2; k++) |
| 67 |
{ |
| 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]); |
| 72 |
|
| 73 |
for (k1 = 0; k1 < q; k1++) |
| 74 |
{ |
| 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; |
| 78 |
|
| 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); |
| 85 |
|
| 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; |
| 92 |
|
| 93 |
/* compute x = W(3) z */ |
| 94 |
|
| 95 |
/* t1 = z1 + z2 */ |
| 96 |
const ATOMIC t1_real = z1_real + z2_real; |
| 97 |
const ATOMIC t1_imag = z1_imag + z2_imag; |
| 98 |
|
| 99 |
/* t2 = z0 - t1/2 */ |
| 100 |
const ATOMIC t2_real = z0_real - t1_real / 2; |
| 101 |
const ATOMIC t2_imag = z0_imag - t1_imag / 2; |
| 102 |
|
| 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); |
| 106 |
|
| 107 |
/* x0 = z0 + t1 */ |
| 108 |
const ATOMIC x0_real = z0_real + t1_real; |
| 109 |
const ATOMIC x0_imag = z0_imag + t1_imag; |
| 110 |
|
| 111 |
/* x1 = t2 + i t3 */ |
| 112 |
const ATOMIC x1_real = t2_real - t3_imag; |
| 113 |
const ATOMIC x1_imag = t2_imag + t3_real; |
| 114 |
|
| 115 |
/* x2 = t2 - i t3 */ |
| 116 |
const ATOMIC x2_real = t2_real + t3_imag; |
| 117 |
const ATOMIC x2_imag = t2_imag - t3_real; |
| 118 |
|
| 119 |
/* apply twiddle factors */ |
| 120 |
|
| 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; |
| 124 |
|
| 125 |
/* to0 = 1 * x0 */ |
| 126 |
VECTOR(out,ostride,to0) = x0_real; |
| 127 |
VECTOR(out,ostride,to0 + 1) = x0_imag; |
| 128 |
|
| 129 |
/* to1 = 1 * x1 */ |
| 130 |
VECTOR(out,ostride,to1) = x1_real; |
| 131 |
VECTOR(out,ostride,to1 + 1) = x1_imag; |
| 132 |
|
| 133 |
/* to2 = 1 * x2 */ |
| 134 |
VECTOR(out,ostride,to2) = x2_real; |
| 135 |
VECTOR(out,ostride,to2 + 1) = -x2_imag; |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
if (product_1 % 2 == 1) |
| 140 |
return; |
| 141 |
|
| 142 |
for (k1 = 0; k1 < q; k1++) |
| 143 |
{ |
| 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; |
| 147 |
|
| 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); |
| 151 |
|
| 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; |
| 156 |
|
| 157 |
const size_t to0 = k1 * product + product_1 - 1; |
| 158 |
const size_t to1 = to0 + 2 * product_1; |
| 159 |
|
| 160 |
VECTOR(out,ostride,to0) = x0_real; |
| 161 |
VECTOR(out,ostride,to0 + 1) = x0_imag; |
| 162 |
VECTOR(out,ostride,to1) = x1_real; |
| 163 |
} |
| 164 |
|
| 165 |
return; |
| 166 |
} |