⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fft.texi

📁 开放gsl矩阵运算
💻 TEXI
📖 第 1 页 / 共 3 页
字号:
issue a warning that the transform will be slow when the length ispoorly factorized.  If you frequently encounter data lengths whichcannot be factorized using the existing small-prime modules consult@cite{GSL FFT Algorithms} for details on adding support for otherfactors.@comment First, the space for the trigonometric lookup tables and scratch area is@comment allocated by a call to one of the @code{alloc} functions.  We@comment call the combination of factorization, scratch space and trigonometric@comment lookup arrays a @dfn{wavetable}.  It contains the sine and cosine@comment waveforms for the all the frequencies that will be used in the FFT.@comment The wavetable is initialized by a call to the corresponding @code{init}@comment function.  It factorizes the data length, using the implemented@comment subtransforms as preferred factors wherever possible.  The trigonometric@comment lookup table for the chosen factorization is also computed.@comment An FFT is computed by a call to one of the @code{forward},@comment @code{backward} or @code{inverse} functions, with the data, length and@comment wavetable as arguments.All these functions are declared in the header file @file{gsl_fft_complex.h}.@deftypefun {gsl_fft_complex_wavetable *} gsl_fft_complex_wavetable_alloc (size_t @var{n})This function prepares a trigonometric lookup table for a complex FFT oflength @var{n}. The function returns a pointer to the newly allocated@code{gsl_fft_complex_wavetable} if no errors were detected, and a nullpointer in the case of error.  The length @var{n} is factorized into aproduct of subtransforms, and the factors and their trigonometriccoefficients are stored in the wavetable. The trigonometric coefficientsare computed using direct calls to @code{sin} and @code{cos}, foraccuracy.  Recursion relations could be used to compute the lookup tablefaster, but if an application performs many FFTs of the same length thenthis computation is a one-off overhead which does not affect the finalthroughput.The wavetable structure can be used repeatedly for any transform of thesame length.  The table is not modified by calls to any of the other FFTfunctions.  The same wavetable can be used for both forward and backward(or inverse) transforms of a given length.@end deftypefun@deftypefun void gsl_fft_complex_wavetable_free (gsl_fft_complex_wavetable * @var{wavetable})This function frees the memory associated with the wavetable@var{wavetable}.  The wavetable can be freed if no further FFTs of thesame length will be needed.@end deftypefun@noindentThese functions operate on a @code{gsl_fft_complex_wavetable} structurewhich contains internal parameters for the FFT.  It is not necessary toset any of the components directly but it can sometimes be useful toexamine them.  For example, the chosen factorization of the FFT lengthis given and can be used to provide an estimate of the run-time ornumerical error.The wavetable structure is declared in the header file@file{gsl_fft_complex.h}.@deftp {Data Type} gsl_fft_complex_wavetableThis is a structure that holds the factorization and trigonometriclookup tables for the mixed radix fft algorithm.  It has the followingcomponents:@table @code@item size_t nThis is the number of complex data points@item size_t nfThis is the number of factors that the length @code{n} was decomposed into.@item size_t factor[64]This is the array of factors.  Only the first @code{nf} elements areused. @comment (FIXME: This is a fixed length array and therefore probably in@comment violation of the GNU Coding Standards).@item gsl_complex * trigThis is a pointer to a preallocated trigonometric lookup table of@code{n} complex elements.@item gsl_complex * twiddle[64]This is an array of pointers into @code{trig}, giving the twiddlefactors for each pass.@end table@end deftp@noindentThe mixed radix algorithms require an additional working space to holdthe intermediate steps of the transform.@deftypefun {gsl_fft_complex_workspace *} gsl_fft_complex_workspace_alloc (size_t @var{n})This function allocates a workspace for a complex transform of length@var{n}.@end deftypefun@deftypefun void gsl_fft_complex_workspace_free (gsl_fft_complex_workspace * @var{workspace})This function frees the memory associated with the workspace@var{workspace}. The workspace can be freed if no further FFTs of thesame length will be needed.@end deftypefun@comment @deftp {Data Type} gsl_fft_complex_workspace@comment This is a structure that holds the workspace for the mixed radix fft@comment algorithm.  It has the following components:@comment@comment @table @code@comment @item gsl_complex * scratch@comment This is a pointer to a workspace of @code{n} complex elements,@comment capable of holding intermediate copies of the original data set.@comment @end table@comment @end deftp@noindentThe following functions compute the transform,@deftypefun int gsl_fft_complex_forward (gsl_complex_packed_array @var{data}[], size_t @var{stride}, size_t @var{n}, const gsl_fft_complex_wavetable * @var{wavetable}, gsl_fft_complex_workspace * @var{work})@deftypefunx int gsl_fft_complex_transform (gsl_complex_packed_array @var{data}[], size_t @var{stride}, size_t @var{n}, const gsl_fft_complex_wavetable * @var{wavetable}, gsl_fft_complex_workspace * @var{work})@deftypefunx int gsl_fft_complex_backward (gsl_complex_packed_array @var{data}[], size_t @var{stride}, size_t @var{n}, const gsl_fft_complex_wavetable * @var{wavetable}, gsl_fft_complex_workspace * @var{work})@deftypefunx int gsl_fft_complex_inverse (gsl_complex_packed_array @var{data}[], size_t @var{stride}, size_t @var{n}, const gsl_fft_complex_wavetable * @var{wavetable}, gsl_fft_complex_workspace * @var{work})These functions compute forward, backward and inverse FFTs of length@var{n} with stride @var{stride}, on the packed complex array@var{data}, using a mixed radix decimation-in-frequency algorithm.There is no restriction on the length @var{n}.  Efficient modules areprovided for subtransforms of length 2, 3, 4, 5, 6 and 7.  Any remainingfactors are computed with a slow, @math{O(n^2)}, general-@math{n}module. The caller must supply a @var{wavetable} containing thetrigonometric lookup tables and a workspace @var{work}.The functions return a value of @code{0} if no errors were detected. Thefollowing @code{gsl_errno} conditions are defined for these functions:@table @code@item GSL_EDOMThe length of the data @var{n} is not a positive integer (i.e. @var{n}is zero).@item GSL_EINVALThe length of the data @var{n} and the length used to compute the given@var{wavetable} do not match.@end table@end deftypefun@comment @node Example of using mixed-radix FFT routines for complex data@comment @subsection Example of using mixed-radix FFT routines for complex dataHere is an example program which computes the FFT of a short pulse in asample of length 630 (@math{=2*3*3*5*7}) using the mixed-radixalgorithm.@example#include <stdio.h>#include <math.h>#include <gsl/gsl_errno.h>#include <gsl/gsl_fft_complex.h>#define REAL(z,i) ((z)[2*(i)])#define IMAG(z,i) ((z)[2*(i)+1])intmain (void)@{  int i;  const int n = 630;  double data[2*n];  gsl_fft_complex_wavetable * wavetable;  gsl_fft_complex_workspace * workspace;  for (i = 0; i < n; i++)    @{      REAL(data,i) = 0.0;      IMAG(data,i) = 0.0;    @}  data[0].real = 1.0;  for (i = 1; i <= 10; i++)    @{      REAL(data,i) = REAL(data,n-i) = 1.0;    @}  for (i = 0; i < n; i++)    @{      printf ("%d: %e %e\n", i, REAL(data,i),                                 IMAG(data,i));    @}  printf ("\n");  wavetable = gsl_fft_complex_wavetable_alloc (n);  workspace = gsl_fft_complex_workspace_alloc (n);  for (i = 0; i < wavetable->nf; i++)    @{       printf("# factor %d: %d\n", i,               wavetable->factor[i]);    @}  gsl_fft_complex_forward (data, 1, n,                            wavetable, workspace);  for (i = 0; i < n; i++)    @{      printf ("%d: %e %e\n", i, REAL(data,i),                                 IMAG(data,i));    @}  gsl_fft_complex_wavetable_free (wavetable);  gsl_fft_complex_workspace_free (workspace);  return 0;@}@end example@noindentNote that we have assumed that the program is using the default@code{gsl} error handler (which calls @code{abort} for any errors).  Ifyou are not using a safe error handler you would need to check thereturn status of all the @code{gsl} routines.@node Overview of real data FFTs@section Overview of real data FFTs@cindex FFT of real dataThe functions for real data are similar to those for complex data.However, there is an important difference between forward and inversetransforms.  The fourier transform of a real sequence is not real.  It isa complex sequence with a special symmetry:@tex\beforedisplay$$z_k = z_{N-k}^*$$\afterdisplay@end tex@ifinfo@examplez_k = z_@{N-k@}^*@end example@end ifinfo@noindentA sequence with this symmetry is called @dfn{conjugate-complex} or@dfn{half-complex}.  This different structure requires differentstorage layouts for the forward transform (from real to half-complex)and inverse transform (from half-complex back to real).  As aconsequence the routines are divided into two sets: functions in@code{gsl_fft_real} which operate on real sequences and functions in@code{gsl_fft_halfcomplex} which operate on half-complex sequences.Functions in @code{gsl_fft_real} compute the frequency coefficients of areal sequence.  The half-complex coefficients @math{c} of a real sequence@math{x} are given by fourier analysis,@tex\beforedisplay$$c_k = \sum_{j=0}^{N-1} x_k \exp(-2 \pi i j k /N)$$\afterdisplay@end tex@ifinfo@examplec_k = \sum_@{j=0@}^@{N-1@} x_k \exp(-2 \pi i j k /N)@end example@end ifinfo@noindentFunctions in @code{gsl_fft_halfcomplex} compute inverse or backwardstransforms.  They reconstruct real sequences by fourier synthesis fromtheir half-complex frequency coefficients, @math{c},@tex\beforedisplay$$x_j = {1 \over N} \sum_{k=0}^{N-1} c_k \exp(2 \pi i j k /N)$$\afterdisplay@end tex@ifinfo@examplex_j = @{1 \over N@} \sum_@{k=0@}^@{N-1@} c_k \exp(2 \pi i j k /N)@end example@end ifinfo@noindentThe symmetry of the half-complex sequence implies that only half of thecomplex numbers in the output need to be stored.  The remaining half canbe reconstructed using the half-complex symmetry condition. (This worksfor all lengths, even and odd.  When the length is even the middle value,where @math{k=N/2}, is also real).  Thus only @var{N} real numbers arerequired to store the half-complex sequence, and the transform of a realsequence can be stored in the same size array as the original data.The precise storage arrangements depend on the algorithm, and aredifferent for radix-2 and mixed-radix routines.  The radix-2 functionoperates in-place, which constrain the locations where each element canbe stored.  The restriction forces real and imaginary parts to be storedfar apart.  The mixed-radix algorithm does not have this restriction, andit stores the real and imaginary parts of a given term in neighboringlocations.  This is desirable for better locality of memory accesses.@node Radix-2 FFT routines for real data@section Radix-2 FFT routines for real data@cindex FFT of real data, radix-2 algorithm@cindex Radix-2 FFT for real dataThis section describes radix-2 FFT algorithms for real data.  They usethe Cooley-Tukey algorithm to compute in-place FFTs for lengths whichare a power of 2. The radix-2 FFT functions for real data are declared in the header files@file{gsl_fft_real.h} @deftypefun int gsl_fft_real_radix2_transform (double @var{data}[], size_t @var{stride}, size_t @var{n})This function computes an in-place radix-2 FFT of length @var{n} andstride @var{stride} on the real array @var{data}.  The output is ahalf-complex sequence, which is stored in-place.  The arrangement of thehalf-complex terms uses the following scheme: for @math{k < N/2} thereal part of the @math{k}-th term is stored in location @math{k}, andthe corresponding imaginary part is stored in location @math{N-k}.  Termswith @math{k > N/2} can be reconstructed using the symmetry @c{$z_k = z^*_{N-k}$}@math{z_k = z^*_@{N-k@}}. The terms for @math{k=0} and @math{k=N/2} are both purelyreal, and count as a special case.  Their real parts are stored inlocations @math{0} and @math{N/2} respectively, while their imaginaryparts which are zero are not stored.The following table shows the correspondence between the output@var{data} and the equivalent results obtained by considering the inputdata as a complex sequence with zero imaginary part,@examplecomplex[0].real    =    data[0] complex[0].imag    =    0 complex[1].real    =    data[1] complex[1].imag    =    data[N-1]...............         ................complex[k].real    =    data[k]complex[k].imag    =    data[N-k] ...............         ................complex[N/2].real  =    data[N/2]complex[N/2].real  =    0...............         ................complex[k'].real   =    data[k]        k' = N - kcomplex[k'].imag   =   -data[N-k] ...............         ................complex[N-1].real  =    data[1]complex[N-1].imag  =   -data[N-1]@end example@end deftypefunThe radix-2 FFT functions for halfcomplex data are declared in theheader file @file{gsl_fft_halfcomplex.h}.@deftypefun int gsl_fft_halfcomplex_radix2_inverse (double @var{data}[], size_t @var{stride}, size_t @var{n})@deftypefunx int gsl_fft_halfcomplex_radix2_backward (double @var{data}[], size_t @var{stride}, size_t @var{n})These functions compute the inverse or backwards in-place radix-2 FFT oflength @var{n} and stride @var{stride} on the half-complex sequence@var{data} stored according the output scheme used by@code{gsl_fft_real_radix2}.  The result is a real array stored in naturalorder.@end deftypefun@node Mixed-radix FFT routines for real data@section Mixed-radix FFT routines for real data@cindex FFT of real data, mixed-radix algorithm@cindex Mixed-radix FFT, real dataThis section describes mixed-radix FFT algorithms for real data.  Themixed-radix functions work for FFTs of any length.  They are areimplementation of the real-FFT routines in the Fortran @sc{fftpack} libraryby Paul Swarztrauber.  The theory behind the algorithm is explained in

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -