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.
24 #include <gsl/gsl_errno.h>
25 #include <gsl/gsl_complex.h>
26 #include <gsl/gsl_fft_halfcomplex.h>
31 FUNCTION(gsl_fft_halfcomplex,backward) (BASE data[], const size_t stride,
33 const TYPE(gsl_fft_halfcomplex_wavetable) * wavetable,
34 TYPE(gsl_fft_real_workspace) * work)
36 int status = FUNCTION(gsl_fft_halfcomplex,transform) (data, stride, n, wavetable, work) ;
41 FUNCTION(gsl_fft_halfcomplex,inverse) (BASE data[], const size_t stride,
43 const TYPE(gsl_fft_halfcomplex_wavetable) * wavetable,
44 TYPE(gsl_fft_real_workspace) * work)
46 int status = FUNCTION(gsl_fft_halfcomplex,transform) (data, stride, n, wavetable, work);
53 /* normalize inverse fft with 1/n */
56 const double norm = 1.0 / n;
58 for (i = 0; i < n; i++)
60 data[stride*i] *= norm;
67 FUNCTION(gsl_fft_halfcomplex,transform) (BASE data[], const size_t stride, const size_t n,
68 const TYPE(gsl_fft_halfcomplex_wavetable) * wavetable,
69 TYPE(gsl_fft_real_workspace) * work)
71 BASE * const scratch = work->scratch;
75 size_t istride, ostride ;
78 size_t factor, product, q;
84 TYPE(gsl_complex) *twiddle1, *twiddle2, *twiddle3, *twiddle4;
88 GSL_ERROR ("length n must be positive integer", GSL_EDOM);
92 { /* FFT of one data point is the identity */
96 if (n != wavetable->n)
98 GSL_ERROR ("wavetable does not match length of data", GSL_EINVAL);
103 GSL_ERROR ("workspace does not match length of data", GSL_EINVAL);
110 for (i = 0; i < nf; i++)
112 factor = wavetable->factor[i];
117 tskip = (q + 1) / 2 - 1;
138 twiddle1 = wavetable->twiddle[i];
139 FUNCTION(fft_halfcomplex,pass_2) (in, istride, out, ostride,
140 product, n, twiddle1);
142 else if (factor == 3)
144 twiddle1 = wavetable->twiddle[i];
145 twiddle2 = twiddle1 + tskip;
146 FUNCTION(fft_halfcomplex,pass_3) (in, istride, out, ostride,
147 product, n, twiddle1, twiddle2);
149 else if (factor == 4)
151 twiddle1 = wavetable->twiddle[i];
152 twiddle2 = twiddle1 + tskip;
153 twiddle3 = twiddle2 + tskip;
154 FUNCTION(fft_halfcomplex,pass_4) (in, istride, out, ostride,
155 product, n, twiddle1, twiddle2,
158 else if (factor == 5)
160 twiddle1 = wavetable->twiddle[i];
161 twiddle2 = twiddle1 + tskip;
162 twiddle3 = twiddle2 + tskip;
163 twiddle4 = twiddle3 + tskip;
164 FUNCTION(fft_halfcomplex,pass_5) (in, istride, out, ostride,
165 product, n, twiddle1, twiddle2,
170 twiddle1 = wavetable->twiddle[i];
171 FUNCTION(fft_halfcomplex,pass_n) (in, istride, out, ostride,
172 factor, product, n, twiddle1);
176 if (state == 1) /* copy results back from scratch to data */
178 for (i = 0; i < n; i++)
180 data[stride*i] = scratch[i] ;