libdspl-2.0 Digital Signal Processing Algorithm Library
Discrete Fourier transform and fast Fourier transform algorithms

## Data Structures

struct  fft_t
Fast Fourier Transform Object Data Structure. More...

## Functions

int DSPL_API dft (double *x, int n, complex_t *y)
Discrete Fourier transform of a real signal. More...

int DSPL_API dft_cmplx (complex_t *x, int n, complex_t *y)
Discrete Fourier transform of a complex signal. More...

int DSPL_API idft_cmplx (complex_t *x, int n, complex_t *y)
Inverse discrete Fourier transform of the complex spectrum. More...

int DSPL_API ifft_cmplx (complex_t *x, int n, fft_t *pfft, complex_t *y)
Inverse fast Fourier transform. More...

int DSPL_API fft (double *x, int n, fft_t *pfft, complex_t *y)
Fast Fourier transform for the real vector. More...

int DSPL_API fft_cmplx (complex_t *x, int n, fft_t *pfft, complex_t *y)
Fast Fourier transform for the complex vector. More...

int DSPL_API fft_create (fft_t *pfft, int n)
Function creates and fill fft_t structure. More...

void DSPL_API fft_free (fft_t *pfft)
Free fft_t structure. More...

int DSPL_API fft_shift (double *x, int n, double *y)
Perform a shift of the vector x, for use with the fft and ifft functions, in order to move the frequency 0 to the center of the vector y. More...

int DSPL_API fourier_series_dec (double *t, double *s, int nt, double period, int nw, double *w, complex_t *y)
Fourier series coefficient calculation for periodic signal. More...

int DSPL_API fourier_series_rec (double *w, complex_t *s, int nw, double *t, int nt, complex_t *y)
Time signal reconstruction from Fourier series coefficients. More...

int DSPL_API goertzel (double *x, int n, int *ind, int k, complex_t *y)
Goertzel algorithm individual DFT samples calculation for the real input vector x. More...

int DSPL_API goertzel_cmplx (complex_t *x, int n, int *ind, int k, complex_t *y)
Goertzel algorithm individual DFT samples calculation for the complex input vector x. More...

## ◆ dft()

 int dft ( double * x, int n, complex_t * y )

Discrete Fourier transform of a real signal.

The function calculates the $$n$$ -point discrete Fourier transform real signal $$x (m)$$, $$m = 0 \ldots n-1$$.

$Y (k) = \sum_ {m = 0} ^ {n-1} x (m) \exp \left (-j \frac {2 \pi} {n} m k \right),$

where $$k = 0 \ldots n-1$$.

Parameters
 [in] x Pointer to the vector of the real input signal $$x (m)$$, $$m = 0 \ldots n-1$$. The size of the vector is [n x 1]. [in] n The size of the DFT $$n$$ (the size of the vectors of the input signal and the result of the DFT). [out] y Pointer to the complex vector of the DFT result $$Y (k)$$, $$k = 0 \ldots n-1$$. The size of the vector is [n x 1]. Memory must be allocated.
Returns
RES_OK if the DFT is calculated successfully.
Otherwise, error code.

An example of using the dft function:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dspl.h"
/* DFT size */
#define N 16
int main()
{
void* handle; /* DSPL handle */
double x[N]; /* real input signal */
complex_t y[N]; /* DFT vector */
int k;
/* fill input signal */
for(k = 0; k < N; k++)
x[k] = (double)k;
/* DFT calculation */
dft(x, N, y);
/* Print result */
for(k = 0; k < N; k++)
printf("y[%2d] = %9.3f%9.3f\n", k, RE(y[k]), IM(y[k]));
/* remember to free the resource */
dspl_free(handle);
return 0;
}

The result of the program:

y [0] = 120.000 0.000
y [1] = -8.000 40.219
y [2] = -8.000 19.314
y [3] = -8.000 11.973
y [4] = -8.000 8.000
y [5] = -8.000 5.345
y [6] = -8.000 3.314
y [7] = -8.000 1.591
y [8] = -8.000 0.000
y [9] = -8.000 -1.591
y [10] = -8.000 -3.314
y [11] = -8.000 -5.345
y [12] = -8.000 -8.000
y [13] = -8.000 -11.973
y [14] = -8.000 -19.314
y [15] = -8.000 -40.219

Note
This function performs the DFT calculation using the naive method and requires $$n ^ 2$$ complex multiplications.
To increase the calculation speed, it is recommended to use fast Fourier transform algorithms.

Definition at line 163 of file dft.c.

## ◆ dft_cmplx()

 int dft_cmplx ( complex_t * x, int n, complex_t * y )

Discrete Fourier transform of a complex signal.

The function calculates the $$n$$ -point discrete Fourier transform complex signal $$x (m)$$, $$m = 0 \ldots n-1$$.

$Y (k) = \sum_ {m = 0} ^ {n-1} x (m) \exp \left (-j \frac {2 \pi} {n} m k \right),$

where $$k = 0 \ldots n-1$$.

Parameters
 [in] x Pointer to a vector of complex input signal $$x (m)$$, $$m = 0 \ldots n-1$$. The size of the vector is [n x 1]. [in] n The size of the DFT $$n$$ (the size of the vectors of the input signal and the result of the DFT). [out] y Integrated Vector Pointer DFT result $$Y (k)$$, $$k = 0 \ldots n-1$$. The size of the vector is [n x 1]. Memory must be allocated.
Returns
RES_OK if the DFT is calculated successfully.
Otherwise, error code.

An example of using the dft_cmplx function:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dspl.h"
#define N 16
int main()
{
void* handle; /* DSPL handle */
complex_t y[N]; /* DFT */
complex_t x[N]; /* complex input signal */
int k;
for(k = 0; k < N; k++)
{
RE(x[k]) = (double)k;
IM(x[k]) = 0.0;
}
dft_cmplx(x,N,y);
for(k = 0; k < N; k++)
printf("y[%2d] = %9.3f%9.3f\n", k, RE(y[k]), IM(y[k]));
dspl_free(handle); /* remember to free the resource */
return 0;
}

The result of the program:

y [0] = 120.000 0.000
y [1] = -8.000 40.219
y [2] = -8.000 19.314
y [3] = -8.000 11.973
y [4] = -8.000 8.000
y [5] = -8.000 5.345
y [6] = -8.000 3.314
y [7] = -8.000 1.591
y [8] = -8.000 0.000
y [9] = -8.000 -1.591
y [10] = -8.000 -3.314
y [11] = -8.000 -5.345
y [12] = -8.000 -8.000
y [13] = -8.000 -11.973
y [14] = -8.000 -19.314
y [15] = -8.000 -40.219

Note
This function performs the calculation of the DFT by the naive method and requires $$n ^ 2$$ complex multiplications.
To increase the calculation speed, it is recommended use fast Fourier transform algorithms.

Definition at line 329 of file dft.c.

## ◆ fft()

 int fft ( double * x, int n, fft_t * pfft, complex_t * y )

Fast Fourier transform for the real vector.

Function calculated $$n$$-points FFT for the real vector $$x(m)$$, $$m = 0 \ldots n-1$$.

$Y(k) = \sum_{m = 0}^{n-1} x(m) \exp \left( -j \frac{2\pi}{n} m k \right),$

here $$k = 0 \ldots n-1$$.

Parameters
 [in] x Pointer to the input real vector $$x(m)$$, $$m = 0 \ldots n-1$$. Vector size is [n x 1]. [in] n FFT size $$n$$. FFT size can be composite: $$n = n_0 \times n_1 \times n_2 \times \ldots \times n_p \times m$$, here $$n_i = 2,3,5,7$$, а $$m$$ – simple number less than 46340 (see fft_create function). [in] pfft Pointer to the fft_t object. This pointer cannot be NULL. Structure fft_t should be previously once filled with the fft_create function, and the memory should be cleared before exiting by the fft_free function. [out] y Pointer to the FFT result complex vector $$Y(k)$$, $$k = 0 \ldots n-1$$. Vector size is [n x 1]. Memory must be allocated.
Returns
RES_OK if FFT is calculated successfully.
Else code error.

Example:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dspl.h"
/* FFT size */
#define N 14
int main()
{
void* handle; /* DSPL handle */
double x[N]; /* Input signal array */
complex_t y[N]; /* Output signal array */
fft_t pfft = {0}; /* FFT object (fill zeros) */
int k;
/* Fill FFT structure */
fft_create(&pfft, N);
/* Fill input signal x[k] = k */
for(k = 0; k < N; k++)
x[k] = (double)k;
/* FFT */
fft(x, N, &pfft, y);
/* print result */
for(k = 0; k < N; k++)
printf("y[%2d] = %9.3f%9.3f\n", k, RE(y[k]), IM(y[k]));
fft_free(&pfft); /* Clear fft_t object */
dspl_free(handle); /* Clear DSPL handle */
return 0;
}

Result:

y[ 0] =    91.000    0.000
y[ 1] =    -7.000   30.669
y[ 2] =    -7.000   14.536
y[ 3] =    -7.000    8.778
y[ 4] =    -7.000    5.582
y[ 5] =    -7.000    3.371
y[ 6] =    -7.000    1.598
y[ 7] =    -7.000    0.000
y[ 8] =    -7.000   -1.598
y[ 9] =    -7.000   -3.371
y[10] =    -7.000   -5.582
y[11] =    -7.000   -8.778
y[12] =    -7.000  -14.536
y[13] =    -7.000  -30.669


Definition at line 357 of file fft.c.

Referenced by xcorr(), and xcorr_cmplx().

## ◆ fft_cmplx()

 int fft_cmplx ( complex_t * x, int n, fft_t * pfft, complex_t * y )

Fast Fourier transform for the complex vector.

Function calculated $$n$$-points FFT for the complex vector $$x(m)$$, $$m = 0 \ldots n-1$$.

$Y(k) = \sum_{m = 0}^{n-1} x(m) \exp \left( -j \frac{2\pi}{n} m k \right),$

here $$k = 0 \ldots n-1$$.

Parameters
 [in] x Pointer to the input complex vector $$x(m)$$, $$m = 0 \ldots n-1$$. Vector size is [n x 1]. [in] n FFT size $$n$$. FFT size can be composite: $$n = n_0 \times n_1 \times n_2 \times \ldots \times n_p \times m$$, here $$n_i = 2,3,5,7$$, а $$m$$ – simple number less than 46340 (see fft_create function). [in] pfft Pointer to the fft_t object. This pointer cannot be NULL. Structure fft_t should be previously once filled with the fft_create function, and the memory should be cleared before exiting by the fft_free function. [out] y Pointer to the FFT result complex vector $$Y(k)$$, $$k = 0 \ldots n-1$$. Vector size is [n x 1]. Memory must be allocated.
Returns
RES_OK if FFT is calculated successfully.
Else code error.

Example:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dspl.h"
/* FFT size */
#define N 18
int main()
{
void* handle; /* DSPL handle */
complex_t x[N]; /* Input signal array */
complex_t y[N]; /* Output signal array */
fft_t pfft = {0}; /* FFT object (fill zeros) */
int k;
/* Fill FFT structure */
fft_create(&pfft, N);
/* Fill input signal x[k] = exp(j*k) */
for(k = 0; k < N; k++)
{
RE(x[k]) = (double)cos((double)k);
IM(x[k]) = (double)sin((double)k);
}
/* FFT */
fft_cmplx(x, N, &pfft, y);
/* print result */
for(k = 0; k < N; k++)
printf("y[%2d] = %9.3f%9.3f\n", k, RE(y[k]), IM(y[k]));
fft_free(&pfft); /* Clear fft_t object */
dspl_free(handle); /* Clear DSPL handle */
return 0;
}

Result:

y[ 0] =    -0.517    0.686
y[ 1] =    -0.943    0.879
y[ 2] =    -2.299    1.492
y[ 3] =    16.078   -6.820
y[ 4] =     2.040   -0.470
y[ 5] =     1.130   -0.059
y[ 6] =     0.786    0.097
y[ 7] =     0.596    0.183
y[ 8] =     0.470    0.240
y[ 9] =     0.375    0.283
y[10] =     0.297    0.318
y[11] =     0.227    0.350
y[12] =     0.161    0.380
y[13] =     0.094    0.410
y[14] =     0.023    0.442
y[15] =    -0.059    0.479
y[16] =    -0.161    0.525
y[17] =    -0.300    0.588


Definition at line 646 of file fft.c.

Referenced by conv_fft_cmplx().

## ◆ fft_create()

 int fft_create ( fft_t * pfft, int n )

Function creates and fill fft_t structure.

The function allocates memory and calculates twiddle factors of the n-point FFT for the structurefft_t.

Parameters
 [in,out] pfft Pointer to the fft_t object. Pointer cannot be NULL. [in] n FFT size $$n$$. FFT size can be composite $$n = n_0 \times n_1 \times n_2 \ldots \times n_p \times m$$, here $$n_i = 2,3,5,7$$, and $$m$$ – arbitrary prime factor not exceeding 46340. Thus, the FFT algorithm supports arbitrary integer lengths. degrees of numbers 2,3,5,7, as well as their various combinations. For example, with $$n = 725760$$ the structure will be successfully filled, because $$725760 = 2 \cdot 3 \cdot 4 \cdot 5 \cdot 6 \cdot 7 \cdot 9 \cdot 16$$. If $$n = 172804 = 43201 \cdot 4$$ then the structure will also be successfully filled, because the simple factor in $$n$$ does not exceed 46340. For size $$n = 13 \cdot 17 \cdot 23 \cdot 13 = 66079$$ the function will return an error since 66079 is greater than 46340 and is not the result of the product of numbers 2,3,5,7.
Returns
RES_OK if FFT structure is created and filled successfully.
Else code error.
Note
Some compilers do not nullify its contents when creating a structure. Therefore, it is recommended to reset the structure after its declaration:
fft_t pfft = {0}; // fill and fields of fft_t as zeros
int n = 64; // FFT size
int err;
// Create fft_t object for 64-points FFT
err = fft_create(&pfft, n);
// ...................................
// Clear fft_t structure
fft_free(&pfft);

Before exiting the program, the memory allocated in the structure need to clear by fft_free function.

Note
The "magic number" 46340 because $$\sqrt{2^{31}} = 46340.95$$.

Definition at line 935 of file fft.c.

Referenced by fft(), fft_cmplx(), and ifft_cmplx().

## ◆ fft_free()

 void fft_free ( fft_t * pfft )

Free fft_t structure.

The function clears the intermediate data memory and vectors of FFT twiddle factors of the structure fft_t.

Parameters
 [in] pfft Pointer to the fft_t object.

Definition at line 1177 of file fft.c.

Referenced by xcorr(), and xcorr_cmplx().

## ◆ fft_shift()

 int fft_shift ( double * x, int n, double * y )

Perform a shift of the vector x, for use with the fft and ifft functions, in order to move the frequency 0 to the center of the vector y.

Parameters
 [in] x Pointer to the input vector (FFT or IFFT result). Vector size is [n x 1]. [in] n Input and output vector size. [out] y Pointer to the output vector with frequency 0 in the center. Vector size is [n x 1]. Memory must be allocated.
Returns
RES_OK if function is calculated successfully.
Else code error.

Definition at line 1357 of file fft.c.

## ◆ fourier_series_dec()

 int fourier_series_dec ( double * t, double * s, int nt, double period, int nw, double * w, complex_t * y )

Fourier series coefficient calculation for periodic signal.

Parameters
 [in] t Pointer to the time vector. Vector size is [nt x 1]. [in] s Pointer to the signal corresponds to time t. Vector size is [nt x 1]. [in] nt Size of time and signal vectors. This value must be positive. [in] period Signal time period. [in] nw Number of Fourie series coefficients. [out] w Pointer to the frequency vector (rad/s). Vector size is [nw x 1]. Memory must be allocated. [out] y Pointer to the complex Fourier series coefficients vector. Vector size is [nw x 1]. Memory must be allocated.
Returns
RES_OK if function is calculated successfully.
Else code error.
Note
Numerical integration is used for Fourier series coefficients calculation. This function is not effective. To increase the speed of calculation of the signal spectrum it is more expedient to use fast Fourier transform algorithms.

Definition at line 151 of file fourier_series.c.

## ◆ fourier_series_rec()

 int fourier_series_rec ( double * w, complex_t * s, int nw, double * t, int nt, complex_t * y )

Time signal reconstruction from Fourier series coefficients.

Function reconstructs the time signal:

$s(t) = \sum\limits_{n = 0}^{n_{\omega}-1} S(\omega_n) \exp(j\omega_n t)$

Parameters
 [in] w Pointer to the Fourier series spectrum frequency vector $$\omega_n$$. Vector size is [nw x 1]. [in] s Pointer to the Fourier series coefficients vector $$S(\omega_n)$$. Vector size is [nw x 1]. [in] nw Number of Fourier series coefficients. This value must be positive. [in] t Pointer to the reconstructed signal time vector. Vector size is [nt x 1]. [in] nt Size of time vector and reconstructed signal vector . [out] y Pointer to the reconstructed signal vector. Vector size is [nt x 1]. Memory must be allocated.
Returns
RES_OK if function is calculated successfully.
Else code error.
Note
The output reconstructed signal is generally complex. However, subject to the symmetry properties of the vectors w ands with respect to zero frequency we get the imaginary part of the vector y at the EPS level. The negligible imaginary part in this case can be ignored.

Definition at line 415 of file fourier_series.c.

## ◆ goertzel()

 int goertzel ( double * x, int n, int * ind, int k, complex_t * y )

Goertzel algorithm individual DFT samples calculation for the real input vector x.

Goertzel algorithm calculates k samples of n-point DFT, according to ind indexes vector.

Parameters
 [in] x Pointer to the real input vector x Vector size is [n x 1]. [in] n Size of vector x. [in] ind Pointer to the DFT samples indexes which need to calculate by Goertzel algorithm. Vector size is [k x 1]. [in] k Size of vector ind. [out] y Pointer to the DFT samples vector corresponds to indexes ind. Vector size is [k x 1]. Memory must be allocated.
Returns
RES_OK if function is calculated successfully.
Else code error.
Note
Goertzel's algorithm is effective when it is necessary to calculate several DFT samples of a signal of long duration.
However, the size k of the vector of indicesind can be arbitrary, including more than the length of the signal n. In this case, some DFT samples will be repeated, but this will not entail a runtime error.
The values of the indices of the DFT spectral samples ind can also be arbitrary integers, including negative ones. In this case, the DFT samples will be calculated. with indices modulo n.

Definition at line 125 of file goertzel.c.

## ◆ goertzel_cmplx()

 int goertzel_cmplx ( complex_t * x, int n, int * ind, int k, complex_t * y )

Goertzel algorithm individual DFT samples calculation for the complex input vector x.

Goertzel algorithm calculates k samples of n-point DFT, according to ind indexes vector.

Parameters
 [in] x Pointer to the complex input vector x Vector size is [n x 1]. [in] n Size of vector x. [in] ind Pointer to the DFT samples indexes which need to calculate by Goertzel algorithm. Vector size is [k x 1]. [in] k Size of vector ind. [out] y Pointer to the DFT samples vector corresponds to indexes ind. Vector size is [k x 1]. Memory must be allocated.
Returns
RES_OK if function is calculated successfully.
Else code error.
Note
Goertzel's algorithm is effective when it is necessary to calculate several DFT samples of a signal of long duration.
However, the size k of the vector of indicesind can be arbitrary, including more than the length of the signal n. In this case, some DFT samples will be repeated, but this will not entail a runtime error.
The values of the indices of the DFT spectral samples ind can also be arbitrary integers, including negative ones. In this case, the DFT samples will be calculated. with indices modulo n.

Definition at line 263 of file goertzel.c.

## ◆ idft_cmplx()

 int idft_cmplx ( complex_t * x, int n, complex_t * y )

Inverse discrete Fourier transform of the complex spectrum.

The function calculates the $$n$$ -point inverse discrete transform Fourier complex spectrum $$x (m)$$, $$m = 0 \ldots n-1$$.

$y (k) = \sum_ {m = 0} ^ {n-1} x (m) \exp \left (j \frac {2 \pi} {n} m k \right),$

where $$k = 0 \ldots n-1$$.

Parameters
 [in] x Pointer to the vector of the input complex signal spectrum $$x (m)$$, $$m = 0 \ldots n-1$$. The size of the vector is [n x 1]. [in] n The size of the ODPF $$n$$ (the size of the vectors of the input spectrum and the result of the ODPF). [out] y Pointer to the complex vector of the ODPF result $$y (k)$$, $$k = 0 \ldots n-1$$. The size of the vector is [n x 1]. Memory must be allocated.
Returns
RES_OK if the ODPF is calculated successfully.
Otherwise, error code.

An example of using the dft_cmplx function:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dspl.h"
#define N 16
int main()
{
void* handle; /* DSPL handle */
complex_t x[N]; /* complex input signal */
complex_t y[N]; /* DFT */
complex_t z[N]; /* IDFT */
int k;
/* Fill input signal */
for(k = 0; k < N; k++)
{
RE(x[k]) = (double)k;
IM(x[k]) = 0.0;
}
/* DFT */
dft_cmplx(x,N,y);
/* IDFT */
idft_cmplx(y,N,z);
/* print result */
for(k = 0; k < N; k++)
printf("x[%2d] = %9.3f%+9.3fj, z[%2d] = %9.3f%+9.3f\n",
k, RE(x[k]), IM(x[k]), k, RE(z[k]), IM(z[k]));
dspl_free(handle); /* remember to free the resource */
return 0;
}

The result of the program:

x [0] = 0.000 + 0.000j, z [0] = 0.000 -0.000
x [1] = 1.000 + 0.000j, z [1] = 1.000 -0.000
x [2] = 2.000 + 0.000j, z [2] = 2.000 -0.000
x [3] = 3.000 + 0.000j, z [3] = 3.000 -0.000
x [4] = 4.000 + 0.000j, z [4] = 4.000 -0.000
x [5] = 5.000 + 0.000j, z [5] = 5.000 -0.000
x [6] = 6.000 + 0.000j, z [6] = 6.000 -0.000
x [7] = 7.000 + 0.000j, z [7] = 7.000 -0.000
x [8] = 8.000 + 0.000j, z [8] = 8.000 -0.000
x [9] = 9.000 + 0.000j, z [9] = 9.000 -0.000
x [10] = 10.000 + 0.000j, z [10] = 10.000 -0.000
x [11] = 11.000 + 0.000j, z [11] = 11.000 +0.000
x [12] = 12.000 + 0.000j, z [12] = 12.000 +0.000
x [13] = 13.000 + 0.000j, z [13] = 13.000 +0.000
x [14] = 14.000 + 0.000j, z [14] = 14.000 +0.000
x [15] = 15.000 + 0.000j, z [15] = 15.000 -0.000

Note
This function performs the calculation of the DFT using the naive method. and requires $$n ^ 2$$ complex multiplications.
To increase the calculation speed, it is recommended use fast Fourier transform algorithms.

Definition at line 500 of file dft.c.

## ◆ ifft_cmplx()

 int ifft_cmplx ( complex_t * x, int n, fft_t * pfft, complex_t * y )

Inverse fast Fourier transform.

Function calculates $$n$$-point IFFT of complex data $$x(m)$$, $$m = 0 \ldots n-1$$.

$Y(k) = \frac{1}{N} \sum_{m = 0}^{n-1} x(m) \exp \left( j \frac{2\pi}{n} m k \right),$

here $$k = 0 \ldots n-1$$.

Parameters
 [in] x Pointer to the input vector $$x(m)$$, $$m = 0 \ldots n-1$$. Vector size is [n x 1]. [in] n IFFT size $$n$$. IFFT size can be composite: $$n = n_0 \times n_1 \times n_2 \times \ldots \times n_p \times m$$, here $$n_i = 2,3,5,7$$, а $$m$$ – simple number less than 46340 (see fft_create function). [in] pfft Pointer to the fft_t object. This pointer cannot be NULL. Structure fft_t should be previously once filled with the fft_create function, and the memory should be cleared before exiting by the fft_free function. [out] y Pointer to the IFFT result vector $$Y(k)$$, $$k = 0 \ldots n-1$$. Vector size is [n x 1]. Memory must be allocated.
Returns
RES_OK if IFFT is calculated successfully.
Else code error.

IFFT example:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dspl.h"
#define N 18
int main()
{
void* handle; /* DSPL handle */
complex_t x[N]; /* Input signal array */
complex_t y[N]; /* FFT Output signal array */
complex_t z[N]; /* IFFT Output signal array */
fft_t pfft = {0}; /* FFT object (fill zeros) */
int k;
/* Fill FFT structure */
fft_create(&pfft, N);
/* Fill input signal x[k] = exp(j*k) */
for(k = 0; k < N; k++)
{
RE(x[k]) = (double)cos((double)k);
IM(x[k]) = (double)sin((double)k);
}
/* FFT */
fft_cmplx(x, N, &pfft, y);
/* FFT */
ifft_cmplx(y, N, &pfft, z);
/* print result */
for(k = 0; k < N; k++)
{
printf("| x[%2d] = %9.3f%9.3f ", k, RE(x[k]), IM(x[k]));
printf("| y[%2d] = %9.3f%9.3f ", k, RE(y[k]), IM(y[k]));
printf("| z[%2d] = %9.3f%9.3f |\n", k, RE(z[k]), IM(z[k]));
}
fft_free(&pfft); /* Clear fft_t object */
dspl_free(handle); /* Clear DSPL handle */
return 0;
}

Result:

| x[ 0] =  1.000   0.000 | y[ 0] = -0.517   0.686 | z[ 0] =   1.000   0.000 |
| x[ 1] =  0.540   0.841 | y[ 1] = -0.943   0.879 | z[ 1] =   0.540   0.841 |
| x[ 2] = -0.416   0.909 | y[ 2] = -2.299   1.492 | z[ 2] =  -0.416   0.909 |
| x[ 3] = -0.990   0.141 | y[ 3] = 16.078  -6.820 | z[ 3] =  -0.990   0.141 |
| x[ 4] = -0.654  -0.757 | y[ 4] =  2.040  -0.470 | z[ 4] =  -0.654  -0.757 |
| x[ 5] =  0.284  -0.959 | y[ 5] =  1.130  -0.059 | z[ 5] =   0.284  -0.959 |
| x[ 6] =  0.960  -0.279 | y[ 6] =  0.786   0.097 | z[ 6] =   0.960  -0.279 |
| x[ 7] =  0.754   0.657 | y[ 7] =  0.596   0.183 | z[ 7] =   0.754   0.657 |
| x[ 8] = -0.146   0.989 | y[ 8] =  0.470   0.240 | z[ 8] =  -0.146   0.989 |
| x[ 9] = -0.911   0.412 | y[ 9] =  0.375   0.283 | z[ 9] =  -0.911   0.412 |
| x[10] = -0.839  -0.544 | y[10] =  0.297   0.318 | z[10] =  -0.839  -0.544 |
| x[11] =  0.004  -1.000 | y[11] =  0.227   0.350 | z[11] =   0.004  -1.000 |
| x[12] =  0.844  -0.537 | y[12] =  0.161   0.380 | z[12] =   0.844  -0.537 |
| x[13] =  0.907   0.420 | y[13] =  0.094   0.410 | z[13] =   0.907   0.420 |
| x[14] =  0.137   0.991 | y[14] =  0.023   0.442 | z[14] =   0.137   0.991 |
| x[15] = -0.760   0.650 | y[15] = -0.059   0.479 | z[15] =  -0.760   0.650 |
| x[16] = -0.958  -0.288 | y[16] = -0.161   0.525 | z[16] =  -0.958  -0.288 |
| x[17] = -0.275  -0.961 | y[17] = -0.300   0.588 | z[17] =  -0.275  -0.961 |


Definition at line 180 of file fft.c.

Referenced by conv_fft_cmplx().

#define RE(x)
Macro sets real part of the complex number.
Definition: dspl.h:420
int DSPL_API idft_cmplx(complex_t *x, int n, complex_t *y)
Inverse discrete Fourier transform of the complex spectrum.
Definition: dft.c:500
int DSPL_API fft_create(fft_t *pfft, int n)
Function creates and fill fft_t structure.
Definition: fft.c:935
int DSPL_API fft_cmplx(complex_t *x, int n, fft_t *pfft, complex_t *y)
Fast Fourier transform for the complex vector.
Definition: fft.c:646
int DSPL_API ifft_cmplx(complex_t *x, int n, fft_t *pfft, complex_t *y)
Inverse fast Fourier transform.
Definition: fft.c:180
void DSPL_API fft_free(fft_t *pfft)
Free fft_t structure.
Definition: fft.c:1177
Fast Fourier Transform Object Data Structure.
Definition: dspl.h:278
int DSPL_API fft(double *x, int n, fft_t *pfft, complex_t *y)
Fast Fourier transform for the real vector.
Definition: fft.c:357
double complex_t[2]
Complex data type.
Definition: dspl.h:86
void dspl_free(void *handle)
Cleans up the previously linked DSPL-2.0 dynamic library.
int DSPL_API dft_cmplx(complex_t *x, int n, complex_t *y)
Discrete Fourier transform of a complex signal.
Definition: dft.c:329
#define IM(x)
Macro sets imaginary part of the complex number.
Definition: dspl.h:478
int DSPL_API dft(double *x, int n, complex_t *y)
Discrete Fourier transform of a real signal.
Definition: dft.c:163