| 1 |
/* fft/c_pass_5.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 int |
| 21 |
FUNCTION(fft_complex,pass_5) (const BASE in[], |
| 22 |
const size_t istride, |
| 23 |
BASE out[], |
| 24 |
const size_t ostride, |
| 25 |
const gsl_fft_direction sign, |
| 26 |
const size_t product, |
| 27 |
const size_t n, |
| 28 |
const TYPE(gsl_complex) twiddle1[], |
| 29 |
const TYPE(gsl_complex) twiddle2[], |
| 30 |
const TYPE(gsl_complex) twiddle3[], |
| 31 |
const TYPE(gsl_complex) twiddle4[]) |
| 32 |
{ |
| 33 |
size_t i = 0, j = 0; |
| 34 |
size_t k, k1; |
| 35 |
|
| 36 |
const size_t factor = 5; |
| 37 |
const size_t m = n / factor; |
| 38 |
const size_t q = n / product; |
| 39 |
const size_t p_1 = product / factor; |
| 40 |
const size_t jump = (factor - 1) * p_1; |
| 41 |
|
| 42 |
const ATOMIC sin_2pi_by_5 = sin (2.0 * M_PI / 5.0); |
| 43 |
const ATOMIC sin_2pi_by_10 = sin (2.0 * M_PI / 10.0); |
| 44 |
|
| 45 |
for (k = 0; k < q; k++) |
| 46 |
{ |
| 47 |
|
| 48 |
ATOMIC w1_real, w1_imag, w2_real, w2_imag, w3_real, w3_imag, w4_real, |
| 49 |
w4_imag; |
| 50 |
|
| 51 |
if (k == 0) |
| 52 |
{ |
| 53 |
w1_real = 1.0; |
| 54 |
w1_imag = 0.0; |
| 55 |
w2_real = 1.0; |
| 56 |
w2_imag = 0.0; |
| 57 |
w3_real = 1.0; |
| 58 |
w3_imag = 0.0; |
| 59 |
w4_real = 1.0; |
| 60 |
w4_imag = 0.0; |
| 61 |
} |
| 62 |
else |
| 63 |
{ |
| 64 |
if (sign == gsl_fft_forward) |
| 65 |
{ |
| 66 |
/* forward tranform */ |
| 67 |
w1_real = GSL_REAL(twiddle1[k - 1]); |
| 68 |
w1_imag = GSL_IMAG(twiddle1[k - 1]); |
| 69 |
w2_real = GSL_REAL(twiddle2[k - 1]); |
| 70 |
w2_imag = GSL_IMAG(twiddle2[k - 1]); |
| 71 |
w3_real = GSL_REAL(twiddle3[k - 1]); |
| 72 |
w3_imag = GSL_IMAG(twiddle3[k - 1]); |
| 73 |
w4_real = GSL_REAL(twiddle4[k - 1]); |
| 74 |
w4_imag = GSL_IMAG(twiddle4[k - 1]); |
| 75 |
} |
| 76 |
else |
| 77 |
{ |
| 78 |
/* backward tranform: w -> conjugate(w) */ |
| 79 |
w1_real = GSL_REAL(twiddle1[k - 1]); |
| 80 |
w1_imag = -GSL_IMAG(twiddle1[k - 1]); |
| 81 |
w2_real = GSL_REAL(twiddle2[k - 1]); |
| 82 |
w2_imag = -GSL_IMAG(twiddle2[k - 1]); |
| 83 |
w3_real = GSL_REAL(twiddle3[k - 1]); |
| 84 |
w3_imag = -GSL_IMAG(twiddle3[k - 1]); |
| 85 |
w4_real = GSL_REAL(twiddle4[k - 1]); |
| 86 |
w4_imag = -GSL_IMAG(twiddle4[k - 1]); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
for (k1 = 0; k1 < p_1; k1++) |
| 91 |
{ |
| 92 |
|
| 93 |
ATOMIC x0_real, x0_imag, x1_real, x1_imag, x2_real, x2_imag, |
| 94 |
x3_real, x3_imag, x4_real, x4_imag; |
| 95 |
|
| 96 |
const ATOMIC z0_real = REAL(in,istride,i); |
| 97 |
const ATOMIC z0_imag = IMAG(in,istride,i); |
| 98 |
const ATOMIC z1_real = REAL(in,istride,i + m); |
| 99 |
const ATOMIC z1_imag = IMAG(in,istride,i + m); |
| 100 |
const ATOMIC z2_real = REAL(in,istride,i + 2*m); |
| 101 |
const ATOMIC z2_imag = IMAG(in,istride,i + 2*m); |
| 102 |
const ATOMIC z3_real = REAL(in,istride,i + 3*m); |
| 103 |
const ATOMIC z3_imag = IMAG(in,istride,i + 3*m); |
| 104 |
const ATOMIC z4_real = REAL(in,istride,i + 4*m); |
| 105 |
const ATOMIC z4_imag = IMAG(in,istride,i + 4*m); |
| 106 |
|
| 107 |
/* compute x = W(5) z */ |
| 108 |
|
| 109 |
/* t1 = z1 + z4 */ |
| 110 |
const ATOMIC t1_real = z1_real + z4_real; |
| 111 |
const ATOMIC t1_imag = z1_imag + z4_imag; |
| 112 |
|
| 113 |
/* t2 = z2 + z3 */ |
| 114 |
const ATOMIC t2_real = z2_real + z3_real; |
| 115 |
const ATOMIC t2_imag = z2_imag + z3_imag; |
| 116 |
|
| 117 |
/* t3 = z1 - z4 */ |
| 118 |
const ATOMIC t3_real = z1_real - z4_real; |
| 119 |
const ATOMIC t3_imag = z1_imag - z4_imag; |
| 120 |
|
| 121 |
/* t4 = z2 - z3 */ |
| 122 |
const ATOMIC t4_real = z2_real - z3_real; |
| 123 |
const ATOMIC t4_imag = z2_imag - z3_imag; |
| 124 |
|
| 125 |
/* t5 = t1 + t2 */ |
| 126 |
const ATOMIC t5_real = t1_real + t2_real; |
| 127 |
const ATOMIC t5_imag = t1_imag + t2_imag; |
| 128 |
|
| 129 |
/* t6 = (sqrt(5)/4)(t1 - t2) */ |
| 130 |
const ATOMIC t6_real = (sqrt (5.0) / 4.0) * (t1_real - t2_real); |
| 131 |
const ATOMIC t6_imag = (sqrt (5.0) / 4.0) * (t1_imag - t2_imag); |
| 132 |
|
| 133 |
/* t7 = z0 - ((t5)/4) */ |
| 134 |
const ATOMIC t7_real = z0_real - t5_real / 4.0; |
| 135 |
const ATOMIC t7_imag = z0_imag - t5_imag / 4.0; |
| 136 |
|
| 137 |
/* t8 = t7 + t6 */ |
| 138 |
const ATOMIC t8_real = t7_real + t6_real; |
| 139 |
const ATOMIC t8_imag = t7_imag + t6_imag; |
| 140 |
|
| 141 |
/* t9 = t7 - t6 */ |
| 142 |
const ATOMIC t9_real = t7_real - t6_real; |
| 143 |
const ATOMIC t9_imag = t7_imag - t6_imag; |
| 144 |
|
| 145 |
/* t10 = sin(2 pi/5) t3 + sin(2 pi/10) t4 */ |
| 146 |
const ATOMIC t10_real = ((int) sign) * (sin_2pi_by_5 * t3_real + |
| 147 |
sin_2pi_by_10 * t4_real); |
| 148 |
const ATOMIC t10_imag = ((int) sign) * (sin_2pi_by_5 * t3_imag + |
| 149 |
sin_2pi_by_10 * t4_imag); |
| 150 |
|
| 151 |
/* t11 = sin(2 pi/10) t3 - sin(2 pi/5) t4 */ |
| 152 |
const ATOMIC t11_real = ((int) sign) * (sin_2pi_by_10 * t3_real - |
| 153 |
sin_2pi_by_5 * t4_real); |
| 154 |
const ATOMIC t11_imag = ((int) sign) * (sin_2pi_by_10 * t3_imag - |
| 155 |
sin_2pi_by_5 * t4_imag); |
| 156 |
|
| 157 |
/* x0 = z0 + t5 */ |
| 158 |
x0_real = z0_real + t5_real; |
| 159 |
x0_imag = z0_imag + t5_imag; |
| 160 |
|
| 161 |
/* x1 = t8 + i t10 */ |
| 162 |
x1_real = t8_real - t10_imag; |
| 163 |
x1_imag = t8_imag + t10_real; |
| 164 |
|
| 165 |
/* x2 = t9 + i t11 */ |
| 166 |
x2_real = t9_real - t11_imag; |
| 167 |
x2_imag = t9_imag + t11_real; |
| 168 |
|
| 169 |
/* x3 = t9 - i t11 */ |
| 170 |
x3_real = t9_real + t11_imag; |
| 171 |
x3_imag = t9_imag - t11_real; |
| 172 |
|
| 173 |
/* x4 = t8 - i t10 */ |
| 174 |
x4_real = t8_real + t10_imag; |
| 175 |
x4_imag = t8_imag - t10_real; |
| 176 |
|
| 177 |
/* apply twiddle factors */ |
| 178 |
|
| 179 |
/* to0 = 1 * x0 */ |
| 180 |
REAL(out,ostride,j) = x0_real; |
| 181 |
IMAG(out,ostride,j) = x0_imag; |
| 182 |
|
| 183 |
/* to1 = w1 * x1 */ |
| 184 |
REAL(out,ostride,j + p_1) = w1_real * x1_real - w1_imag * x1_imag; |
| 185 |
IMAG(out,ostride,j + p_1) = w1_real * x1_imag + w1_imag * x1_real; |
| 186 |
|
| 187 |
/* to2 = w2 * x2 */ |
| 188 |
REAL(out,ostride,j + 2*p_1) = w2_real * x2_real - w2_imag * x2_imag; |
| 189 |
IMAG(out,ostride,j+2*p_1) = w2_real * x2_imag + w2_imag * x2_real; |
| 190 |
|
| 191 |
/* to3 = w3 * x3 */ |
| 192 |
REAL(out,ostride,j+3*p_1) = w3_real * x3_real - w3_imag * x3_imag; |
| 193 |
IMAG(out,ostride,j+3*p_1) = w3_real * x3_imag + w3_imag * x3_real; |
| 194 |
|
| 195 |
/* to4 = w4 * x4 */ |
| 196 |
REAL(out,ostride,j+4*p_1) = w4_real * x4_real - w4_imag * x4_imag; |
| 197 |
IMAG(out,ostride,j+4*p_1) = w4_real * x4_imag + w4_imag * x4_real; |
| 198 |
|
| 199 |
i++; |
| 200 |
j++; |
| 201 |
} |
| 202 |
j += jump; |
| 203 |
} |
| 204 |
return 0; |
| 205 |
} |