kopia lustrzana https://github.com/Dsplib/libdspl-2.0
addded documenation for complex functions and convolution
rodzic
8df0c8fa66
commit
973a6495c6
|
@ -1 +1,6 @@
|
|||
# libdspl-2.0
|
||||
# libdspl-2.0 Digital signal processing library
|
||||
|
||||
|
||||
|
||||
libdspl-2.0 is free cross-platform library of digital signal processing algorithms.
|
||||
libdspl-2.0 includes the following groups of algorithms:
|
||||
|
|
|
@ -21,7 +21,7 @@ DSPL-2.0 - свободная библиотека алгоритмов цифр
|
|||
Библиотека поддерживает работу с вещественными и
|
||||
комплексными типами входных данных. <BR>
|
||||
|
||||
Описание испльзуемых типов:<BR>
|
||||
Описание используемых типов:<BR>
|
||||
|
||||
\ref TYPES_GROUP <BR>
|
||||
|
||||
|
|
|
@ -358,6 +358,65 @@ cos_cmplx(5.0+6.0j) = 57.219 +193.428j
|
|||
|
||||
|
||||
|
||||
/*! ****************************************************************************
|
||||
\ingroup SPEC_MATH_COMMON_GROUP
|
||||
\fn int log_cmplx(complex_t* x, int n, complex_t *y)
|
||||
\brief Натуральный логарифм комплексного аргумента `x`
|
||||
|
||||
Функция рассчитывает значения натурального логарифма комплексного аргумента,
|
||||
заданного вектором `x` длины `n`: <BR>
|
||||
\f[
|
||||
\textrm{Ln}(x) = j \varphi + \ln(|x|),
|
||||
\f]
|
||||
где \f$\varphi\f$ - фаза комплексного числа.
|
||||
|
||||
\param[in] x Указатель на комплексный вектор аргумента логарифма.<BR>
|
||||
Размер вектора `[n x 1]`. <BR><BR>
|
||||
|
||||
\param[in] n Размер входного и выходного векторов `x` и `y`.<BR><BR>
|
||||
|
||||
|
||||
\param[out] y Указатель на вектор значений комплексного логарифма,
|
||||
соответствующего входному вектору `x`.<BR>
|
||||
Размер массива `[n x 1]`. <BR>
|
||||
Память должна быть выделена. <BR><BR>
|
||||
|
||||
\return
|
||||
`RES_OK` если значение функции рассчитано успешно. <BR>
|
||||
В противном случае \ref ERROR_CODE_GROUP "код ошибки":<BR>
|
||||
|
||||
Например при выполнении следующего кода
|
||||
\code{.cpp}
|
||||
complex_t x[3] = {{1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}};
|
||||
complex_t y[3];
|
||||
int k;
|
||||
|
||||
log_cmplx(x, 3, y);
|
||||
|
||||
for(k = 0; k < 3; k++)
|
||||
printf("log_cmplx(%.1f%+.1fj) = %.3f%+.3fj\n",
|
||||
RE(x[k]), IM(x[k]), RE(y[k]), IM(y[k]));
|
||||
|
||||
\endcode
|
||||
<BR>
|
||||
|
||||
Результатом работы будет
|
||||
|
||||
\verbatim
|
||||
log_cmplx(1.0+2.0j) = 0.805+1.107j
|
||||
log_cmplx(3.0+4.0j) = 1.609+0.927j
|
||||
log_cmplx(5.0+6.0j) = 2.055+0.876j
|
||||
\endverbatim
|
||||
|
||||
\author
|
||||
Бахурин Сергей www.dsplib.org
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -370,7 +429,7 @@ cos_cmplx(5.0+6.0j) = 57.219 +193.428j
|
|||
исходного вещественного массива `x`. <BR>
|
||||
|
||||
|
||||
\param[in] x Указатель на массв вещественных данных.<BR>
|
||||
\param[in] x Указатель на массив вещественных данных.<BR>
|
||||
Размер массива `[n x 1]`. <BR><BR>
|
||||
|
||||
\param[in] n Размер массивов входных и выходных данных.<BR><BR>
|
||||
|
@ -403,7 +462,120 @@ cos_cmplx(5.0+6.0j) = 57.219 +193.428j
|
|||
\endverbatim
|
||||
|
||||
\author
|
||||
Бахурин Сергей.
|
||||
www.dsplib.org
|
||||
Бахурин Сергей. www.dsplib.org
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*! ****************************************************************************
|
||||
\ingroup SPEC_MATH_TRIG_GROUP
|
||||
\fn int sin_cmplx(complex_t* x, int n, complex_t *y)
|
||||
\brief Синус комплексного аргумента `x`
|
||||
|
||||
Функция рассчитывает значения синуса комплексного аргумента,
|
||||
заданного вектором `x` длины `n`: <BR>
|
||||
\f[
|
||||
\textrm{sin}(x) = \frac{\exp(jx) - \exp(-jx)}{2j}
|
||||
\f]
|
||||
|
||||
|
||||
\param[in] x Указатель на вектор аргумента комплексного синуса.<BR>
|
||||
Размер вектора `[n x 1]`. <BR><BR>
|
||||
|
||||
\param[in] n Размер входного и выходного векторов `x` и `y`.<BR><BR>
|
||||
|
||||
|
||||
\param[out] y Указатель на вектор значений комплексного синуса,
|
||||
соответствующего входному вектору `x`.<BR>
|
||||
Размер массива `[n x 1]`. <BR>
|
||||
Память должна быть выделена. <BR><BR>
|
||||
|
||||
\return
|
||||
`RES_OK` если значение функции рассчитано успешно . <BR>
|
||||
В противном случае \ref ERROR_CODE_GROUP "код ошибки":<BR>
|
||||
|
||||
Например при выполнении следующего кода
|
||||
\code{.cpp}
|
||||
complex_t x[3] = {{1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}};
|
||||
complex_t y[3];
|
||||
int k;
|
||||
|
||||
sin_cmplx(x, 3, y);
|
||||
|
||||
for(k = 0; k < 3; k++)
|
||||
printf("sin_cmplx(%.1f%+.1fj) = %9.3f%+9.3fj\n",
|
||||
RE(x[k]), IM(x[k]), RE(y[k]), IM(y[k]));
|
||||
|
||||
\endcode
|
||||
<BR>
|
||||
|
||||
Результатом работы будет
|
||||
|
||||
\verbatim
|
||||
sin_cmplx(1.0+2.0j) = 3.166 +1.960j
|
||||
sin_cmplx(3.0+4.0j) = 3.854 -27.017j
|
||||
sin_cmplx(5.0+6.0j) = -193.430 +57.218j
|
||||
\endverbatim
|
||||
|
||||
\author
|
||||
Бахурин Сергей www.dsplib.org
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
|
||||
|
||||
/*! ****************************************************************************
|
||||
\ingroup SPEC_MATH_COMMON_GROUP
|
||||
\fn int sqrt_cmplx(complex_t* x, int n, complex_t *y)
|
||||
\brief Квадратный корень из комплексного вектора `x` (поэлементный).
|
||||
|
||||
Функция рассчитывает значения квадратного корня комплексного аргумента,
|
||||
заданного вектором `x` длины `n`: <BR>
|
||||
\f[
|
||||
y(k) = \sqrt{x(k)}, \qquad k = 0 \ldots n-1.
|
||||
\f]
|
||||
|
||||
|
||||
\param[in] x Указатель на вектор аргумента квадратного корня.<BR>
|
||||
Размер вектора `[n x 1]`. <BR><BR>
|
||||
|
||||
\param[in] n Размер входного и выходного векторов `x` и `y`.<BR><BR>
|
||||
|
||||
|
||||
\param[out] y Указатель на вектор значений комплексного корня,
|
||||
соответствующего входному вектору `x`.<BR>
|
||||
Размер массива `[n x 1]`. <BR>
|
||||
Память должна быть выделена. <BR><BR>
|
||||
|
||||
\return
|
||||
`RES_OK` если значение функции рассчитано успешно . <BR>
|
||||
В противном случае \ref ERROR_CODE_GROUP "код ошибки":<BR>
|
||||
|
||||
Например при выполнении следующего кода
|
||||
\code{.cpp}
|
||||
complex_t x[3] = {{1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}};
|
||||
complex_t y[3];
|
||||
int k;
|
||||
|
||||
sqrt_cmplx(x, 3, y);
|
||||
|
||||
for(k = 0; k < 3; k++)
|
||||
printf("sqrt_cmplx(%.1f%+.1fj) = %.3f%+.3fj\n",
|
||||
RE(x[k]), IM(x[k]), RE(y[k]), IM(y[k]));
|
||||
|
||||
\endcode
|
||||
<BR>
|
||||
|
||||
Результатом работы будет
|
||||
|
||||
\verbatim
|
||||
sqrt_cmplx(1.0+2.0j) = 1.272+0.786j
|
||||
sqrt_cmplx(3.0+4.0j) = 2.000+1.000j
|
||||
sqrt_cmplx(5.0+6.0j) = 2.531+1.185j
|
||||
\endverbatim
|
||||
|
||||
\author
|
||||
Бахурин Сергей www.dsplib.org
|
||||
***************************************************************************** */
|
||||
|
|
|
@ -24,9 +24,38 @@
|
|||
`RES_OK` если свертка расчитана успешно.<BR>
|
||||
В противном случае \ref ERROR_CODE_GROUP "код ошибки".
|
||||
|
||||
\author
|
||||
Бахурин Сергей
|
||||
www.dsplib.org
|
||||
\note Если вектора `a` и `b` представляют собой коэффициенты двух полиномов,
|
||||
то результат линейной свертки представляет собой коэффициенты произведения
|
||||
исходных полиномов.
|
||||
|
||||
Пример использования функции:
|
||||
|
||||
\code{.cpp}
|
||||
double ar[3] = {1.0, 2.0, 3.0};
|
||||
double br[4] = {3.0, -1.0, 2.0, 4.0};
|
||||
double cr[6];
|
||||
|
||||
int n;
|
||||
|
||||
conv(ar, 3, br, 4, cr);
|
||||
|
||||
for(n = 0; n < 6; n++)
|
||||
printf("cr[%d] = %5.1f\n", n, cr[n]);
|
||||
|
||||
\endcode
|
||||
<BR>
|
||||
|
||||
Результат работы:
|
||||
\verbatim
|
||||
cr[0] = 3.0
|
||||
cr[1] = 5.0
|
||||
cr[2] = 9.0
|
||||
cr[3] = 5.0
|
||||
cr[4] = 14.0
|
||||
cr[5] = 12.0
|
||||
\endverbatim
|
||||
|
||||
\author Бахурин Сергей www.dsplib.org
|
||||
**************************************************************************** */
|
||||
|
||||
|
||||
|
@ -62,9 +91,39 @@ www.dsplib.org
|
|||
`RES_OK` если свертка расчитана успешно.<BR>
|
||||
В противном случае \ref ERROR_CODE_GROUP "код ошибки".
|
||||
|
||||
\author
|
||||
Бахурин Сергей
|
||||
www.dsplib.org
|
||||
|
||||
\note Если вектора `a` и `b` представляют собой коэффициенты двух полиномов,
|
||||
то результат линейной свертки представляет собой коэффициенты произведения
|
||||
исходных полиномов.
|
||||
|
||||
Пример использования функции:
|
||||
|
||||
\code{.cpp}
|
||||
complex_t ac[3] = {{0.0, 1.0}, {1.0, 1.0}, {2.0, 2.0}};
|
||||
complex_t bc[4] = {{3.0, 3.0}, {4.0, 4.0}, {5.0, 5.0}, {6.0, 6.0}};
|
||||
complex_t cc[6];
|
||||
|
||||
int n;
|
||||
|
||||
conv_cmplx(ac, 3, bc, 4, cc);
|
||||
|
||||
for(n = 0; n < 6; n++)
|
||||
printf("cc[%d] = %5.1f%+5.1fj\n", n, RE(cc[n]),IM(cc[n]));
|
||||
|
||||
\endcode
|
||||
<BR>
|
||||
|
||||
Результат работы:
|
||||
\verbatim
|
||||
cc[0] = -3.0 +3.0j
|
||||
cc[1] = -4.0+10.0j
|
||||
cc[2] = -5.0+25.0j
|
||||
cc[3] = -6.0+32.0j
|
||||
cc[4] = 0.0+32.0j
|
||||
cc[5] = 0.0+24.0j
|
||||
\endverbatim
|
||||
|
||||
\author Бахурин Сергей www.dsplib.org
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
|
|
|
@ -321,7 +321,55 @@ int DSPL_API cos_cmplx(complex_t* x, int n, complex_t *y)
|
|||
|
||||
|
||||
/******************************************************************************
|
||||
Logarithm complex
|
||||
\ingroup SPEC_MATH_COMMON_GROUP
|
||||
\fn int log_cmplx(complex_t* x, int n, complex_t *y)
|
||||
\brief The logarithm function the complex vector argument `x`
|
||||
|
||||
Function calculates the logarithm function as:<BR>
|
||||
|
||||
\f[
|
||||
\textrm{Ln}(x) = j \varphi + \ln(|x|),
|
||||
\f]
|
||||
here \f$\varphi\f$ - the complex number phase.
|
||||
|
||||
\param[in] x Pointer to the argument vector `x`.<BR>
|
||||
Vector size is `[n x 1]`. <BR><BR>
|
||||
|
||||
\param[in] n Input vector `x` and the logarithm vector `y` size.<BR><BR>
|
||||
|
||||
|
||||
\param[out] y Pointer to the output complex vector `y`,
|
||||
corresponds to the input vector `x`.<BR>
|
||||
Vector size is `[n x 1]`. <BR>
|
||||
Memory must be allocated. <BR><BR>
|
||||
|
||||
\return
|
||||
`RES_OK` if function calculated successfully. <BR>
|
||||
Else \ref ERROR_CODE_GROUP "code error".<BR>
|
||||
|
||||
Example:<BR>
|
||||
\code{.cpp}
|
||||
complex_t x[3] = {{1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}};
|
||||
complex_t y[3];
|
||||
int k;
|
||||
|
||||
log_cmplx(x, 3, y);
|
||||
|
||||
for(k = 0; k < 3; k++)
|
||||
printf("log_cmplx(%.1f%+.1fj) = %.3f%+.3fj\n",
|
||||
RE(x[k]), IM(x[k]), RE(y[k]), IM(y[k]));
|
||||
\endcode
|
||||
<BR>
|
||||
|
||||
Output is:<BR>
|
||||
\verbatim
|
||||
log_cmplx(1.0+2.0j) = 0.805+1.107j
|
||||
log_cmplx(3.0+4.0j) = 1.609+0.927j
|
||||
log_cmplx(5.0+6.0j) = 2.055+0.876j
|
||||
\endverbatim
|
||||
|
||||
\author
|
||||
Sergey Bakhurin www.dsplib.org
|
||||
*******************************************************************************/
|
||||
int DSPL_API log_cmplx(complex_t* x, int n, complex_t *y)
|
||||
{
|
||||
|
@ -346,7 +394,49 @@ int DSPL_API log_cmplx(complex_t* x, int n, complex_t *y)
|
|||
|
||||
|
||||
/******************************************************************************
|
||||
convert double array to a complex array
|
||||
\ingroup TYPES_GROUP
|
||||
\fn int re2cmplx(double* x, int n, complex_t *y)
|
||||
\brief Convert real array to the complex array.
|
||||
|
||||
Function copies the vector `x` to the real part of vector `y`.
|
||||
Image part of the vector `y` sets as zero.<BR>
|
||||
So complex vector contains data:<BR>
|
||||
`y[i] = x[i] + j0, here i = 0,1,2 ... n-1`
|
||||
|
||||
|
||||
\param[in] x Pointer to the real vector `x`.<BR>
|
||||
Vector size is `[n x 1]`. <BR><BR>
|
||||
|
||||
\param[in] n Size of the real vector `x` and complex vector `y`.<BR><BR>
|
||||
|
||||
\param[out] y Pointer to the complex vector `y`.<BR>
|
||||
Vector size is `[n x 1]`. <BR>
|
||||
Memory must be allocated. <BR><BR>
|
||||
|
||||
|
||||
\return
|
||||
`RES_OK` if function returns successfully. <BR>
|
||||
Else \ref ERROR_CODE_GROUP "code error":<BR>
|
||||
|
||||
|
||||
|
||||
Например при выполнении следующего кода
|
||||
\code{.cpp}
|
||||
double x[3] = {1.0, 2.0, 3.0};
|
||||
complex_t y[3];
|
||||
|
||||
re2cmplx(x, 3, y);
|
||||
\endcode
|
||||
|
||||
Vector `y` will keep:
|
||||
|
||||
\verbatim
|
||||
y[0] = 1+0j;
|
||||
y[1] = 2+0j;
|
||||
y[2] = 3+0j.
|
||||
\endverbatim
|
||||
|
||||
\author Sergey Bakhurin. www.dsplib.org
|
||||
*******************************************************************************/
|
||||
int DSPL_API re2cmplx(double* x, int n, complex_t* y)
|
||||
{
|
||||
|
@ -369,7 +459,56 @@ int DSPL_API re2cmplx(double* x, int n, complex_t* y)
|
|||
|
||||
|
||||
/******************************************************************************
|
||||
Complex cosine
|
||||
\ingroup SPEC_MATH_TRIG_GROUP
|
||||
\fn int sin_cmplx(complex_t* x, int n, complex_t *y)
|
||||
\brief The sine function the complex vector argument `x`
|
||||
|
||||
Function calculates the sine function as:<BR>
|
||||
|
||||
\f[
|
||||
\textrm{cos}(x) = \frac{\exp(jx) - \exp(-jx)}{2j}
|
||||
\f]
|
||||
|
||||
|
||||
\param[in] x Pointer to the argument vector `x`.<BR>
|
||||
Vector size is `[n x 1]`. <BR><BR>
|
||||
|
||||
\param[in] n Input vector `x` and the sine vector `y` size.<BR><BR>
|
||||
|
||||
|
||||
\param[out] y Pointer to the output complex vector `y`,
|
||||
corresponds to the input vector `x`.<BR>
|
||||
Vector size is `[n x 1]`. <BR>
|
||||
Memory must be allocated. <BR><BR>
|
||||
|
||||
\return
|
||||
`RES_OK` if function calculated successfully. <BR>
|
||||
Else \ref ERROR_CODE_GROUP "code error".<BR>
|
||||
|
||||
Example:<BR>
|
||||
\code{.cpp}
|
||||
complex_t x[3] = {{1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}};
|
||||
complex_t y[3];
|
||||
int k;
|
||||
|
||||
sin_cmplx(x, 3, y);
|
||||
|
||||
for(k = 0; k < 3; k++)
|
||||
printf("sin_cmplx(%.1f%+.1fj) = %9.3f%+9.3fj\n",
|
||||
RE(x[k]), IM(x[k]), RE(y[k]), IM(y[k]));
|
||||
|
||||
\endcode
|
||||
<BR>
|
||||
|
||||
Output is:<BR>
|
||||
\verbatim
|
||||
sin_cmplx(1.0+2.0j) = 3.166 +1.960j
|
||||
sin_cmplx(3.0+4.0j) = 3.854 -27.017j
|
||||
sin_cmplx(5.0+6.0j) = -193.430 +57.218j
|
||||
\endverbatim
|
||||
|
||||
\author
|
||||
Sergey Bakhurin www.dsplib.org
|
||||
*******************************************************************************/
|
||||
int DSPL_API sin_cmplx(complex_t* x, int n, complex_t *y)
|
||||
{
|
||||
|
@ -398,7 +537,53 @@ int DSPL_API sin_cmplx(complex_t* x, int n, complex_t *y)
|
|||
|
||||
|
||||
/******************************************************************************
|
||||
SQRT complex
|
||||
\ingroup SPEC_MATH_COMMON_GROUP
|
||||
\fn int sqrt_cmplx(complex_t* x, int n, complex_t *y)
|
||||
\brief Square root of the complex vector argguument `x`.
|
||||
|
||||
Function calculates square root value of vector `x` length `n`: <BR>
|
||||
\f[
|
||||
y(k) = \sqrt{x(k)}, \qquad k = 0 \ldots n-1.
|
||||
\f]
|
||||
|
||||
|
||||
\param[in] x Pointer to the input complex vector `x`.<BR>
|
||||
Vector size is `[n x 1]`. <BR><BR>
|
||||
|
||||
\param[in] n Size of input and output vectors `x` and `y`.<BR><BR>
|
||||
|
||||
|
||||
\param[out] y Pointer to the square root vector `y`.<BR>
|
||||
Vector size is `[n x 1]`. <BR>
|
||||
Memory must be allocated. <BR><BR>
|
||||
|
||||
\return `RES_OK` if function is calculated successfully. <BR>
|
||||
Else \ref ERROR_CODE_GROUP "code error".<BR>
|
||||
|
||||
Example
|
||||
\code{.cpp}
|
||||
complex_t x[3] = {{1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}};
|
||||
complex_t y[3]
|
||||
int k;
|
||||
|
||||
sqrt_cmplx(x, 3, y);
|
||||
|
||||
for(k = 0; k < 3; k++)
|
||||
printf("sqrt_cmplx(%.1f%+.1fj) = %.3f%+.3fj\n",
|
||||
RE(x[k]), IM(x[k]), RE(y[k]), IM(y[k]));
|
||||
|
||||
\endcode
|
||||
<BR>
|
||||
|
||||
Результатом работы будет
|
||||
|
||||
\verbatim
|
||||
sqrt_cmplx(1.0+2.0j) = 1.272+0.786j
|
||||
sqrt_cmplx(3.0+4.0j) = 2.000+1.000j
|
||||
sqrt_cmplx(5.0+6.0j) = 2.531+1.185j
|
||||
\endverbatim
|
||||
|
||||
\author Sergey Bakhurin www.dsplib.org
|
||||
*******************************************************************************/
|
||||
int DSPL_API sqrt_cmplx(complex_t* x, int n, complex_t *y)
|
||||
{
|
||||
|
|
112
dspl/src/conv.c
112
dspl/src/conv.c
|
@ -27,7 +27,61 @@
|
|||
|
||||
|
||||
/*******************************************************************************
|
||||
Real vectors linear convolution
|
||||
\ingroup FILTER_CONV_GROUP
|
||||
\fn int conv(double* a, int na, double* b, int nb, double* c)
|
||||
\brief Real vectors linear convolution.
|
||||
|
||||
Function convolves two real vectors \f$ c = a * b\f$ length `na` and `nb`.
|
||||
The output convolution is a vector `c` with length equal to `na + nb - 1`.
|
||||
|
||||
\param[in] a Pointer to the first vector `a`.<BR>
|
||||
Vector size is `[na x 1]`.<BR><BR>
|
||||
|
||||
\param[in] na Size of the first vector `a`.<BR><BR>
|
||||
|
||||
\param[in] b Pointer to the second vector `b`.<BR>
|
||||
Vector size is `[nb x 1]`.<BR><BR>
|
||||
|
||||
\param[in] nb Size of the second vector `b`.<BR><BR>
|
||||
|
||||
\param[out] c Pointer to the convolution output vector \f$ c = a * b\f$.<BR>
|
||||
Vector size is `[na + nb - 1 x 1]`.<BR>
|
||||
Memory must be allocated.<BR><BR>
|
||||
|
||||
\return `RES_OK` if convolution is calculated successfully.<BR>
|
||||
Else \ref ERROR_CODE_GROUP "code error".
|
||||
|
||||
\note If vectors `a` and `b` are coefficients of two polynomials,
|
||||
then convolution of the vectors `a` and `b` returns polynomial product
|
||||
coefficients.
|
||||
|
||||
Example:
|
||||
\code{.cpp}
|
||||
double ar[3] = {1.0, 2.0, 3.0};
|
||||
double br[4] = {3.0, -1.0, 2.0, 4.0};
|
||||
double cr[6];
|
||||
|
||||
int n;
|
||||
|
||||
conv(ar, 3, br, 4, cr);
|
||||
|
||||
for(n = 0; n < 6; n++)
|
||||
printf("cr[%d] = %5.1f\n", n, cr[n]);
|
||||
|
||||
\endcode
|
||||
<BR>
|
||||
|
||||
Output:
|
||||
\verbatim
|
||||
cr[0] = 3.0
|
||||
cr[1] = 5.0
|
||||
cr[2] = 9.0
|
||||
cr[3] = 5.0
|
||||
cr[4] = 14.0
|
||||
cr[5] = 12.0
|
||||
\endverbatim
|
||||
|
||||
\author Sergey Bakhurin www.dsplib.org
|
||||
*******************************************************************************/
|
||||
int DSPL_API conv(double* a, int na, double* b, int nb, double* c)
|
||||
{
|
||||
|
@ -70,7 +124,61 @@ int DSPL_API conv(double* a, int na, double* b, int nb, double* c)
|
|||
|
||||
|
||||
/******************************************************************************
|
||||
Complex vectors linear convolution
|
||||
\ingroup FILTER_CONV_GROUP
|
||||
\fn int conv_cmplx(complex_t* a, int na, complex_t* b, int nb, complex_t* c)
|
||||
\brief Complex vectors linear convolution.
|
||||
|
||||
Function convolves two complex vectors \f$ c = a * b\f$ length `na` and `nb`.
|
||||
The output convolution is a vector `c` with length equal to `na + nb - 1`.
|
||||
|
||||
\param[in] a Pointer to the first vector `a`.<BR>
|
||||
Vector size is `[na x 1]`.<BR><BR>
|
||||
|
||||
\param[in] na Size of the first vector `a`.<BR><BR>
|
||||
|
||||
\param[in] b Pointer to the second vector `b`.<BR>
|
||||
Vector size is `[nb x 1]`.<BR><BR>
|
||||
|
||||
\param[in] nb Size of the second vector `b`.<BR><BR>
|
||||
|
||||
\param[out] c Pointer to the convolution output vector \f$ c = a * b\f$.<BR>
|
||||
Vector size is `[na + nb - 1 x 1]`.<BR>
|
||||
Memory must be allocated.<BR><BR>
|
||||
|
||||
\return `RES_OK` if convolution is calculated successfully.<BR>
|
||||
Else \ref ERROR_CODE_GROUP "code error".
|
||||
|
||||
\note If vectors `a` and `b` are coefficients of two polynomials,
|
||||
then convolution of the vectors `a` and `b` returns polynomial product
|
||||
coefficients.
|
||||
|
||||
Example:
|
||||
\code{.cpp}
|
||||
complex_t ac[3] = {{0.0, 1.0}, {1.0, 1.0}, {2.0, 2.0}};
|
||||
complex_t bc[4] = {{3.0, 3.0}, {4.0, 4.0}, {5.0, 5.0}, {6.0, 6.0}};
|
||||
complex_t cc[6];
|
||||
|
||||
int n;
|
||||
|
||||
conv_cmplx(ac, 3, bc, 4, cc);
|
||||
|
||||
for(n = 0; n < 6; n++)
|
||||
printf("cc[%d] = %5.1f%+5.1fj\n", n, RE(cc[n]),IM(cc[n]));
|
||||
|
||||
\endcode
|
||||
<BR>
|
||||
|
||||
Output:
|
||||
\verbatim
|
||||
cc[0] = -3.0 +3.0j
|
||||
cc[1] = -4.0+10.0j
|
||||
cc[2] = -5.0+25.0j
|
||||
cc[3] = -6.0+32.0j
|
||||
cc[4] = 0.0+32.0j
|
||||
cc[5] = 0.0+24.0j
|
||||
\endverbatim
|
||||
|
||||
\author Sergey Bakhurin www.dsplib.org
|
||||
*******************************************************************************/
|
||||
int DSPL_API conv_cmplx(complex_t* a, int na, complex_t* b,
|
||||
int nb, complex_t* c)
|
||||
|
|
|
@ -30,6 +30,25 @@ int main()
|
|||
printf("cos_cmplx(%.1f%+.1fj) = %9.3f%+9.3fj\n",
|
||||
RE(x[k]), IM(x[k]), RE(y[k]), IM(y[k]));
|
||||
|
||||
printf("\n\nlog_cmplx\n---------------------------------\n");
|
||||
log_cmplx(x, 3, y);
|
||||
for(k = 0; k < 3; k++)
|
||||
printf("log_cmplx(%.1f%+.1fj) = %.3f%+.3fj\n",
|
||||
RE(x[k]), IM(x[k]), RE(y[k]), IM(y[k]));
|
||||
|
||||
printf("\n\nsin_cmplx\n---------------------------------\n");
|
||||
sin_cmplx(x, 3, y);
|
||||
for(k = 0; k < 3; k++)
|
||||
printf("sin_cmplx(%.1f%+.1fj) = %9.3f%+9.3fj\n",
|
||||
RE(x[k]), IM(x[k]), RE(y[k]), IM(y[k]));
|
||||
|
||||
printf("\n\nsqrt_cmplx\n---------------------------------\n");
|
||||
sqrt_cmplx(x, 3, y);
|
||||
for(k = 0; k < 3; k++)
|
||||
printf("sqrt_cmplx(%.1f%+.1fj) = %.3f%+.3fj\n",
|
||||
RE(x[k]), IM(x[k]), RE(y[k]), IM(y[k]));
|
||||
|
||||
|
||||
|
||||
dspl_free(handle); // free dspl handle
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ int main()
|
|||
{
|
||||
void* handle; // DSPL handle
|
||||
handle = dspl_load(); // Load DSPL function
|
||||
complex_t a[N], b[M], c[N+M-1];
|
||||
complex_t a[N], b[M], c[N+M-1], d[N+M-1];
|
||||
fft_t pfft;
|
||||
int n;
|
||||
|
||||
|
@ -18,10 +18,13 @@ int main()
|
|||
memset(&pfft, 0, sizeof(fft_t));
|
||||
|
||||
conv_fft_cmplx(a, N, b, M, &pfft, c);
|
||||
conv_cmplx(a, N, b, M, d);
|
||||
|
||||
for(n = 0; n < N+M-1; n++)
|
||||
printf("c[%3d] = %9.2f%+9.2fj\n", n, RE(c[n]), IM(c[n]));
|
||||
|
||||
{
|
||||
printf("c[%3d] = %9.2f%+9.2fj ", n, RE(c[n]), IM(c[n]));
|
||||
printf("d[%3d] = %9.2f%+9.2fj \n", n, RE(d[n]), IM(d[n]));
|
||||
}
|
||||
fft_free(&pfft);
|
||||
dspl_free(handle); // free dspl handle
|
||||
return 0;
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "dspl.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
void* handle; // DSPL handle
|
||||
handle = dspl_load(); // Load DSPL function
|
||||
complex_t ac[3] = {{0.0, 1.0}, {1.0, 1.0}, {2.0, 2.0}};
|
||||
complex_t bc[4] = {{3.0, 3.0}, {4.0, 4.0}, {5.0, 5.0}, {6.0, 6.0}};
|
||||
complex_t cc[6];
|
||||
|
||||
double ar[3] = {1.0, 2.0, 3.0};
|
||||
double br[4] = {3.0, -1.0, 2.0, 4.0};
|
||||
double cr[6];
|
||||
|
||||
int n;
|
||||
|
||||
printf("\nconv\n--------------------------------\n");
|
||||
conv(ar, 3, br, 4, cr);
|
||||
for(n = 0; n < 6; n++)
|
||||
printf("cr[%d] = %5.1f\n", n, cr[n]);
|
||||
|
||||
printf("\nconv_cmplx\n--------------------------------\n");
|
||||
conv_cmplx(ac, 3, bc, 4, cc);
|
||||
for(n = 0; n < 6; n++)
|
||||
printf("cc[%d] = %5.1f%+5.1fj\n", n, RE(cc[n]),IM(cc[n]));
|
||||
|
||||
|
||||
|
||||
|
||||
dspl_free(handle); // free dspl handle
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Ładowanie…
Reference in New Issue