fftSineInit

Computes the parameters needed for fftSine.

Synopsis

fftSineInit (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 fftSine when the optional argument params is specified. If no solution was computed, then None is returned.

Description

The function fftSineInit should be used when many calls must be made to fftSine without changing the sequence length n. It uses the system’s high performance library for the computation, if available. Otherwise, the function fftSineInit is based on the routine SINTI 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 fftSineInit once, then calling fftSineInit three times. The internal parameter initialization in fftSine is now skipped.

from __future__ import print_function
from numpy import *
from pyimsl.math.constant import constant
from pyimsl.math.fftSine import fftSine
from pyimsl.math.fftSineInit import fftSineInit

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

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

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

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

    # Compute the transform of p
    q = fftSine(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      0.38   8.00
  1      0.71   0.00
  2      0.92   0.00
  3      1.00   0.00
  4      0.92   0.00
  5      0.71   0.00
  6      0.38   0.00

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

 index   p        q
  0      0.92  -0.00
  1      0.71   0.00
  2     -0.38   8.00
  3     -1.00  -0.00
  4     -0.38   0.00
  5      0.71  -0.00
  6      0.92  -0.00