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.
20 TYPE(gsl_fft_real_wavetable) *
21 FUNCTION(gsl_fft_real_wavetable,alloc) (size_t n)
26 size_t t, product, product_1, q;
29 TYPE(gsl_fft_real_wavetable) * wavetable;
33 GSL_ERROR_VAL ("length n must be positive integer", GSL_EDOM, 0);
36 wavetable = (TYPE(gsl_fft_real_wavetable) *)
37 malloc(sizeof(TYPE(gsl_fft_real_wavetable)));
39 if (wavetable == NULL)
41 GSL_ERROR_VAL ("failed to allocate struct", GSL_ENOMEM, 0);
50 wavetable->trig = (TYPE(gsl_complex) *)
51 malloc ((n / 2) * sizeof (TYPE(gsl_complex)));
53 if (wavetable->trig == NULL)
55 /* error in constructor, prevent memory leak */
59 GSL_ERROR_VAL ("failed to allocate trigonometric lookup table",
66 status = fft_real_factorize (n, &n_factors, wavetable->factor);
70 /* error in constructor, prevent memory leak */
72 free(wavetable->trig);
75 GSL_ERROR_VAL ("factorization failed", GSL_EFACTOR, 0);
78 wavetable->nf = n_factors;
80 d_theta = 2.0 * M_PI / ((double) n);
84 for (i = 0; i < wavetable->nf; i++)
87 const size_t factor = wavetable->factor[i];
88 wavetable->twiddle[i] = wavetable->trig + t;
89 product_1 = product; /* product_1 = p_(i-1) */
93 for (j = 1; j < factor; j++)
97 for (k = 1; k < (product_1 + 1) / 2; k++)
102 theta = d_theta * m; /* d_theta*j*k*q */
103 GSL_REAL(wavetable->trig[t]) = cos (theta);
104 GSL_IMAG(wavetable->trig[t]) = sin (theta);
113 /* error in constructor, prevent memory leak */
115 free(wavetable->trig);
118 GSL_ERROR_VAL ("overflowed trigonometric lookup table",
125 TYPE(gsl_fft_real_workspace) *
126 FUNCTION(gsl_fft_real_workspace,alloc) (size_t n)
128 TYPE(gsl_fft_real_workspace) * workspace;
132 GSL_ERROR_VAL ("length n must be positive integer", GSL_EDOM, 0);
135 workspace = (TYPE(gsl_fft_real_workspace) *)
136 malloc(sizeof(TYPE(gsl_fft_real_workspace)));
138 if (workspace == NULL)
140 GSL_ERROR_VAL ("failed to allocate struct", GSL_ENOMEM, 0);
145 workspace->scratch = (BASE *) malloc (n * sizeof (BASE));
147 if (workspace->scratch == NULL)
149 /* error in constructor, prevent memory leak */
153 GSL_ERROR_VAL ("failed to allocate scratch space", GSL_ENOMEM, 0);
162 FUNCTION(gsl_fft_real_wavetable,free) (TYPE(gsl_fft_real_wavetable) * wavetable)
165 /* release trigonometric lookup tables */
167 free (wavetable->trig);
168 wavetable->trig = NULL;
174 FUNCTION(gsl_fft_real_workspace,free) (TYPE(gsl_fft_real_workspace) * workspace)
177 /* release scratch space */
179 free (workspace->scratch);
180 workspace->scratch = NULL;