1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
/* fft/hc_main.c
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <stdlib.h>
#include <math.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_complex.h>
#include <gsl/gsl_fft_halfcomplex.h>
#include "hc_pass.h"
int
FUNCTION(gsl_fft_halfcomplex,backward) (BASE data[], const size_t stride,
const size_t n,
const TYPE(gsl_fft_halfcomplex_wavetable) * wavetable,
TYPE(gsl_fft_real_workspace) * work)
{
int status = FUNCTION(gsl_fft_halfcomplex,transform) (data, stride, n, wavetable, work) ;
return status ;
}
int
FUNCTION(gsl_fft_halfcomplex,inverse) (BASE data[], const size_t stride,
const size_t n,
const TYPE(gsl_fft_halfcomplex_wavetable) * wavetable,
TYPE(gsl_fft_real_workspace) * work)
{
int status = FUNCTION(gsl_fft_halfcomplex,transform) (data, stride, n, wavetable, work);
if (status)
{
return status;
}
/* normalize inverse fft with 1/n */
{
const double norm = 1.0 / n;
size_t i;
for (i = 0; i < n; i++)
{
data[stride*i] *= norm;
}
}
return status;
}
int
FUNCTION(gsl_fft_halfcomplex,transform) (BASE data[], const size_t stride, const size_t n,
const TYPE(gsl_fft_halfcomplex_wavetable) * wavetable,
TYPE(gsl_fft_real_workspace) * work)
{
BASE * const scratch = work->scratch;
BASE * in;
BASE * out;
size_t istride, ostride ;
size_t factor, product, q;
size_t i;
size_t nf;
int state;
int product_1;
int tskip;
TYPE(gsl_complex) *twiddle1, *twiddle2, *twiddle3, *twiddle4;
if (n == 0)
{
GSL_ERROR ("length n must be positive integer", GSL_EDOM);
}
if (n == 1)
{ /* FFT of one data point is the identity */
return 0;
}
if (n != wavetable->n)
{
GSL_ERROR ("wavetable does not match length of data", GSL_EINVAL);
}
if (n != work->n)
{
GSL_ERROR ("workspace does not match length of data", GSL_EINVAL);
}
nf = wavetable->nf;
product = 1;
state = 0;
for (i = 0; i < nf; i++)
{
factor = wavetable->factor[i];
product_1 = product;
product *= factor;
q = n / product;
tskip = (q + 1) / 2 - 1;
if (state == 0)
{
in = data;
istride = stride;
out = scratch;
ostride = 1;
state = 1;
}
else
{
in = scratch;
istride = 1;
out = data;
ostride = stride;
state = 0;
}
if (factor == 2)
{
twiddle1 = wavetable->twiddle[i];
FUNCTION(fft_halfcomplex,pass_2) (in, istride, out, ostride,
product, n, twiddle1);
}
else if (factor == 3)
{
twiddle1 = wavetable->twiddle[i];
twiddle2 = twiddle1 + tskip;
FUNCTION(fft_halfcomplex,pass_3) (in, istride, out, ostride,
product, n, twiddle1, twiddle2);
}
else if (factor == 4)
{
twiddle1 = wavetable->twiddle[i];
twiddle2 = twiddle1 + tskip;
twiddle3 = twiddle2 + tskip;
FUNCTION(fft_halfcomplex,pass_4) (in, istride, out, ostride,
product, n, twiddle1, twiddle2,
twiddle3);
}
else if (factor == 5)
{
twiddle1 = wavetable->twiddle[i];
twiddle2 = twiddle1 + tskip;
twiddle3 = twiddle2 + tskip;
twiddle4 = twiddle3 + tskip;
FUNCTION(fft_halfcomplex,pass_5) (in, istride, out, ostride,
product, n, twiddle1, twiddle2,
twiddle3, twiddle4);
}
else
{
twiddle1 = wavetable->twiddle[i];
FUNCTION(fft_halfcomplex,pass_n) (in, istride, out, ostride,
factor, product, n, twiddle1);
}
}
if (state == 1) /* copy results back from scratch to data */
{
for (i = 0; i < n; i++)
{
data[stride*i] = scratch[i] ;
}
}
return 0;
}
|