IMSL C Math Library
fft_cosine_init

   more...
Computes the parameters needed for imsl_f_fft_cosine.
Synopsis
#include <imsl.h>
float *imsl_f_fft_cosine_init (int n)
The type double procedure is imsl_d_fft_cosine_init.
Required Arguments
int n (Input)
Length of the sequence to be transformed. It must be greater than 1.
Return Value
A pointer to the internal parameter vector that can then be used by imsl_f_fft_cosine when the optional argument IMSL_PARAMS is specified. To release this space, use imsl_free. If no solution was computed, then NULL is returned.
Description
The function imsl_f_fft_cosine_init should be used when many calls must be made to imsl_f_fft_cosine without changing the sequence length n. It uses the system’s high performance library for the computation, if available. Otherwise, the function imsl_f_fft_cosine_init 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 imsl_f_fft_cosine_init once, then calling imsl_f_fft_cosine three times. The internal parameter initialization in imsl_f_fft_cosine is now skipped.
 
#include <imsl.h>
#include <math.h>
#include <stdio.h>
 
int main()
{
int n = 7;
int i, k;
float p[7];
float q[7];
float pi;
float *params;
 
pi = imsl_f_constant("pi", 0);
 
/* Compute parameters for transform of
length n */
 
params = imsl_f_fft_cosine_init (n);
 
/* Different frequencies of the same
wave will be transformed */
for (k=0; k<3; k++)
{
printf("\n");
 
/* Fill p with a pure cosine wave */
 
for (i=0; i<n; i++)
p[i] = cos((float)((k+1)*i)*pi/(float)(n-1));
 
/* Compute the transform of p */
 
imsl_f_fft_cosine (n, p,
IMSL_PARAMS, params,
IMSL_RETURN_USER, q,
0);
 
printf (" index\t p\t q\n");
for (i=0; i<n; i++)
printf("\t%1d\t%5.2f\t%5.2f\n", 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