fftCosineInit

Computes the parameters needed for fftCosine.

Synopsis

fftCosineInit (n)

Required Arguments

int n (Input)
Length of the sequence to be transformed. It must be greater than 1.

Return Value

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

Description

The function fftCosineInit should be used when many calls must be made to fftCosine without changing the sequence length n. It uses the system’s high performance library for the computation, if available. Otherwise, the function fftCosineInit is based on the routine COSTI in FFTPACK. The package FFTPACK was developed by Paul Swarztrauber at the National Center for Atmospheric Research.

Example

This example computes three distinct sine FFTs by calling fftCosineInit once, then calling fftCosine three times. The internal parameter initialization in fftCosine is now skipped.

from __future__ import print_function
from numpy import *
from pyimsl.math.constant import constant
from pyimsl.math.fftCosine import fftCosine
from pyimsl.math.fftCosineInit import fftCosineInit

n = 7
pi = constant("pi")
p = empty(n)

# Compute parameters for transform of length n
work = fftCosineInit(n)

# Different frequencies of the same wave will be transformed
for k in range(0, 3):

    # Fill p with a pure cosine wave
    for i in range(0, n):
        p[i] = cos((k + 1) * i * pi / (n - 1))

    # Compute the transform of p
    q = fftCosine(p, params=work)

    print("")
    print("  index     p         q")
    for i in range(0, n):
        print("     %1d   %5.2f     %5.2f" % (i, p[i], q[i]))

Output

  index     p         q
     0    1.00      0.00
     1    0.87      6.00
     2    0.50     -0.00
     3    0.00      0.00
     4   -0.50      0.00
     5   -0.87      0.00
     6   -1.00      0.00

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

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