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_real.h>
28 #include "real_pass.h"
31 FUNCTION(gsl_fft_real,transform) (BASE data[], const size_t stride, const size_t n,
32 const TYPE(gsl_fft_real_wavetable) * wavetable,
33 TYPE(gsl_fft_real_workspace) * work)
35 const size_t nf = wavetable->nf;
39 size_t q, product = 1;
43 BASE *const scratch = work->scratch;
44 TYPE(gsl_complex) *twiddle1, *twiddle2, *twiddle3, *twiddle4;
48 size_t istride = stride ;
54 GSL_ERROR ("length n must be positive integer", GSL_EDOM);
58 { /* FFT of one data point is the identity */
62 if (n != wavetable->n)
64 GSL_ERROR ("wavetable does not match length of data", GSL_EINVAL);
69 GSL_ERROR ("workspace does not match length of data", GSL_EINVAL);
72 for (i = 0; i < nf; i++)
74 const size_t factor = wavetable->factor[i];
79 tskip = (product_1 + 1) / 2 - 1;
100 twiddle1 = wavetable->twiddle[i];
101 FUNCTION(fft_real,pass_2) (in, istride, out, ostride, product, n, twiddle1);
103 else if (factor == 3)
105 twiddle1 = wavetable->twiddle[i];
106 twiddle2 = twiddle1 + tskip;
107 FUNCTION(fft_real,pass_3) (in, istride, out, ostride, product, n, twiddle1,
110 else if (factor == 4)
112 twiddle1 = wavetable->twiddle[i];
113 twiddle2 = twiddle1 + tskip;
114 twiddle3 = twiddle2 + tskip;
115 FUNCTION(fft_real,pass_4) (in, istride, out, ostride, product, n, twiddle1,
118 else if (factor == 5)
120 twiddle1 = wavetable->twiddle[i];
121 twiddle2 = twiddle1 + tskip;
122 twiddle3 = twiddle2 + tskip;
123 twiddle4 = twiddle3 + tskip;
124 FUNCTION(fft_real,pass_5) (in, istride, out, ostride, product, n, twiddle1,
125 twiddle2, twiddle3, twiddle4);
129 twiddle1 = wavetable->twiddle[i];
130 FUNCTION(fft_real,pass_n) (in, istride, out, ostride, factor, product, n,
135 if (state == 1) /* copy results back from scratch to data */
137 for (i = 0; i < n; i++)
139 data[stride*i] = scratch[i] ;