Modified codeblocks files
|
@ -9,3 +9,5 @@
|
|||
*.a
|
||||
*.html
|
||||
*.png
|
||||
*.def
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
*.o
|
||||
*.so
|
||||
*.dll
|
||||
*.exe
|
||||
*.txt
|
||||
*.dat
|
||||
*.bin
|
||||
*.csv
|
||||
*.a
|
||||
*.html
|
||||
*.png
|
||||
*.def
|
||||
|
Przed Szerokość: | Wysokość: | Rozmiar: 11 KiB |
Przed Szerokość: | Wysokość: | Rozmiar: 14 KiB |
Przed Szerokość: | Wysokość: | Rozmiar: 20 KiB |
Przed Szerokość: | Wysokość: | Rozmiar: 21 KiB |
Przed Szerokość: | Wysokość: | Rozmiar: 36 KiB |
Przed Szerokość: | Wysokość: | Rozmiar: 32 KiB |
Przed Szerokość: | Wysokość: | Rozmiar: 86 KiB |
Przed Szerokość: | Wysokość: | Rozmiar: 32 KiB |
Przed Szerokość: | Wysokość: | Rozmiar: 25 KiB |
Przed Szerokość: | Wysokość: | Rozmiar: 81 KiB |
Przed Szerokość: | Wysokość: | Rozmiar: 65 KiB |
Przed Szerokość: | Wysokość: | Rozmiar: 17 KiB |
|
@ -51,7 +51,7 @@ PROJECT_BRIEF = "Библиотека алгоритмов цифров
|
|||
# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy
|
||||
# the logo to the output directory.
|
||||
|
||||
PROJECT_LOGO =
|
||||
PROJECT_LOGO = F:/dsplib.org/libdspl-2.0/dspl/dox/ru/img/dspl_small.png
|
||||
|
||||
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
|
||||
# into which the generated documentation will be written. If a relative path is
|
||||
|
|
|
@ -87,3 +87,89 @@ err = 0
|
|||
www.dsplib.org
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*! ****************************************************************************
|
||||
\ingroup IIR_FILTER_DESIGN_GROUP
|
||||
\fn int iir(double rp, double rs, int ord, double w0, double w1, int type, double* b, double* a)
|
||||
\brief Функция расчета коэффициентов передаточной характеристики \f$H(z)\f$
|
||||
цифрового фильтра БИХ.
|
||||
|
||||
Функция рассчитывает коэффициенты передаточной характеристики \f$H(z)\f$
|
||||
цифрового фильтра, которые могут быть использованы в функции \ref filter_iir
|
||||
|
||||
\param[in] rp Уровень неравномерности квадрата АЧХ
|
||||
в полосе пропускания фильтра (дБ).\n
|
||||
Размер вектора `[ord+1 x 1]`. \n \n
|
||||
|
||||
|
||||
\param[in] rs Уровень подавления
|
||||
в полосе заграждения фильтра (дБ).\n \n
|
||||
|
||||
\param[in] ord Порядок фильтра. \n
|
||||
Количество коэффициентов числителя и знаменателя
|
||||
передаточной функции \f$H(z)\f$
|
||||
цифрового фильтров равно `ord+1`. \n
|
||||
Для полосовых и режекторных фильтров параметр `ord`
|
||||
должен быть чётным.\n \n
|
||||
|
||||
\param[in] w0 Нормированная частота среза ФНЧ или ФВЧ, или
|
||||
левая частота среза для полосового и режекторного фильтра.\n \n
|
||||
|
||||
|
||||
\param[in] w1 Правая частота среза полосового и режекторного фильтра.\n
|
||||
Данный параметр игнорируется для ФНЧ и ФВЧ. \n \n
|
||||
|
||||
\param[in] type Тип фильтра. \n
|
||||
Данный параметр определяет тип фильтра и образуется
|
||||
набором флагов типа фильтра:\n
|
||||
\verbatim
|
||||
DSPL_FILTER_LPF - фильтр нижних частот;
|
||||
DSPL_FILTER_HPF - фильтр верхних частот;
|
||||
DSPL_FILTER_BPASS - полосовой фильтр;
|
||||
DSPL_FILTER_BSTOP - режекторный фильтр,
|
||||
\endverbatim
|
||||
а также флагов типа аппроксимации АЧХ фильтра:
|
||||
\verbatim
|
||||
DSPL_FILTER_BUTTER - фильтр Баттерворта;
|
||||
DSPL_FILTER_CHEBY1 - фильтр Чебышева первого рода;
|
||||
DSPL_FILTER_CHEBY2 - фильтр Чебышева второго рода;
|
||||
DSPL_FILTER_ELLIP - эллиптический фильтр.
|
||||
\endverbatim
|
||||
\n \n
|
||||
|
||||
\param[out] b Указатель на вектор коэффициентов
|
||||
числителя передаточной функции \f$H(z)\f$. \n
|
||||
Размер вектора `ord+1`.\n
|
||||
Память должна быть выделена. \n \n
|
||||
|
||||
\param[out] a Указатель на вектор коэффициентов
|
||||
знаменателя передаточной функции \f$H(z)\f$. \n
|
||||
Размер вектора `ord+1`.\n
|
||||
Память должна быть выделена. \n \n
|
||||
|
||||
\return
|
||||
`RES_OK` Фильтр рассчитан успешно. \n \n
|
||||
В противном случае \ref ERROR_CODE_GROUP "код ошибки". \n
|
||||
|
||||
<h3>Пример использования функции</h3>
|
||||
|
||||
\include iir_test.c
|
||||
|
||||
Данная программа производит расчет коэффициентов фильтров
|
||||
при различном сочетании флагов параметра `type`.
|
||||
|
||||
Кроме этого производится расчет АЧХ полученных цифровых фильтров и выводится на
|
||||
график АЧХ пакетом GNUPLOT
|
||||
|
||||
\image html iir_test.png
|
||||
|
||||
|
||||
\author
|
||||
Бахурин Сергей
|
||||
www.dsplib.org
|
||||
***************************************************************************** */
|
174
dspl/src/array.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015-2019 Sergey Bakhurin
|
||||
* Copyright (c) 2015-2020 Sergey Bakhurin
|
||||
* Digital Signal Processing Library [http://dsplib.org]
|
||||
*
|
||||
* This file is part of libdspl-2.0.
|
||||
|
@ -25,6 +25,7 @@
|
|||
#include "dspl.h"
|
||||
#include "blas.h"
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
\fn int concat(void* a, size_t na, void* b, size_t nb, void* c)
|
||||
\brief Concatenate arrays `a` and `b`
|
||||
|
@ -237,71 +238,6 @@ int DSPL_API decimate_cmplx(complex_t* x, int n, int d, complex_t* y, int* cnt)
|
|||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
\ingroup SPEC_MATH_STAT_GROUP
|
||||
\fn int find_max_abs(double* a, int n, double* m, int* ind)
|
||||
\brief Find maximum absolute value from the real vector `a`
|
||||
|
||||
Function searches maximum absolute value in the real vector `a`.
|
||||
This value writes to the address `m` and index keeps to te address `ind`.
|
||||
|
||||
\param[in] a Pointer to the real vector `a`. \n
|
||||
Vector size is `[n x 1]`. \n \n
|
||||
|
||||
\param[in] n Size of the input vector `a`. \n \n
|
||||
|
||||
|
||||
\param[out] m Pointer to the variable which keeps vector `a`
|
||||
maximum absolute value. \n
|
||||
Pointer can be `NULL`, maximum value will not return
|
||||
in this case. \n \n
|
||||
|
||||
\param[out] ind Pointer to the variable which keeps index of a
|
||||
maximum absolute value inside vector `a`. \n
|
||||
Pointer can be `NULL`, index will not return
|
||||
in this case. \n \n
|
||||
\return
|
||||
`RES_OK` if function calculates successfully,
|
||||
else \ref ERROR_CODE_GROUP "code error".
|
||||
|
||||
Example:
|
||||
\code{.cpp}
|
||||
double a[5] = {0.0, 2.0, -5.0, 4.0, 2.0};
|
||||
double m;
|
||||
int ind;
|
||||
find_max_abs(a, 5, &m, &ind);
|
||||
printf("\n\nmax absolute value: %8.1f (index %d)", m, ind);
|
||||
\endcode
|
||||
As result the variable `m` will keep value `5`,
|
||||
and variable `ind` will keep `2`.
|
||||
|
||||
\author Sergey Bakhurin www.dsplib.org
|
||||
*******************************************************************************/
|
||||
int DSPL_API find_max_abs(double* a, int n, double* m, int* ind)
|
||||
{
|
||||
int k, i;
|
||||
double t;
|
||||
if(!a)
|
||||
return ERROR_PTR;
|
||||
if(n < 1)
|
||||
return ERROR_SIZE;
|
||||
t = fabs(a[0]);
|
||||
i = 0;
|
||||
for(k = 1; k < n; k++)
|
||||
{
|
||||
if(fabs(a[k]) > t)
|
||||
{
|
||||
t = fabs(a[k]);
|
||||
i = k;
|
||||
}
|
||||
}
|
||||
if(m)
|
||||
*m = t;
|
||||
if(ind)
|
||||
*ind = i;
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
|
@ -440,6 +376,112 @@ int DSPL_API flipip_cmplx(complex_t* x, int n)
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
Linspace array filling
|
||||
*******************************************************************************/
|
||||
int DSPL_API linspace(double x0, double x1, int n, int type, double* x)
|
||||
{
|
||||
double dx;
|
||||
int k;
|
||||
|
||||
if(n < 2)
|
||||
return ERROR_SIZE;
|
||||
if(!x)
|
||||
return ERROR_PTR;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case DSPL_SYMMETRIC:
|
||||
dx = (x1 - x0)/(double)(n-1);
|
||||
x[0] = x0;
|
||||
for(k = 1; k < n; k++)
|
||||
x[k] = x[k-1] + dx;
|
||||
break;
|
||||
case DSPL_PERIODIC:
|
||||
dx = (x1 - x0)/(double)n;
|
||||
x[0] = x0;
|
||||
for(k = 1; k < n; k++)
|
||||
x[k] = x[k-1] + dx;
|
||||
break;
|
||||
default:
|
||||
return ERROR_SYM_TYPE;
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
Logspace array filling
|
||||
*******************************************************************************/
|
||||
int DSPL_API logspace(double x0, double x1, int n, int type, double* x)
|
||||
{
|
||||
double mx, a, b;
|
||||
int k;
|
||||
|
||||
if(n < 2)
|
||||
return ERROR_SIZE;
|
||||
if(!x)
|
||||
return ERROR_PTR;
|
||||
|
||||
a = pow(10.0, x0);
|
||||
b = pow(10.0, x1);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case DSPL_SYMMETRIC:
|
||||
mx = pow(b/a, 1.0/(double)(n-1));
|
||||
x[0] = a;
|
||||
for(k = 1; k < n; k++)
|
||||
x[k] = x[k-1] * mx;
|
||||
break;
|
||||
case DSPL_PERIODIC:
|
||||
mx = pow(b/a, 1.0/(double)n);
|
||||
x[0] = a;
|
||||
for(k = 1; k < n; k++)
|
||||
x[k] = x[k-1] * mx;
|
||||
break;
|
||||
default:
|
||||
return ERROR_SYM_TYPE;
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
\author Sergey Bakhurin www.dsplib.org
|
||||
*******************************************************************************/
|
||||
int array_scale_lin(double* x, int n,
|
||||
double xmin, double xmax, double dx,
|
||||
double h, double* y)
|
||||
{
|
||||
double kx;
|
||||
int k;
|
||||
if(!x)
|
||||
return ERROR_PTR;
|
||||
if(n<1)
|
||||
return ERROR_SIZE;
|
||||
if(h<0.0)
|
||||
return ERROR_NEGATIVE;
|
||||
|
||||
if(xmin >= xmax)
|
||||
return ERROR_MIN_MAX;
|
||||
|
||||
kx = h / (xmax - xmin);
|
||||
|
||||
for(k = 0; k < n; k++)
|
||||
y[k] = (x[k] - xmin) * kx + dx;
|
||||
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
\ingroup SPEC_MATH_COMMON_GROUP
|
||||
\fn int verif(double* x, double* y, size_t n, double eps, double* err)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015-2019 Sergey Bakhurin
|
||||
* Copyright (c) 2015-2020 Sergey Bakhurin
|
||||
* Digital Signal Processing Library [http://dsplib.org]
|
||||
*
|
||||
* This file is part of DSPL.
|
||||
|
@ -25,154 +25,6 @@
|
|||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
\ingroup SPEC_MATH_TRIG_GROUP
|
||||
\fn int acos_cmplx(complex_t* x, int n, complex_t *y)
|
||||
\brief The inverse of the cosine function the complex vector argument `x`
|
||||
|
||||
Function calculates the inverse of the cosine function as: \n
|
||||
|
||||
\f[
|
||||
\textrm{Arccos}(x) = \frac{\pi}{2} - \textrm{Arcsin}(x) =
|
||||
\frac{\pi}{2} -j \textrm{Ln}\left( j x + \sqrt{1 - x^2} \right)
|
||||
\f]
|
||||
|
||||
|
||||
\param[in] x Pointer to the argument vector `x`. \n
|
||||
Vector size is `[n x 1]`. \n \n
|
||||
|
||||
\param[in] n Input vector `x` and the inverse cosine vector `y` size. \n \n
|
||||
|
||||
|
||||
\param[out] y Pointer to the output complex vector `y`,
|
||||
corresponds to the input vector `x`. \n
|
||||
Vector size is `[n x 1]`. \n
|
||||
Memory must be allocated. \n \n
|
||||
|
||||
\return
|
||||
`RES_OK` if function calculated successfully. \n
|
||||
Else \ref ERROR_CODE_GROUP "code error". \n
|
||||
|
||||
Example: \n
|
||||
\code{.cpp}
|
||||
complex_t x[3] = {{1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}};
|
||||
complex_t y[3];
|
||||
int k;
|
||||
|
||||
acos_cmplx(x, 3, y);
|
||||
|
||||
for(k = 0; k < 3; k++)
|
||||
printf("acos_cmplx(%.1f%+.1fj) = %.3f%+.3fj\n",
|
||||
RE(x[k]), IM(x[k]), RE(y[k]), IM(y[k]));
|
||||
\endcode
|
||||
\n
|
||||
|
||||
Output is: \n
|
||||
\verbatim
|
||||
acos_cmplx(1.0+2.0j) = 1.144-1.529j
|
||||
acos_cmplx(3.0+4.0j) = 0.937-2.306j
|
||||
acos_cmplx(5.0+6.0j) = 0.880-2.749j
|
||||
\endverbatim
|
||||
|
||||
\author
|
||||
Sergey Bakhurin www.dsplib.org
|
||||
*******************************************************************************/
|
||||
int DSPL_API acos_cmplx(complex_t* x, int n, complex_t *y)
|
||||
{
|
||||
int k, res;
|
||||
double pi2 = 0.5 * M_PI;
|
||||
|
||||
res = asin_cmplx(x, n, y);
|
||||
if(res != RES_OK)
|
||||
return res;
|
||||
|
||||
for(k = 0; k < n; k++)
|
||||
{
|
||||
RE(y[k]) = pi2 - RE(y[k]);
|
||||
IM(y[k]) = - IM(y[k]);
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
\ingroup SPEC_MATH_TRIG_GROUP
|
||||
\fn int asin_cmplx(complex_t* x, int n, complex_t *y)
|
||||
\brief The inverse of the sine function the complex vector argument `x`
|
||||
|
||||
Function calculates the inverse of the sine function as: \n
|
||||
|
||||
\f[
|
||||
\textrm{Arcsin}(x) = j \textrm{Ln}\left( j x + \sqrt{1 - x^2} \right)
|
||||
\f]
|
||||
|
||||
|
||||
\param[in] x Pointer to the argument vector `x`. \n
|
||||
Vector size is `[n x 1]`. \n \n
|
||||
|
||||
\param[in] n Input vector `x` and the inverse sine vector `y` size. \n \n
|
||||
|
||||
|
||||
\param[out] y Pointer to the output complex vector `y`,
|
||||
corresponds to the input vector `x`. \n
|
||||
Vector size is `[n x 1]`. \n
|
||||
Memory must be allocated. \n \n
|
||||
|
||||
\return
|
||||
`RES_OK` if function calculated successfully. \n
|
||||
Else \ref ERROR_CODE_GROUP "code error". \n
|
||||
|
||||
Example: \n
|
||||
\code{.cpp}
|
||||
complex_t x[3] = {{1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}};
|
||||
complex_t y[3];
|
||||
int k;
|
||||
|
||||
asin_cmplx(x, 3, y);
|
||||
for(k = 0; k < 3; k++)
|
||||
printf("asin_cmplx(%.1f%+.1fj) = %.3f%+.3fj\n",
|
||||
RE(x[k]), IM(x[k]), RE(y[k]), IM(y[k]));
|
||||
|
||||
\endcode
|
||||
\n
|
||||
|
||||
Output is: \n
|
||||
\verbatim
|
||||
asin_cmplx(1.0+2.0j) = 0.427+1.529j
|
||||
asin_cmplx(3.0+4.0j) = 0.634+2.306j
|
||||
asin_cmplx(5.0+6.0j) = 0.691+2.749j
|
||||
\endverbatim
|
||||
|
||||
\author
|
||||
Sergey Bakhurin www.dsplib.org
|
||||
*******************************************************************************/
|
||||
int DSPL_API asin_cmplx(complex_t* x, int n, complex_t *y)
|
||||
{
|
||||
int k;
|
||||
complex_t tmp;
|
||||
if(!x || !y)
|
||||
return ERROR_PTR;
|
||||
if(n < 1)
|
||||
return ERROR_SIZE;
|
||||
|
||||
for(k = 0; k < n; k++)
|
||||
{
|
||||
RE(tmp) = 1.0 - CMRE(x[k], x[k]); /* 1-x[k]^2 */
|
||||
IM(tmp) = - CMIM(x[k], x[k]); /* 1-x[k]^2 */
|
||||
sqrt_cmplx(&tmp, 1, y+k); /* sqrt(1 - x[k]^2) */
|
||||
RE(y[k]) -= IM(x[k]); /* j * x[k] + sqrt(1 - x[k]^2) */
|
||||
IM(y[k]) += RE(x[k]); /* j * x[k] + sqrt(1 - x[k]^2) */
|
||||
log_cmplx(y+k, 1, &tmp); /* log( j * x[k] + sqrt(1 - x[k]^2) ) */
|
||||
RE(y[k]) = IM(tmp); /* -j * log( j * x[k] + sqrt(1 - x[k]^2) ) */
|
||||
IM(y[k]) = -RE(tmp); /* -j * log( j * x[k] + sqrt(1 - x[k]^2) ) */
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
\ingroup TYPES_GROUP
|
||||
|
@ -180,18 +32,18 @@ int DSPL_API asin_cmplx(complex_t* x, int n, complex_t *y)
|
|||
\brief Separate complex vector to the real and image vectors
|
||||
|
||||
Function fills `re` and `im` vectors corresponds to real and image
|
||||
parts of the input complex array `x`. \n
|
||||
parts of the input complex array `x`. \n
|
||||
|
||||
|
||||
\param[in] x Pointer to the real complex vector. \n
|
||||
Vector size is `[n x 1]`. \n \n
|
||||
|
||||
\param[in] n Size of the input complex vector `x` and real and image
|
||||
\param[in] n Size of the input complex vector `x` and real and image
|
||||
vectors `re` and `im`. \n \n
|
||||
|
||||
\param[out] re Pointer to the real part vector. \n
|
||||
Vector size is `[n x 1]`. \n
|
||||
Memory must be allocated. \n \n
|
||||
Memory must be allocated. \n \n
|
||||
|
||||
\param[out] im Pointer to the image part vector. \n
|
||||
Vector size is `[n x 1]`. \n
|
||||
|
@ -207,7 +59,7 @@ Example: \n
|
|||
double re[3], im[3];
|
||||
|
||||
cmplx2re(x, 3, re, im);
|
||||
\endcode
|
||||
\endcode
|
||||
|
||||
Vectors `re` and `im` will contains:
|
||||
|
||||
|
@ -217,7 +69,7 @@ re[1] = 3.0; im[1] = 4.0;
|
|||
re[2] = 5.0; im[2] = 6.0;
|
||||
\endverbatim
|
||||
|
||||
\author Sergey Bakhurin. www.dsplib.org
|
||||
\author Sergey Bakhurin. www.dsplib.org
|
||||
*******************************************************************************/
|
||||
int DSPL_API cmplx2re(complex_t* x, int n, double* re, double* im)
|
||||
{
|
||||
|
@ -244,162 +96,13 @@ int DSPL_API cmplx2re(complex_t* x, int n, double* re, double* im)
|
|||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
\ingroup SPEC_MATH_TRIG_GROUP
|
||||
\fn int cos_cmplx(complex_t* x, int n, complex_t *y)
|
||||
\brief The cosine function the complex vector argument `x`
|
||||
|
||||
Function calculates the cosine function as: \n
|
||||
|
||||
\f[
|
||||
\textrm{cos}(x) = \frac{\exp(jx) + \exp(-jx)}{2}
|
||||
\f]
|
||||
|
||||
|
||||
\param[in] x Pointer to the argument vector `x`. \n
|
||||
Vector size is `[n x 1]`. \n \n
|
||||
|
||||
\param[in] n Input vector `x` and the cosine vector `y` size. \n \n
|
||||
|
||||
|
||||
\param[out] y Pointer to the output complex vector `y`,
|
||||
corresponds to the input vector `x`. \n
|
||||
Vector size is `[n x 1]`. \n
|
||||
Memory must be allocated. \n \n
|
||||
|
||||
\return
|
||||
`RES_OK` if function calculated successfully. \n
|
||||
Else \ref ERROR_CODE_GROUP "code error". \n
|
||||
|
||||
Example: \n
|
||||
\code{.cpp}
|
||||
complex_t x[3] = {{1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}};
|
||||
complex_t y[3];
|
||||
int k;
|
||||
|
||||
cos_cmplx(x, 3, y);
|
||||
|
||||
for(k = 0; k < 3; k++)
|
||||
printf("cos_cmplx(%.1f%+.1fj) = %9.3f%+9.3fj\n",
|
||||
RE(x[k]), IM(x[k]), RE(y[k]), IM(y[k]));
|
||||
|
||||
\endcode
|
||||
\n
|
||||
|
||||
Output is: \n
|
||||
\verbatim
|
||||
cos_cmplx(1.0+2.0j) = 2.033 -3.052j
|
||||
cos_cmplx(3.0+4.0j) = -27.035 -3.851j
|
||||
cos_cmplx(5.0+6.0j) = 57.219 +193.428j
|
||||
\endverbatim
|
||||
|
||||
\author
|
||||
Sergey Bakhurin www.dsplib.org
|
||||
*******************************************************************************/
|
||||
int DSPL_API cos_cmplx(complex_t* x, int n, complex_t *y)
|
||||
{
|
||||
int k;
|
||||
double ep, em, sx, cx;
|
||||
if(!x || !y)
|
||||
return ERROR_PTR;
|
||||
if(n < 1)
|
||||
return ERROR_SIZE;
|
||||
|
||||
for(k = 0; k < n; k++)
|
||||
{
|
||||
ep = exp( IM(x[k]));
|
||||
em = exp(-IM(x[k]));
|
||||
sx = 0.5 * sin(RE(x[k]));
|
||||
cx = 0.5 * cos(RE(x[k]));
|
||||
RE(y[k]) = cx * (em + ep);
|
||||
IM(y[k]) = sx * (em - ep);
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
\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: \n
|
||||
|
||||
\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`. \n
|
||||
Vector size is `[n x 1]`. \n \n
|
||||
|
||||
\param[in] n Input vector `x` and the logarithm vector `y` size. \n \n
|
||||
|
||||
|
||||
\param[out] y Pointer to the output complex vector `y`,
|
||||
corresponds to the input vector `x`. \n
|
||||
Vector size is `[n x 1]`. \n
|
||||
Memory must be allocated. \n \n
|
||||
|
||||
\return
|
||||
`RES_OK` if function calculated successfully. \n
|
||||
Else \ref ERROR_CODE_GROUP "code error". \n
|
||||
|
||||
Example: \n
|
||||
\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
|
||||
\n
|
||||
|
||||
Output is: \n
|
||||
\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)
|
||||
{
|
||||
int k;
|
||||
if(!x || !y)
|
||||
return ERROR_PTR;
|
||||
if(n < 1)
|
||||
return ERROR_SIZE;
|
||||
|
||||
for(k = 0; k < n; k++)
|
||||
{
|
||||
RE(y[k]) = 0.5 * log(ABSSQR(x[k]));
|
||||
IM(y[k]) = atan2(IM(x[k]), RE(x[k]));
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
\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. \n
|
||||
Function copies the vector `x` to the real part of vector `y`.
|
||||
Image part of the vector `y` sets as zero. \n
|
||||
So complex vector contains data: \n
|
||||
`y[i] = x[i] + j0, here i = 0,1,2 ... n-1`
|
||||
|
||||
|
@ -420,23 +123,23 @@ Else \ref ERROR_CODE_GROUP "code error": \n
|
|||
|
||||
|
||||
|
||||
Например при выполнении следующего кода
|
||||
Например при выполнении следующего кода
|
||||
\code{.cpp}
|
||||
double x[3] = {1.0, 2.0, 3.0};
|
||||
complex_t y[3];
|
||||
|
||||
re2cmplx(x, 3, y);
|
||||
\endcode
|
||||
\endcode
|
||||
|
||||
Vector `y` will keep:
|
||||
|
||||
\verbatim
|
||||
\verbatim
|
||||
y[0] = 1+0j;
|
||||
y[1] = 2+0j;
|
||||
y[2] = 3+0j.
|
||||
\endverbatim
|
||||
|
||||
\author Sergey Bakhurin. www.dsplib.org
|
||||
\author Sergey Bakhurin. www.dsplib.org
|
||||
*******************************************************************************/
|
||||
int DSPL_API re2cmplx(double* x, int n, complex_t* y)
|
||||
{
|
||||
|
@ -455,173 +158,3 @@ int DSPL_API re2cmplx(double* x, int n, complex_t* y)
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
\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: \n
|
||||
|
||||
\f[
|
||||
\textrm{cos}(x) = \frac{\exp(jx) - \exp(-jx)}{2j}
|
||||
\f]
|
||||
|
||||
|
||||
\param[in] x Pointer to the argument vector `x`. \n
|
||||
Vector size is `[n x 1]`. \n \n
|
||||
|
||||
\param[in] n Input vector `x` and the sine vector `y` size. \n \n
|
||||
|
||||
|
||||
\param[out] y Pointer to the output complex vector `y`,
|
||||
corresponds to the input vector `x`. \n
|
||||
Vector size is `[n x 1]`. \n
|
||||
Memory must be allocated. \n \n
|
||||
|
||||
\return
|
||||
`RES_OK` if function calculated successfully. \n
|
||||
Else \ref ERROR_CODE_GROUP "code error". \n
|
||||
|
||||
Example: \n
|
||||
\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
|
||||
\n
|
||||
|
||||
Output is: \n
|
||||
\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)
|
||||
{
|
||||
int k;
|
||||
double ep, em, sx, cx;
|
||||
if(!x || !y)
|
||||
return ERROR_PTR;
|
||||
if(n < 1)
|
||||
return ERROR_SIZE;
|
||||
|
||||
for(k = 0; k < n; k++)
|
||||
{
|
||||
ep = exp( IM(x[k]));
|
||||
em = exp(-IM(x[k]));
|
||||
sx = 0.5 * sin(RE(x[k]));
|
||||
cx = 0.5 * cos(RE(x[k]));
|
||||
RE(y[k]) = sx * (em + ep);
|
||||
IM(y[k]) = cx * (ep - em);
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
\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`: \n
|
||||
\f[
|
||||
y(k) = \sqrt{x(k)}, \qquad k = 0 \ldots n-1.
|
||||
\f]
|
||||
|
||||
|
||||
\param[in] x Pointer to the input complex vector `x`. \n
|
||||
Vector size is `[n x 1]`. \n \n
|
||||
|
||||
\param[in] n Size of input and output vectors `x` and `y`. \n \n
|
||||
|
||||
|
||||
\param[out] y Pointer to the square root vector `y`. \n
|
||||
Vector size is `[n x 1]`. \n
|
||||
Memory must be allocated. \n \n
|
||||
|
||||
\return `RES_OK` if function is calculated successfully. \n
|
||||
Else \ref ERROR_CODE_GROUP "code error". \n
|
||||
|
||||
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
|
||||
\n
|
||||
|
||||
Результатом работы будет
|
||||
|
||||
\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)
|
||||
{
|
||||
int k;
|
||||
double r, zr, at;
|
||||
complex_t t;
|
||||
if(!x || !y)
|
||||
return ERROR_PTR;
|
||||
if(n < 1)
|
||||
return ERROR_SIZE;
|
||||
|
||||
for(k = 0; k < n; k++)
|
||||
{
|
||||
r = ABS(x[k]);
|
||||
if(r == 0.0)
|
||||
{
|
||||
RE(y[k]) = 0.0;
|
||||
IM(y[k]) = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
RE(t) = RE(x[k]) + r;
|
||||
IM(t) = IM(x[k]);
|
||||
at = ABS(t);
|
||||
if(at == 0.0)
|
||||
{
|
||||
RE(y[k]) = 0.0;
|
||||
IM(y[k]) = sqrt(r);
|
||||
}
|
||||
else
|
||||
{
|
||||
zr = 1.0 / ABS(t);
|
||||
r = sqrt(r);
|
||||
RE(y[k]) = RE(t) * zr * r;
|
||||
IM(y[k]) = IM(t) * zr * r;
|
||||
}
|
||||
}
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -508,7 +508,6 @@ exit_label:
|
|||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
\ingroup FILTER_CONV_GROUP
|
||||
\fn int filter_iir(double* b, double* a, int ord, double* x, int n, double* y)
|
||||
|
|
|
@ -372,7 +372,7 @@ error_proc:
|
|||
|
||||
|
||||
/*******************************************************************************
|
||||
FFT magnitude for the real signal
|
||||
FFT magnitude for the complex signal
|
||||
*******************************************************************************/
|
||||
int DSPL_API fft_mag_cmplx(complex_t* x, int n, fft_t* pfft,
|
||||
double fs, int flag,
|
||||
|
|
|
@ -1,100 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2015-2019 Sergey Bakhurin
|
||||
* Digital Signal Processing Library [http://dsplib.org]
|
||||
*
|
||||
* This file is part of libdspl-2.0.
|
||||
*
|
||||
* is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* DSPL is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "dspl.h"
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
Linspace array filling
|
||||
*******************************************************************************/
|
||||
int DSPL_API linspace(double x0, double x1, int n, int type, double* x)
|
||||
{
|
||||
double dx;
|
||||
int k;
|
||||
|
||||
if(n < 2)
|
||||
return ERROR_SIZE;
|
||||
if(!x)
|
||||
return ERROR_PTR;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case DSPL_SYMMETRIC:
|
||||
dx = (x1 - x0)/(double)(n-1);
|
||||
x[0] = x0;
|
||||
for(k = 1; k < n; k++)
|
||||
x[k] = x[k-1] + dx;
|
||||
break;
|
||||
case DSPL_PERIODIC:
|
||||
dx = (x1 - x0)/(double)n;
|
||||
x[0] = x0;
|
||||
for(k = 1; k < n; k++)
|
||||
x[k] = x[k-1] + dx;
|
||||
break;
|
||||
default:
|
||||
return ERROR_SYM_TYPE;
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
Logspace array filling
|
||||
*******************************************************************************/
|
||||
int DSPL_API logspace(double x0, double x1, int n, int type, double* x)
|
||||
{
|
||||
double mx, a, b;
|
||||
int k;
|
||||
|
||||
if(n < 2)
|
||||
return ERROR_SIZE;
|
||||
if(!x)
|
||||
return ERROR_PTR;
|
||||
|
||||
a = pow(10.0, x0);
|
||||
b = pow(10.0, x1);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case DSPL_SYMMETRIC:
|
||||
mx = pow(b/a, 1.0/(double)(n-1));
|
||||
x[0] = a;
|
||||
for(k = 1; k < n; k++)
|
||||
x[k] = x[k-1] * mx;
|
||||
break;
|
||||
case DSPL_PERIODIC:
|
||||
mx = pow(b/a, 1.0/(double)n);
|
||||
x[0] = a;
|
||||
for(k = 1; k < n; k++)
|
||||
x[k] = x[k-1] * mx;
|
||||
break;
|
||||
default:
|
||||
return ERROR_SYM_TYPE;
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
|
@ -197,7 +197,6 @@ int DSPL_API writetxt(double* x, double* y, int n, char* fn)
|
|||
{
|
||||
int k;
|
||||
FILE* pFile = NULL;
|
||||
int res;
|
||||
if(!x)
|
||||
return ERROR_PTR;
|
||||
if(n < 1)
|
||||
|
@ -212,12 +211,12 @@ int DSPL_API writetxt(double* x, double* y, int n, char* fn)
|
|||
if(y)
|
||||
for(k = 0; k < n; k++)
|
||||
fprintf(pFile, "%+.12E\t%+.12E\n", x[k], y[k]);
|
||||
|
||||
|
||||
else
|
||||
for(k = 0; k < n; k++)
|
||||
for(k = 0; k < n; k++)
|
||||
fprintf(pFile, "%+.12E\n", x[k]);
|
||||
|
||||
|
||||
|
||||
|
||||
fclose(pFile);
|
||||
return RES_OK;
|
||||
}
|
||||
|
|
476
dspl/src/math.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015-2019 Sergey Bakhurin
|
||||
* Copyright (c) 2015-2020 Sergey Bakhurin
|
||||
* Digital Signal Processing Library [http://dsplib.org]
|
||||
*
|
||||
* This file is part of DSPL.
|
||||
|
@ -24,6 +24,158 @@
|
|||
#include "dspl.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
\ingroup SPEC_MATH_TRIG_GROUP
|
||||
\fn int acos_cmplx(complex_t* x, int n, complex_t *y)
|
||||
\brief The inverse of the cosine function the complex vector argument `x`
|
||||
|
||||
Function calculates the inverse of the cosine function as: \n
|
||||
|
||||
\f[
|
||||
\textrm{Arccos}(x) = \frac{\pi}{2} - \textrm{Arcsin}(x) =
|
||||
\frac{\pi}{2} -j \textrm{Ln}\left( j x + \sqrt{1 - x^2} \right)
|
||||
\f]
|
||||
|
||||
|
||||
\param[in] x Pointer to the argument vector `x`. \n
|
||||
Vector size is `[n x 1]`. \n \n
|
||||
|
||||
\param[in] n Input vector `x` and the inverse cosine vector `y` size. \n \n
|
||||
|
||||
|
||||
\param[out] y Pointer to the output complex vector `y`,
|
||||
corresponds to the input vector `x`. \n
|
||||
Vector size is `[n x 1]`. \n
|
||||
Memory must be allocated. \n \n
|
||||
|
||||
\return
|
||||
`RES_OK` if function calculated successfully. \n
|
||||
Else \ref ERROR_CODE_GROUP "code error". \n
|
||||
|
||||
Example: \n
|
||||
\code{.cpp}
|
||||
complex_t x[3] = {{1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}};
|
||||
complex_t y[3];
|
||||
int k;
|
||||
|
||||
acos_cmplx(x, 3, y);
|
||||
|
||||
for(k = 0; k < 3; k++)
|
||||
printf("acos_cmplx(%.1f%+.1fj) = %.3f%+.3fj\n",
|
||||
RE(x[k]), IM(x[k]), RE(y[k]), IM(y[k]));
|
||||
\endcode
|
||||
\n
|
||||
|
||||
Output is: \n
|
||||
\verbatim
|
||||
acos_cmplx(1.0+2.0j) = 1.144-1.529j
|
||||
acos_cmplx(3.0+4.0j) = 0.937-2.306j
|
||||
acos_cmplx(5.0+6.0j) = 0.880-2.749j
|
||||
\endverbatim
|
||||
|
||||
\author
|
||||
Sergey Bakhurin www.dsplib.org
|
||||
*******************************************************************************/
|
||||
int DSPL_API acos_cmplx(complex_t* x, int n, complex_t *y)
|
||||
{
|
||||
int k, res;
|
||||
double pi2 = 0.5 * M_PI;
|
||||
|
||||
res = asin_cmplx(x, n, y);
|
||||
if(res != RES_OK)
|
||||
return res;
|
||||
|
||||
for(k = 0; k < n; k++)
|
||||
{
|
||||
RE(y[k]) = pi2 - RE(y[k]);
|
||||
IM(y[k]) = - IM(y[k]);
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
\ingroup SPEC_MATH_TRIG_GROUP
|
||||
\fn int asin_cmplx(complex_t* x, int n, complex_t *y)
|
||||
\brief The inverse of the sine function the complex vector argument `x`
|
||||
|
||||
Function calculates the inverse of the sine function as: \n
|
||||
|
||||
\f[
|
||||
\textrm{Arcsin}(x) = j \textrm{Ln}\left( j x + \sqrt{1 - x^2} \right)
|
||||
\f]
|
||||
|
||||
|
||||
\param[in] x Pointer to the argument vector `x`. \n
|
||||
Vector size is `[n x 1]`. \n \n
|
||||
|
||||
\param[in] n Input vector `x` and the inverse sine vector `y` size. \n \n
|
||||
|
||||
|
||||
\param[out] y Pointer to the output complex vector `y`,
|
||||
corresponds to the input vector `x`. \n
|
||||
Vector size is `[n x 1]`. \n
|
||||
Memory must be allocated. \n \n
|
||||
|
||||
\return
|
||||
`RES_OK` if function calculated successfully. \n
|
||||
Else \ref ERROR_CODE_GROUP "code error". \n
|
||||
|
||||
Example: \n
|
||||
\code{.cpp}
|
||||
complex_t x[3] = {{1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}};
|
||||
complex_t y[3];
|
||||
int k;
|
||||
|
||||
asin_cmplx(x, 3, y);
|
||||
for(k = 0; k < 3; k++)
|
||||
printf("asin_cmplx(%.1f%+.1fj) = %.3f%+.3fj\n",
|
||||
RE(x[k]), IM(x[k]), RE(y[k]), IM(y[k]));
|
||||
|
||||
\endcode
|
||||
\n
|
||||
|
||||
Output is: \n
|
||||
\verbatim
|
||||
asin_cmplx(1.0+2.0j) = 0.427+1.529j
|
||||
asin_cmplx(3.0+4.0j) = 0.634+2.306j
|
||||
asin_cmplx(5.0+6.0j) = 0.691+2.749j
|
||||
\endverbatim
|
||||
|
||||
\author
|
||||
Sergey Bakhurin www.dsplib.org
|
||||
*******************************************************************************/
|
||||
int DSPL_API asin_cmplx(complex_t* x, int n, complex_t *y)
|
||||
{
|
||||
int k;
|
||||
complex_t tmp;
|
||||
if(!x || !y)
|
||||
return ERROR_PTR;
|
||||
if(n < 1)
|
||||
return ERROR_SIZE;
|
||||
|
||||
for(k = 0; k < n; k++)
|
||||
{
|
||||
RE(tmp) = 1.0 - CMRE(x[k], x[k]); /* 1-x[k]^2 */
|
||||
IM(tmp) = - CMIM(x[k], x[k]); /* 1-x[k]^2 */
|
||||
sqrt_cmplx(&tmp, 1, y+k); /* sqrt(1 - x[k]^2) */
|
||||
RE(y[k]) -= IM(x[k]); /* j * x[k] + sqrt(1 - x[k]^2) */
|
||||
IM(y[k]) += RE(x[k]); /* j * x[k] + sqrt(1 - x[k]^2) */
|
||||
log_cmplx(y+k, 1, &tmp); /* log( j * x[k] + sqrt(1 - x[k]^2) ) */
|
||||
RE(y[k]) = IM(tmp); /* -j * log( j * x[k] + sqrt(1 - x[k]^2) ) */
|
||||
IM(y[k]) = -RE(tmp); /* -j * log( j * x[k] + sqrt(1 - x[k]^2) ) */
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
Modified Bessel Function of the First Kind – I0(x) [1]
|
||||
|
||||
|
@ -120,6 +272,232 @@ double DSPL_API dmod (double x, double y)
|
|||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
\ingroup SPEC_MATH_TRIG_GROUP
|
||||
\fn int cos_cmplx(complex_t* x, int n, complex_t *y)
|
||||
\brief The cosine function the complex vector argument `x`
|
||||
|
||||
Function calculates the cosine function as: \n
|
||||
|
||||
\f[
|
||||
\textrm{cos}(x) = \frac{\exp(jx) + \exp(-jx)}{2}
|
||||
\f]
|
||||
|
||||
|
||||
\param[in] x Pointer to the argument vector `x`. \n
|
||||
Vector size is `[n x 1]`. \n \n
|
||||
|
||||
\param[in] n Input vector `x` and the cosine vector `y` size. \n \n
|
||||
|
||||
|
||||
\param[out] y Pointer to the output complex vector `y`,
|
||||
corresponds to the input vector `x`. \n
|
||||
Vector size is `[n x 1]`. \n
|
||||
Memory must be allocated. \n \n
|
||||
|
||||
\return
|
||||
`RES_OK` if function calculated successfully. \n
|
||||
Else \ref ERROR_CODE_GROUP "code error". \n
|
||||
|
||||
Example: \n
|
||||
\code{.cpp}
|
||||
complex_t x[3] = {{1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}};
|
||||
complex_t y[3];
|
||||
int k;
|
||||
|
||||
cos_cmplx(x, 3, y);
|
||||
|
||||
for(k = 0; k < 3; k++)
|
||||
printf("cos_cmplx(%.1f%+.1fj) = %9.3f%+9.3fj\n",
|
||||
RE(x[k]), IM(x[k]), RE(y[k]), IM(y[k]));
|
||||
|
||||
\endcode
|
||||
\n
|
||||
|
||||
Output is: \n
|
||||
\verbatim
|
||||
cos_cmplx(1.0+2.0j) = 2.033 -3.052j
|
||||
cos_cmplx(3.0+4.0j) = -27.035 -3.851j
|
||||
cos_cmplx(5.0+6.0j) = 57.219 +193.428j
|
||||
\endverbatim
|
||||
|
||||
\author
|
||||
Sergey Bakhurin www.dsplib.org
|
||||
*******************************************************************************/
|
||||
int DSPL_API cos_cmplx(complex_t* x, int n, complex_t *y)
|
||||
{
|
||||
int k;
|
||||
double ep, em, sx, cx;
|
||||
if(!x || !y)
|
||||
return ERROR_PTR;
|
||||
if(n < 1)
|
||||
return ERROR_SIZE;
|
||||
|
||||
for(k = 0; k < n; k++)
|
||||
{
|
||||
ep = exp( IM(x[k]));
|
||||
em = exp(-IM(x[k]));
|
||||
sx = 0.5 * sin(RE(x[k]));
|
||||
cx = 0.5 * cos(RE(x[k]));
|
||||
RE(y[k]) = cx * (em + ep);
|
||||
IM(y[k]) = sx * (em - ep);
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
\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: \n
|
||||
|
||||
\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`. \n
|
||||
Vector size is `[n x 1]`. \n \n
|
||||
|
||||
\param[in] n Input vector `x` and the logarithm vector `y` size. \n \n
|
||||
|
||||
|
||||
\param[out] y Pointer to the output complex vector `y`,
|
||||
corresponds to the input vector `x`. \n
|
||||
Vector size is `[n x 1]`. \n
|
||||
Memory must be allocated. \n \n
|
||||
|
||||
\return
|
||||
`RES_OK` if function calculated successfully. \n
|
||||
Else \ref ERROR_CODE_GROUP "code error". \n
|
||||
|
||||
Example: \n
|
||||
\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
|
||||
\n
|
||||
|
||||
Output is: \n
|
||||
\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)
|
||||
{
|
||||
int k;
|
||||
if(!x || !y)
|
||||
return ERROR_PTR;
|
||||
if(n < 1)
|
||||
return ERROR_SIZE;
|
||||
|
||||
for(k = 0; k < n; k++)
|
||||
{
|
||||
RE(y[k]) = 0.5 * log(ABSSQR(x[k]));
|
||||
IM(y[k]) = atan2(IM(x[k]), RE(x[k]));
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
\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: \n
|
||||
|
||||
\f[
|
||||
\textrm{cos}(x) = \frac{\exp(jx) - \exp(-jx)}{2j}
|
||||
\f]
|
||||
|
||||
|
||||
\param[in] x Pointer to the argument vector `x`. \n
|
||||
Vector size is `[n x 1]`. \n \n
|
||||
|
||||
\param[in] n Input vector `x` and the sine vector `y` size. \n \n
|
||||
|
||||
|
||||
\param[out] y Pointer to the output complex vector `y`,
|
||||
corresponds to the input vector `x`. \n
|
||||
Vector size is `[n x 1]`. \n
|
||||
Memory must be allocated. \n \n
|
||||
|
||||
\return
|
||||
`RES_OK` if function calculated successfully. \n
|
||||
Else \ref ERROR_CODE_GROUP "code error". \n
|
||||
|
||||
Example: \n
|
||||
\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
|
||||
\n
|
||||
|
||||
Output is: \n
|
||||
\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)
|
||||
{
|
||||
int k;
|
||||
double ep, em, sx, cx;
|
||||
if(!x || !y)
|
||||
return ERROR_PTR;
|
||||
if(n < 1)
|
||||
return ERROR_SIZE;
|
||||
|
||||
for(k = 0; k < n; k++)
|
||||
{
|
||||
ep = exp( IM(x[k]));
|
||||
em = exp(-IM(x[k]));
|
||||
sx = 0.5 * sin(RE(x[k]));
|
||||
cx = 0.5 * cos(RE(x[k]));
|
||||
RE(y[k]) = sx * (em + ep);
|
||||
IM(y[k]) = cx * (ep - em);
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
sinc(x) = sin(pi*x)/(pi*x)
|
||||
|
@ -303,3 +681,99 @@ int DSPL_API sine_int(double* x, int n, double* si)
|
|||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
\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`: \n
|
||||
\f[
|
||||
y(k) = \sqrt{x(k)}, \qquad k = 0 \ldots n-1.
|
||||
\f]
|
||||
|
||||
|
||||
\param[in] x Pointer to the input complex vector `x`. \n
|
||||
Vector size is `[n x 1]`. \n \n
|
||||
|
||||
\param[in] n Size of input and output vectors `x` and `y`. \n \n
|
||||
|
||||
|
||||
\param[out] y Pointer to the square root vector `y`. \n
|
||||
Vector size is `[n x 1]`. \n
|
||||
Memory must be allocated. \n \n
|
||||
|
||||
\return `RES_OK` if function is calculated successfully. \n
|
||||
Else \ref ERROR_CODE_GROUP "code error". \n
|
||||
|
||||
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
|
||||
\n
|
||||
|
||||
Результатом работы будет
|
||||
|
||||
\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)
|
||||
{
|
||||
int k;
|
||||
double r, zr, at;
|
||||
complex_t t;
|
||||
if(!x || !y)
|
||||
return ERROR_PTR;
|
||||
if(n < 1)
|
||||
return ERROR_SIZE;
|
||||
|
||||
for(k = 0; k < n; k++)
|
||||
{
|
||||
r = ABS(x[k]);
|
||||
if(r == 0.0)
|
||||
{
|
||||
RE(y[k]) = 0.0;
|
||||
IM(y[k]) = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
RE(t) = RE(x[k]) + r;
|
||||
IM(t) = IM(x[k]);
|
||||
at = ABS(t);
|
||||
if(at == 0.0)
|
||||
{
|
||||
RE(y[k]) = 0.0;
|
||||
IM(y[k]) = sqrt(r);
|
||||
}
|
||||
else
|
||||
{
|
||||
zr = 1.0 / ABS(t);
|
||||
r = sqrt(r);
|
||||
RE(y[k]) = RE(t) * zr * r;
|
||||
IM(y[k]) = IM(t) * zr * r;
|
||||
}
|
||||
}
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
|
@ -25,6 +25,74 @@
|
|||
#include "dspl.h"
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
\ingroup SPEC_MATH_STAT_GROUP
|
||||
\fn int find_max_abs(double* a, int n, double* m, int* ind)
|
||||
\brief Find maximum absolute value from the real vector `a`
|
||||
|
||||
Function searches maximum absolute value in the real vector `a`.
|
||||
This value writes to the address `m` and index keeps to te address `ind`.
|
||||
|
||||
\param[in] a Pointer to the real vector `a`. \n
|
||||
Vector size is `[n x 1]`. \n \n
|
||||
|
||||
\param[in] n Size of the input vector `a`. \n \n
|
||||
|
||||
|
||||
\param[out] m Pointer to the variable which keeps vector `a`
|
||||
maximum absolute value. \n
|
||||
Pointer can be `NULL`, maximum value will not return
|
||||
in this case. \n \n
|
||||
|
||||
\param[out] ind Pointer to the variable which keeps index of a
|
||||
maximum absolute value inside vector `a`. \n
|
||||
Pointer can be `NULL`, index will not return
|
||||
in this case. \n \n
|
||||
\return
|
||||
`RES_OK` if function calculates successfully,
|
||||
else \ref ERROR_CODE_GROUP "code error".
|
||||
|
||||
Example:
|
||||
\code{.cpp}
|
||||
double a[5] = {0.0, 2.0, -5.0, 4.0, 2.0};
|
||||
double m;
|
||||
int ind;
|
||||
find_max_abs(a, 5, &m, &ind);
|
||||
printf("\n\nmax absolute value: %8.1f (index %d)", m, ind);
|
||||
\endcode
|
||||
As result the variable `m` will keep value `5`,
|
||||
and variable `ind` will keep `2`.
|
||||
|
||||
\author Sergey Bakhurin www.dsplib.org
|
||||
*******************************************************************************/
|
||||
int DSPL_API find_max_abs(double* a, int n, double* m, int* ind)
|
||||
{
|
||||
int k, i;
|
||||
double t;
|
||||
if(!a)
|
||||
return ERROR_PTR;
|
||||
if(n < 1)
|
||||
return ERROR_SIZE;
|
||||
t = fabs(a[0]);
|
||||
i = 0;
|
||||
for(k = 1; k < n; k++)
|
||||
{
|
||||
if(fabs(a[k]) > t)
|
||||
{
|
||||
t = fabs(a[k]);
|
||||
i = k;
|
||||
}
|
||||
}
|
||||
if(m)
|
||||
*m = t;
|
||||
if(ind)
|
||||
*ind = i;
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
Histogram calculation
|
||||
*******************************************************************************/
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
# depslib dependency file v1.0
|
||||
1570970898 source:f:\dsplib.org\libdspl-2.0\dspl\src\array.c
|
||||
1586882689 source:f:\dsplib.org\libdspl-2.0\dspl\src\array.c
|
||||
<stdio.h>
|
||||
<stdlib.h>
|
||||
<string.h>
|
||||
"dspl.h"
|
||||
"blas.h"
|
||||
|
||||
1572200729 f:\dsplib.org\libdspl-2.0\include\dspl.h
|
||||
1586187310 f:\dsplib.org\libdspl-2.0\include\dspl.h
|
||||
<math.h>
|
||||
|
||||
1570911978 f:\dsplib.org\libdspl-2.0\dspl\src\blas.h
|
||||
|
@ -19,12 +19,12 @@
|
|||
<math.h>
|
||||
"dspl.h"
|
||||
|
||||
1570975391 source:f:\dsplib.org\libdspl-2.0\dspl\src\complex.c
|
||||
1586882996 source:f:\dsplib.org\libdspl-2.0\dspl\src\complex.c
|
||||
<stdio.h>
|
||||
<stdlib.h>
|
||||
"dspl.h"
|
||||
|
||||
1569004225 source:f:\dsplib.org\libdspl-2.0\dspl\src\conv.c
|
||||
1586882688 source:f:\dsplib.org\libdspl-2.0\dspl\src\conv.c
|
||||
<stdlib.h>
|
||||
<string.h>
|
||||
"dspl.h"
|
||||
|
@ -41,7 +41,7 @@
|
|||
<math.h>
|
||||
"dspl.h"
|
||||
|
||||
1570887444 source:f:\dsplib.org\libdspl-2.0\dspl\src\fft.c
|
||||
1586882686 source:f:\dsplib.org\libdspl-2.0\dspl\src\fft.c
|
||||
<stdlib.h>
|
||||
<stdio.h>
|
||||
<string.h>
|
||||
|
@ -105,13 +105,13 @@
|
|||
<string.h>
|
||||
"dspl.h"
|
||||
|
||||
1572186006 source:f:\dsplib.org\libdspl-2.0\dspl\src\inout.c
|
||||
1586883124 source:f:\dsplib.org\libdspl-2.0\dspl\src\inout.c
|
||||
<stdio.h>
|
||||
<stdlib.h>
|
||||
<string.h>
|
||||
"dspl.h"
|
||||
|
||||
1569004225 source:f:\dsplib.org\libdspl-2.0\dspl\src\math.c
|
||||
1579030984 source:f:\dsplib.org\libdspl-2.0\dspl\src\math.c
|
||||
<stdio.h>
|
||||
<stdlib.h>
|
||||
"dspl.h"
|
||||
|
@ -158,7 +158,7 @@
|
|||
<math.h>
|
||||
"dspl.h"
|
||||
|
||||
1569004225 source:f:\dsplib.org\libdspl-2.0\dspl\src\statistic.c
|
||||
1579031016 source:f:\dsplib.org\libdspl-2.0\dspl\src\statistic.c
|
||||
<stdio.h>
|
||||
<stdlib.h>
|
||||
<string.h>
|
||||
|
@ -175,3 +175,8 @@
|
|||
"dspl.h"
|
||||
"dspl_internal.h"
|
||||
|
||||
1578598539 source:f:\dsplib.org\libdspl-2.0\dspl\src\gnuplot.c
|
||||
<stdio.h>
|
||||
<unistd.h>
|
||||
"dspl.h"
|
||||
|
||||
|
|
|
@ -1 +1,15 @@
|
|||
# depslib dependency file v1.0
|
||||
1577612574 source:f:\dsplib.org\libdspl-2.0\examples\src\dspl_info_test.c
|
||||
<stdio.h>
|
||||
<stdlib.h>
|
||||
"dspl.h"
|
||||
|
||||
1586187310 f:\dsplib.org\libdspl-2.0\include\dspl.h
|
||||
<math.h>
|
||||
|
||||
1586187094 source:f:\dsplib.org\libdspl-2.0\include\dspl.c
|
||||
<windows.h>
|
||||
<dlfcn.h>
|
||||
<stdio.h>
|
||||
"dspl.h"
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#ifndef BUILD_LIB
|
||||
|
||||
p_acos_cmplx acos_cmplx ;
|
||||
p_array_scale_lin array_scale_lin ;
|
||||
p_asin_cmplx asin_cmplx ;
|
||||
|
||||
p_butter_ap butter_ap ;
|
||||
|
@ -230,6 +231,7 @@ void* dspl_load()
|
|||
|
||||
|
||||
LOAD_FUNC(acos_cmplx);
|
||||
LOAD_FUNC(array_scale_lin);
|
||||
LOAD_FUNC(asin_cmplx);
|
||||
|
||||
LOAD_FUNC(bessel_i0);
|
||||
|
|
|
@ -135,6 +135,7 @@ typedef struct
|
|||
#define ERROR_MATRIX_INDEX 0x13010914
|
||||
#define ERROR_MATRIX_SINGULAR 0x13011914
|
||||
#define ERROR_MATRIX_SIZE 0x13011926
|
||||
#define ERROR_MIN_MAX 0x13091413
|
||||
/* N 0x14xxxxxx*/
|
||||
#define ERROR_NEGATIVE 0x14050701
|
||||
/* O 0x15xxxxxx*/
|
||||
|
@ -264,6 +265,13 @@ typedef struct
|
|||
DECLARE_FUNC(int, acos_cmplx, complex_t*
|
||||
COMMA int
|
||||
COMMA complex_t*);
|
||||
/*----------------------------------------------------------------------------*/DECLARE_FUNC(int, array_scale_lin, double* x
|
||||
COMMA int n
|
||||
COMMA double xmin
|
||||
COMMA double xmax
|
||||
COMMA double dx
|
||||
COMMA double h
|
||||
COMMA double* y);
|
||||
/*----------------------------------------------------------------------------*/
|
||||
DECLARE_FUNC(int, asin_cmplx, complex_t*
|
||||
COMMA int
|
||||
|
|