kopia lustrzana https://github.com/Dsplib/libdspl-2.0
addded doc for decimate functions
rodzic
e09b960286
commit
4ebf6f0df4
|
@ -52,3 +52,109 @@ www.dsplib.org
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
/*! ****************************************************************************
|
||||
\ingroup SPEC_MATH_COMMON_GROUP
|
||||
\fn int decimate(double* x, int n, int d, double* y, int* cnt)
|
||||
\brief Децимация вещественного вектора данных
|
||||
|
||||
Функция производит децимацию вещественного вектора `x` в `d` раз.<BR>
|
||||
В результате выходной вектор `y` содержит значения:
|
||||
`y(k) = x(k*d), k = 0...n/d-1`<BR>
|
||||
|
||||
\param[in] x Указатель на вектор входных данных `x`.<BR>
|
||||
Размер вектора `[n x 1]`.<BR><BR>
|
||||
|
||||
\param[in] n Размер входного вектора `x`.<BR><BR>
|
||||
|
||||
\param[in] d Коэффициент децимации.<BR>
|
||||
В результате децимации из вектора `x` будет взять каждый
|
||||
d-й элемент.<BR><BR>
|
||||
|
||||
\param[out] y Указатель на децимированный вектор `y`.<BR>
|
||||
Размер выходного вектора равен `[n/d x 1]`
|
||||
будет сохранен по адресу `cnt`.<BR>
|
||||
Память должна быть выделена.<BR><BR>
|
||||
|
||||
\param[out] cnt Указатель переменную, в которую будет сохранен
|
||||
размер выходного вектора после децимации.<BR>
|
||||
Указатель может быть `NULL`, в этом случае
|
||||
размер вектора `y` не возвращается.<BR><BR>
|
||||
|
||||
\return
|
||||
`RES_OK` если функция выполнена успешно.<BR>
|
||||
В противном случае \ref ERROR_CODE_GROUP "код ошибки".
|
||||
|
||||
Пример децимации вещественного массива данных в 2 раза:
|
||||
\code
|
||||
double x[10] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0};
|
||||
double y[5];
|
||||
int d = 2;
|
||||
int cnt;
|
||||
|
||||
decimate(x, 10, d, y, &cnt);
|
||||
\endcode
|
||||
в результате в переменную `cnt` будет записан размер 5,
|
||||
а вектор `y` будет хранить массив данных:
|
||||
\code
|
||||
c = [0.0, 2.0, 4.0, 6.0, 8.0]
|
||||
\endcode
|
||||
|
||||
\author Бахурин Сергей www.dsplib.org
|
||||
**************************************************************************** */
|
||||
|
||||
|
||||
|
||||
/*! ****************************************************************************
|
||||
\ingroup SPEC_MATH_COMMON_GROUP
|
||||
\fn int decimate_cmplx(complex_t* x, int n, int d, complex_t* y, int* cnt)
|
||||
\brief Децимация комплексного вектора данных
|
||||
|
||||
Функция производит децимацию комплексного вектора `x` в `d` раз.<BR>
|
||||
В результате выходной вектор `y` содержит значения:
|
||||
`y(k) = x(k*d), k = 0...n/d-1`<BR>
|
||||
|
||||
\param[in] x Указатель на вектор входных данных `x`.<BR>
|
||||
Размер вектора `[n x 1]`.<BR><BR>
|
||||
|
||||
\param[in] n Размер входного вектора `x`.<BR><BR>
|
||||
|
||||
\param[in] d Коэффициент децимации.<BR>
|
||||
В результате децимации из вектора `x` будет взять каждый
|
||||
d-й элемент.<BR><BR>
|
||||
|
||||
\param[out] y Указатель на децимированный вектор `y`.<BR>
|
||||
Размер выходного вектора равен `[n/d x 1]`
|
||||
будет сохранен по адресу `cnt`.<BR>
|
||||
Память должна быть выделена.<BR><BR>
|
||||
|
||||
\param[out] cnt Указатель переменную, в которую будет сохранен
|
||||
размер выходного вектора после децимации.<BR>
|
||||
Указатель может быть `NULL`, в этом случае
|
||||
размер вектора `y` не возвращается.<BR><BR>
|
||||
|
||||
\return
|
||||
`RES_OK` если функция выполнена успешно.<BR>
|
||||
В противном случае \ref ERROR_CODE_GROUP "код ошибки".
|
||||
|
||||
Пример децимации комплексного массива данных в 2 раза:
|
||||
\code
|
||||
compex_t x[10] = {{0.0, 0.0}, {1.0, 1.0}, {2.0, 2.0}, {3.0, 3.0}, {4.0, 4.0},
|
||||
{5.0, 5.0}, {6.0, 6.0}, {7.0, 7.0}, {8.0, 8.0}, {9.0, 9.0}};
|
||||
compex_t y[5];
|
||||
int d = 2;
|
||||
int cnt;
|
||||
|
||||
decimate_cmplx(x, 10, d, y, &cnt);
|
||||
\endcode
|
||||
в результате в переменную `cnt` будет записан размер 5,
|
||||
а вектор `y` будет хранить массив данных:
|
||||
\code
|
||||
c = [0.0+0.0j, 2.0+2.0j, 4.0+4.0j, 6.0+6.0j, 8.0+8.0j]
|
||||
\endcode
|
||||
|
||||
\author Бахурин Сергей www.dsplib.org
|
||||
**************************************************************************** */
|
||||
|
||||
|
||||
|
|
111
dspl/src/array.c
111
dspl/src/array.c
|
@ -90,23 +90,67 @@ int DSPL_API concat(void* a, size_t na, void* b, size_t nb, void* c)
|
|||
|
||||
|
||||
/******************************************************************************
|
||||
decimate real vector
|
||||
\ingroup SPEC_MATH_COMMON_GROUP
|
||||
\fn int decimate(double* x, int n, int d, double* y, int* cnt)
|
||||
\brief Real vector decimation
|
||||
|
||||
Function `d` times decimates real vector `x`.<BR>
|
||||
Output vector `y` keeps values corresponds to:
|
||||
`y(k) = x(k*d), k = 0...n/d-1`<BR>
|
||||
|
||||
\param[in] x Pointer to the input real vector `x`.<BR>
|
||||
Vector `x` size is `[n x 1]`.<BR><BR>
|
||||
|
||||
\param[in] n Size of input vector `x`.<BR><BR>
|
||||
|
||||
\param[in] d Decimation coefficient.<BR>
|
||||
Each d-th vector will be copy from vector `x` to the
|
||||
output vector `y`.<BR><BR>
|
||||
|
||||
\param[out] y Pointer to the output decimated vector `y`.<BR>
|
||||
Output vector size is `[n/d x 1]` will be copy
|
||||
to the address `cnt`.<BR>
|
||||
|
||||
\param[out] cnt Address which will keep decimated vector `y` size.<BR>
|
||||
Pointer can be `NULL`, vector `y` will not return
|
||||
in this case.<BR><BR>
|
||||
|
||||
\return
|
||||
`RES_OK` if function calculated successfully.<BR>
|
||||
Else \ref ERROR_CODE_GROUP "code error".
|
||||
|
||||
Two-times decimation example:
|
||||
\code
|
||||
double x[10] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0};
|
||||
double y[5];
|
||||
int d = 2;
|
||||
int cnt;
|
||||
|
||||
decimate(x, 10, d, y, &cnt);
|
||||
\endcode
|
||||
As result variable `cnt` will be written value 5 and
|
||||
vector `y` will keep array:
|
||||
\code
|
||||
c = [0.0, 2.0, 4.0, 6.0, 8.0]
|
||||
\endcode
|
||||
|
||||
\author Sergey Bakhurin www.dsplib.org
|
||||
*******************************************************************************/
|
||||
int DSPL_API decimate(double* x, int n, int dec, double* y, int* cnt)
|
||||
int DSPL_API decimate(double* x, int n, int d, double* y, int* cnt)
|
||||
{
|
||||
int k = 0, i = 0;
|
||||
if(!x || !y)
|
||||
return ERROR_PTR;
|
||||
if(n < 1)
|
||||
return ERROR_SIZE;
|
||||
if(dec < 1)
|
||||
if(d < 1)
|
||||
return ERROR_NEGATIVE;
|
||||
|
||||
k = i = 0;
|
||||
while(k + dec < n)
|
||||
while(k + d <= n)
|
||||
{
|
||||
y[i] = x[k];
|
||||
k+=dec;
|
||||
k+=d;
|
||||
i++;
|
||||
}
|
||||
if(cnt)
|
||||
|
@ -119,25 +163,70 @@ int DSPL_API decimate(double* x, int n, int dec, double* y, int* cnt)
|
|||
|
||||
|
||||
/******************************************************************************
|
||||
decimate complex vector
|
||||
\ingroup SPEC_MATH_COMMON_GROUP
|
||||
\fn int decimate_cmplx(complex_t* x, int n, int d, complex_t* y, int* cnt)
|
||||
\brief Complex vector decimation
|
||||
|
||||
Function `d` times decimates a complex vector `x`.<BR>
|
||||
Output vector `y` keeps values corresponds to:
|
||||
`y(k) = x(k*d), k = 0...n/d-1`<BR>
|
||||
|
||||
\param[in] x Pointer to the input complex vector `x`.<BR>
|
||||
Vector `x` size is `[n x 1]`.<BR><BR>
|
||||
|
||||
\param[in] n Size of input vector `x`.<BR><BR>
|
||||
|
||||
\param[in] d Decimation coefficient.<BR>
|
||||
Each d-th vector will be copy from vector `x` to the
|
||||
output vector `y`.<BR><BR>
|
||||
|
||||
\param[out] y Pointer to the output decimated vector `y`.<BR>
|
||||
Output vector size is `[n/d x 1]` will be copy
|
||||
to the address `cnt`.<BR>
|
||||
Memory must be allocated.<BR><BR>
|
||||
|
||||
\param[out] cnt Address which will keep decimated vector `y` size.<BR>
|
||||
Pointer can be `NULL`, vector `y` will not return
|
||||
in this case.<BR><BR>
|
||||
|
||||
\return
|
||||
`RES_OK` if function calculated successfully.<BR>
|
||||
Else \ref ERROR_CODE_GROUP "code error".
|
||||
|
||||
Two-times complex vector decimation example:
|
||||
\code
|
||||
compex_t x[10] = {{0.0, 0.0}, {1.0, 1.0}, {2.0, 2.0}, {3.0, 3.0}, {4.0, 4.0},
|
||||
{5.0, 5.0}, {6.0, 6.0}, {7.0, 7.0}, {8.0, 8.0}, {9.0, 9.0}};
|
||||
compex_t y[5];
|
||||
int d = 2;
|
||||
int cnt;
|
||||
|
||||
decimate_cmplx(x, 10, d, y, &cnt);
|
||||
\endcode
|
||||
As result variable `cnt` will be written value 5 and
|
||||
vector `y` will keep array:
|
||||
\code
|
||||
c = [0.0+0.0j, 2.0+2.0j, 4.0+4.0j, 6.0+6.0j, 8.0+8.0j]
|
||||
\endcode
|
||||
|
||||
\author Sergey Bakhurin www.dsplib.org
|
||||
*******************************************************************************/
|
||||
int DSPL_API decimate_cmplx(complex_t* x, int n, int dec,
|
||||
complex_t* y, int* cnt)
|
||||
int DSPL_API decimate_cmplx(complex_t* x, int n, int d, complex_t* y, int* cnt)
|
||||
{
|
||||
int k = 0, i = 0;
|
||||
if(!x || !y)
|
||||
return ERROR_PTR;
|
||||
if(n < 1)
|
||||
return ERROR_SIZE;
|
||||
if(dec < 1)
|
||||
if(d < 1)
|
||||
return ERROR_NEGATIVE;
|
||||
|
||||
k = i = 0;
|
||||
while(k + dec < n)
|
||||
while(k + d < n)
|
||||
{
|
||||
RE(y[i]) = RE(x[k]);
|
||||
IM(y[i]) = IM(x[k]);
|
||||
k+=dec;
|
||||
k+=d;
|
||||
i++;
|
||||
}
|
||||
if(cnt)
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "dspl.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
void* handle; // DSPL handle
|
||||
handle = dspl_load(); // Load DSPL function
|
||||
|
||||
double a[5] = {0.0, 1.0, 2.0, 3.0, 4.0};
|
||||
double b[5] = {5.0, 6.0, 7.0, 8.0, 9.0};
|
||||
double c[10], d[5];
|
||||
int err, k, n;
|
||||
|
||||
// Concatenate arrays a and b. Result keeps to the array c
|
||||
err = concat((void*)a, 5*sizeof(double),
|
||||
(void*)b, 5*sizeof(double), (void*)c);
|
||||
printf("\n\nconcatenation result: %d\n\narray c = ", err);
|
||||
for(k = 0; k < 10; k++)
|
||||
printf("%6.1f", c[k]);
|
||||
|
||||
// Decimate array c 2 times. Result keeps to the array d
|
||||
err = decimate(c, 10, 2, d, &n);
|
||||
printf("\n\ndecimation result: %d\n\narray d = ", err);
|
||||
for (k = 0; k < n; k++)
|
||||
printf("%6.1f", d[k]);
|
||||
|
||||
dspl_free(handle); // free dspl handle
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
@ -357,13 +357,13 @@ DECLARE_FUNC(int, cos_cmplx, complex_t*
|
|||
//------------------------------------------------------------------------------
|
||||
DECLARE_FUNC(int, decimate, double* x
|
||||
COMMA int n
|
||||
COMMA int dec
|
||||
COMMA int d
|
||||
COMMA double* y
|
||||
COMMA int* cnt);
|
||||
//------------------------------------------------------------------------------
|
||||
DECLARE_FUNC(int, decimate_cmplx, complex_t* x
|
||||
COMMA int n
|
||||
COMMA int dec
|
||||
COMMA int d
|
||||
COMMA complex_t* y
|
||||
COMMA int* cnt);
|
||||
//------------------------------------------------------------------------------
|
||||
|
|
|
@ -357,13 +357,13 @@ DECLARE_FUNC(int, cos_cmplx, complex_t*
|
|||
//------------------------------------------------------------------------------
|
||||
DECLARE_FUNC(int, decimate, double* x
|
||||
COMMA int n
|
||||
COMMA int dec
|
||||
COMMA int d
|
||||
COMMA double* y
|
||||
COMMA int* cnt);
|
||||
//------------------------------------------------------------------------------
|
||||
DECLARE_FUNC(int, decimate_cmplx, complex_t* x
|
||||
COMMA int n
|
||||
COMMA int dec
|
||||
COMMA int d
|
||||
COMMA complex_t* y
|
||||
COMMA int* cnt);
|
||||
//------------------------------------------------------------------------------
|
||||
|
|
Ładowanie…
Reference in New Issue