kopia lustrzana https://github.com/Dsplib/libdspl-2.0
217 wiersze
5.8 KiB
Plaintext
217 wiersze
5.8 KiB
Plaintext
|
|
/*! ****************************************************************************
|
|
\ingroup DFT_GROUP
|
|
\fn int dft(double* x, int n, complex_t* y)
|
|
\brief Discrete Fourier transform of a real signal.
|
|
|
|
The function calculates the \f$ n \f$ -point discrete Fourier transform
|
|
real signal \f$ x (m) \f$, \f$ m = 0 \ldots n-1 \f$. \n
|
|
\f[
|
|
Y (k) = \sum_ {m = 0} ^ {n-1} x (m)
|
|
\exp \left (-j \frac {2 \pi} {n} m k \right),
|
|
\f]
|
|
where \f$ k = 0 \ldots n-1 \f$.
|
|
|
|
\param [in] x
|
|
Pointer to the vector of the real input signal \f$ x (m) \f$,
|
|
\f$ m = 0 \ldots n-1 \f$. \n
|
|
The size of the vector is `[n x 1]`. \n \n
|
|
|
|
\param [in] n
|
|
The size of the DFT \f$ n \f$
|
|
(the size of the vectors of the input signal and the result of the DFT). \n \n
|
|
|
|
\param [out] y
|
|
Pointer to the complex vector of the DFT result \f$ Y (k) \f$,
|
|
\f$ k = 0 \ldots n-1 \f$.
|
|
The size of the vector is `[n x 1]`. \n
|
|
Memory must be allocated. \n \n
|
|
|
|
|
|
\return
|
|
`RES_OK` if the DFT is calculated successfully. \n
|
|
Otherwise, \ref ERROR_CODE_GROUP "error code".
|
|
|
|
An example of using the `dft` function:
|
|
|
|
\include dft_test.c
|
|
|
|
The result of the program:
|
|
|
|
\verbatim
|
|
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
|
|
\endverbatim
|
|
|
|
\note
|
|
This function performs the DFT calculation using the naive method and requires \f$ n ^ 2 \f$
|
|
complex multiplications. \n
|
|
To increase the calculation speed, it is recommended to use
|
|
fast Fourier transform algorithms.
|
|
|
|
\author
|
|
Bakhurin Sergey
|
|
www.dsplib.org
|
|
**************************************************************************** */
|
|
|
|
|
|
|
|
/*! ****************************************************************************
|
|
\ingroup DFT_GROUP
|
|
\fn int dft_cmplx(complex_t* x, int n, complex_t* y)
|
|
\brief Discrete Fourier transform of a complex signal.
|
|
|
|
The function calculates the \f$ n \f$ -point discrete Fourier transform
|
|
complex signal \f$ x (m) \f$, \f$ m = 0 \ldots n-1 \f$. \n
|
|
\f[
|
|
Y (k) = \sum_ {m = 0} ^ {n-1} x (m)
|
|
\exp \left (-j \frac {2 \pi} {n} m k \right),
|
|
\f]
|
|
where \f$ k = 0 \ldots n-1 \f$.
|
|
|
|
\param [in] x
|
|
Pointer to a vector of complex
|
|
input signal \f$ x (m) \f$, \f$ m = 0 \ldots n-1 \f$. \n
|
|
The size of the vector is `[n x 1]`. \n \n
|
|
|
|
\param [in] n
|
|
The size of the DFT \f$ n \f$
|
|
(the size of the vectors of the input signal and the result of the DFT). \n \n
|
|
|
|
\param [out] y
|
|
Integrated Vector Pointer
|
|
DFT result \f$ Y (k) \f$, \f$ k = 0 \ldots n-1 \f$. \n
|
|
The size of the vector is `[n x 1]`. \n
|
|
Memory must be allocated. \n \n
|
|
|
|
|
|
\return
|
|
`RES_OK` if the DFT is calculated successfully. \n
|
|
Otherwise, \ref ERROR_CODE_GROUP "error code".
|
|
|
|
An example of using the `dft_cmplx` function:
|
|
|
|
\include dft_cmplx_test.c
|
|
|
|
The result of the program:
|
|
|
|
\verbatim
|
|
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
|
|
\endverbatim
|
|
|
|
\note
|
|
This function performs the calculation of the DFT by the naive method
|
|
and requires \f$ n ^ 2 \f$ complex multiplications. \n
|
|
To increase the calculation speed, it is recommended
|
|
use fast Fourier transform algorithms.
|
|
|
|
\author
|
|
Bakhurin Sergey
|
|
www.dsplib.org
|
|
***************************************************************************** */
|
|
|
|
|
|
|
|
|
|
/*! ****************************************************************************
|
|
\ingroup DFT_GROUP
|
|
\fn int idft_cmplx(complex_t* x, int n, complex_t* y)
|
|
\brief Inverse discrete Fourier transform of the complex spectrum.
|
|
|
|
The function calculates the \f$ n \f$ -point inverse discrete transform
|
|
Fourier complex spectrum \f$ x (m) \f$, \f$ m = 0 \ldots n-1 \f$. \n
|
|
\f[
|
|
y (k) = \sum_ {m = 0} ^ {n-1} x (m)
|
|
\exp \left (j \frac {2 \pi} {n} m k \right),
|
|
\f]
|
|
where \f$ k = 0 \ldots n-1 \f$.
|
|
|
|
\param [in] x
|
|
Pointer to the vector of the input complex signal spectrum \f$ x (m) \f$,
|
|
\f$ m = 0 \ldots n-1 \f$. \n
|
|
The size of the vector is `[n x 1]`. \n \n
|
|
|
|
\param [in] n
|
|
The size of the ODPF \f$ n \f$
|
|
(the size of the vectors of the input spectrum and the result of the ODPF). \n \n
|
|
|
|
\param [out] y
|
|
Pointer to the complex vector of the ODPF result \f$ y (k) \f$,
|
|
\f$ k = 0 \ldots n-1 \f$.
|
|
The size of the vector is `[n x 1]`. \n
|
|
Memory must be allocated. \n \n
|
|
|
|
|
|
\return
|
|
`RES_OK` if the ODPF is calculated successfully. \n
|
|
Otherwise, \ref ERROR_CODE_GROUP "error code".
|
|
|
|
An example of using the `dft_cmplx` function:
|
|
|
|
\include idft_cmplx_test.c
|
|
|
|
The result of the program:
|
|
|
|
\verbatim
|
|
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
|
|
\endverbatim
|
|
|
|
\note
|
|
This function performs the calculation of the DFT using the naive method.
|
|
and requires \f$ n ^ 2 \f$ complex multiplications. \n
|
|
To increase the calculation speed, it is recommended
|
|
use fast Fourier transform algorithms.
|
|
|
|
\author
|
|
Bakhurin Sergey
|
|
www.dsplib.org
|
|
***************************************************************************** */
|
|
|
|
|
|
|
|
|