Next: Functions for numerical solution of equations, Previous: Functions and Variables for fast Fourier transform, Up: Numerical [Contents][Index]

### 22.3 Functions and Variables for FFTPACK5

`FFTPACK5` provides several routines to compute Fourier transforms for both real and complex sequences and their inverses. The forward transform is defined the same as for `fft`. The major difference is the length of the sequence is not constrained to be a power of two. In fact, any length is supported, but it is most efficient when the length has the form 2^r*3^s*5^t.

`load("fftpack5")` loads this function.

Function: fftpack5_fft (x)

  Like `fft` (`fft`), this computes the fast Fourier transform of a complex sequence. However, the length of x is not limited to a power of 2.

  `load("fftpack5")` loads this function.

  Examples:

  Real data.

      (%i1) load("fftpack5") $
      (%i2) fpprintprec : 4 $
      (%i3) L : [1, 2, 3, 4, -1, -2 ,-3, -4] $
      (%i4) L1 : fftpack5_fft(L);
      (%o4) [0.0, 1.811 %i - 0.1036, 0.0, 0.3107 %i + 0.6036, 0.0,
                                      0.6036 - 0.3107 %i, 0.0, (- 1.811 %i) - 0.1036]
      (%i5) L2 : fftpack5_inverse_fft(L1);
      (%o5) [1.0, 4.441e-16 %i + 2.0, 1.837e-16 %i + 3.0, 4.0 - 4.441e-16 %i,
           - 1.0, (- 4.441e-16 %i) - 2.0, (- 1.837e-16 %i) - 3.0, 4.441e-16
             %i - 4.0]
      (%i6) lmax (abs (L2-L));
      (%o6)                       4.441e-16
      (%i7) L : [1, 2, 3, 4, 5, 6]$
      (%i8) L1 : fftpack5_fft(L);
      (%o8) [3.5, (- 0.866 %i) - 0.5, (- 0.2887 %i) - 0.5, (- 1.48e-16 %i) - 0.5,
                                                     0.2887 %i - 0.5, 0.866
                                                            %%i - 0.5]
      (%i9) L2 : fftpack5_inverse_fft (L1);
      (%o9) [1.0 - 1.48e-16 %i, 3.701e-17 %i + 2.0, 3.0 - 1.48e-16 %i,
                           4.0 - 1.811e-16 %i, 5.0 - 1.48e-16 %i, 5.881e-16
                                 %i + 6.0]
      (%i10) lmax (abs (L2-L));
      (%o10)                             9.064e-16

  Complex data.

      (%i1) load("fftpack5") $
      (%i2) fpprintprec : 4 $
      (%i3) L : [1, 1 + %i, 1 - %i, -1, -1, 1 - %i, 1 + %i, 1] $
      (%i4) L1 : fftpack5_inverse_fft (L);
      (%o4) [4.0, 2.828 %i + 2.828, (- 2.0 %i) - 2.0, 4.0, 0.0,
                                             (- 2.828 %i) - 2.828, 2.0 %i - 2.0, 4.0]
      (%i5) L2 : fftpack5_fft(L1);
      (%o5) [1.0, 1.0 %i + 1.0, 1.0 - 1.0 %i, (- 2.776e-17 %i) - 1.0, - 1.0,
                                      1.0 - 1.0 %i, 1.0 %i + 1.0, 1.0 -
                                                %2.776e-17 %i]
      (%i6) lmax(abs(L2-L));
      (%o6)                              1.11e-16

  Categories:Package fftpack5 ·

Function: fftpack5_inverse_fft (y)

  Computes the inverse complex Fourier transform, like `inverse_fft`, but is not constrained to be a power of two.

  Categories:Package fftpack5 ·

Function: fftpack5_real_fft (x)

  Computes the fast Fourier transform of a real-valued sequence x, just like `real_fft`, except the length is not constrained to be a power of two.

  Examples:

      (%i1) fpprintprec : 4 $
      (%i2) L : [1, 2, 3, 4, 5, 6] $
      (%i3) L1 : fftpack5_real_fft(L);
      (%o3)       [3.5, (- 0.866 %i) - 0.5, (- 0.2887 %i) - 0.5, - 0.5]
      (%i4) L2 : fftpack5_inverse_real_fft(L1, 6);
      (%o4)                  [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
      (%i5) lmax(abs(L2-L));
      (%o5)                            1.332e-15
      (%i6) fftpack5_inverse_real_fft(L1, 7);
      (%o6)            [0.5, 2.083, 2.562, 3.7, 4.3, 5.438, 5.917]

  The last example shows how important it to set the length correctly for `fftpack5_inverse_real_fft`.

  Categories:Package fftpack5 ·

Function: fftpack5_inverse_real_fft (y, n)

  Computes the inverse Fourier transform of y, which must have a length of `floor(n/2) + 1`. The length of sequence produced by the inverse transform must be specified by n. This is required because the length of y does not uniquely determine n. The last element of y is always real if n is even, but it can be complex when n is odd.

  Categories:Package fftpack5 ·

Next: Functions for numerical solution of equations, Previous: Functions and Variables for fast Fourier transform, Up: Numerical [Contents][Index]