fftRealInit

Computes the parameters for fftReal.

Synopsis

fftRealInit (n)

Required Arguments

int n (Input)
Length of the sequence to be transformed.

Return Value

The internal parameter vector that can then be used by fftReal when the optional argument params is specified. If no value can be computed, then None is returned.

Description

The function fftRealInit should be used when many calls are to be made to fftReal without changing the sequence length n. This function computes the parameters that are necessary for the real Fourier transform.

It uses the system’s high performance library for the computation, if available. Otherwise, the function fftRealInit is based on the routine RFFTI in FFTPACK, which was developed by Paul Swarztrauber at the National Center for Atmospheric Research.

Example

This example computes three distinct real FFTs by calling fftRealInit once and then calling fftReal three times.

from __future__ import print_function
from numpy import *
from pyimsl.math.constant import constant
from pyimsl.math.fftReal import fftReal
from pyimsl.math.fftRealInit import fftRealInit

n = 7
work = fftRealInit(n)
two_pi = 2 * constant("pi")
p = empty(n)
for j in range(0, 3):

    # Fill p with a pure sinusoidal signal
    for k in range(0, n):
        p[k] = cos(k * two_pi * j / n)

    q = fftReal(p, params=work)

    print("")
    print("        index      p        q")
    for k in range(0, n):
        print("%11d%10.2f%10.2f" % (k, p[k], q[k]))

Output

        index      p        q
          0      1.00      7.00
          1      1.00      0.00
          2      1.00      0.00
          3      1.00     -0.00
          4      1.00      0.00
          5      1.00      0.00
          6      1.00      0.00

        index      p        q
          0      1.00     -0.00
          1      0.62      3.50
          2     -0.22     -0.00
          3     -0.90      0.00
          4     -0.90     -0.00
          5     -0.22     -0.00
          6      0.62     -0.00

        index      p        q
          0      1.00      0.00
          1     -0.22     -0.00
          2     -0.90     -0.00
          3      0.62      3.50
          4      0.62     -0.00
          5     -0.90      0.00
          6     -0.22     -0.00