fftSine

Computes the discrete Fourier sine transformation of an odd sequence.

Synopsis

fftSine (p)

Required Arguments

float p[] (Input)
Array of size n containing the sequence to be transformed.

Return Value

The transformed sequence. If no solution was computed, then None is returned.

Optional Arguments

params, float[] (Input)

Vector returned by a previous call to fftSineInit. If fftSine is used repeatedly with the same value of n, then it is more efficient to compute these parameters only once.

Default: Initializing parameters computed each time fftSine is entered

Description

The function fftSine computes the discrete Fourier sine transform of a real vector of size N. It uses the system’s high performance library for the computation, if available. Otherwise, the method used is a variant of the Cooley-Tukey algorithm, which is most efficient when N + 1 is a product of small prime factors. If N satisfies this condition, then the computational effort is proportional to N logN. Specifically, given an N-vector p, fftSine returns in q

\[q_m = 2 \sum_{n=0}^{N-1} p_n \sin \left(\frac{(m+1)(n+1)\pi}{N+1}\right)\]

Finally, note that the Fourier sine transform is its own (unnormalized) inverse. The Cooley-Tukey algorithm is based on the sine FFT in FFTPACK, which was developed by Paul Swarztrauber at the National Center for Atmospheric Research.

Example

This example inputs a pure sine wave as a data vector and recovers its Fourier sine series, which is a vector with all components zero, except n at the appropriate frequency.

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

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

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

q = fftSine(p)

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