 libdspl-2.0 Digital Signal Processing Algorithm Library
Basic operations for real and complex arrays.

## Functions

int DSPL_API array_scale_lin (double *x, int n, double xmin, double xmax, double dx, double h, double *y)
Vector x linear transformation. More...

int DSPL_API concat (void *a, size_t na, void *b, size_t nb, void *c)
Concatenate arrays a and b More...

int DSPL_API decimate (double *x, int n, int d, double *y, int *cnt)
Real vector decimation. More...

int DSPL_API decimate_cmplx (complex_t *x, int n, int d, complex_t *y, int *cnt)
Complex vector decimation. More...

int DSPL_API flipip (double *x, int n)
Flip real vector x in place. More...

int DSPL_API flipip_cmplx (complex_t *x, int n)
Flip complex vector x in place. More...

int DSPL_API linspace (double x0, double x1, int n, int type, double *x)
Function fills a vector with n linearly spaced elements between x0 and x1. More...

int DSPL_API logspace (double x0, double x1, int n, int type, double *x)
Function fills a vector with n logarithmically spaced elements between and . More...

int DSPL_API ones (double *x, int n)
Function fills all real vector x by ones values. More...

int DSPL_API verif (double *x, double *y, size_t n, double eps, double *err)
Real arrays verification. More...

int DSPL_API verif_cmplx (complex_t *x, complex_t *y, size_t n, double eps, double *err)
Complex arrays verification. More...

## ◆ array_scale_lin()

 int array_scale_lin ( double * x, int n, double xmin, double xmax, double dx, double h, double * y )

Vector x linear transformation.

Function transforms values , to the , accordint to equation: All values of the vector x between and , transforms to the vector y between and . Parameter sets mean shift of the vector y.

This function is convenient for translating values ​​ of different dimensions. For example it can be used to transfer the values ​​of the vector x to the graph of the height ofh, where the height can be set in the number of pixels, in centimeters, etc.

Parameters
 [in] x Pointer to the input vector x. Vector size is [n x 1]. [in] n Size of vector x. [in] xmin Parameter . [in] xmax Parameter . Value xmax must be more than xmin. [in] dx Displacement after transformation. This parameter must have output vector y dimensions (pixels, centimeters). [in] h Height of vector y after transforming between dx and h+dx. [out] y Pointer to the output vector y. Vector size is [n x 1]. Memory must be allocated.
Note
Pointer y can be equal to x. Velues of vector x will be rewritten in this case.

Returns
RES_OK if function returns successfully.
Else code error.

Definition at line 171 of file array.c.

## ◆ concat()

 int concat ( void * a, size_t na, void * b, size_t nb, void * c )

Concatenate arrays a and b

Let's arrays a and b are vectors:
a = [a(0), a(1), ... a(na-1)],
b = [b(0), b(1), ... b(nb-1)],
concatenation of these arrays will be array c size na+nb:
c = [a(0), a(1), ... a(na-1), b(0), b(1), ... b(nb-1)].

Parameters
 [in] a Pointer to the first array a. Array a size is na bytes. [in] na Array a size (bytes). [in] b Pointer to the second array b. Array b size is nb bytes. [in] nb Array a size (bytes). [out] c Pointer to the concatenation result array c. Array c size is na + nb bytes. Memory must be allocated.
Returns
RES_OK if function returns successfully.
Else code error.

Function uses pointer type void* and can be useful for an arrays concatenation with different types.
For example two double arrays concatenation:

double a = {1.0, 2.0, 3.0};
double b = {4.0, 5.0};
double c;
concat((void*)a, 3*sizeof(double), (void*)b, 2*sizeof(double), (void*)c);

Vector c keeps follow data:

c = [1.0, 2.0, 3.0, 4.0, 5.0]


Definition at line 315 of file array.c.

## ◆ decimate()

 int decimate ( double * x, int n, int d, double * y, int * cnt )

Real vector decimation.

Function d times decimates real vector x.
Output vector y keeps values corresponds to: y(k) = x(k*d), k = 0...n/d-1

Parameters
 [in] x Pointer to the input real vector x. Vector x size is [n x 1]. [in] n Size of input vector x. [in] d Decimation coefficient. Each d-th vector will be copy from vector x to the output vector y. [out] y Pointer to the output decimated vector y. Output vector size is [n/d x 1] will be copy to the address cnt. [out] cnt Address which will keep decimated vector y size. Pointer can be NULL, vector y will not return in this case.
Returns
RES_OK if function calculated successfully.
Else code error.

Two-times decimation example:

double x = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0};
double y;
int d = 2;
int cnt;
decimate(x, 10, d, y, &cnt);

As result variable cnt will be written value 5 and vector y will keep array:

c = [0.0, 2.0, 4.0, 6.0, 8.0]


Definition at line 445 of file array.c.

## ◆ decimate_cmplx()

 int decimate_cmplx ( complex_t * x, int n, int d, complex_t * y, int * cnt )

Complex vector decimation.

Function d times decimates a complex vector x.
Output vector y keeps values corresponds to: y(k) = x(k*d), k = 0...n/d-1

Parameters
 [in] x Pointer to the input complex vector x. Vector x size is [n x 1]. [in] n Size of input vector x. [in] d Decimation coefficient. Each d-th vector will be copy from vector x to the output vector y. [out] y Pointer to the output decimated vector y. Output vector size is [n/d x 1] will be copy to the address cnt. Memory must be allocated. [out] cnt Address which will keep decimated vector y size. Pointer can be NULL, vector y will not return in this case.
Returns
RES_OK if function calculated successfully.
Else code error.

Two-times complex vector decimation example:

compex_t x = {{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;
int d = 2;
int cnt;
decimate_cmplx(x, 10, d, y, &cnt);

As result variable cnt will be written value 5 and vector y will keep array:

c = [0.0+0.0j, 2.0+2.0j, 4.0+4.0j, 6.0+6.0j, 8.0+8.0j]


Definition at line 587 of file array.c.

## ◆ flipip()

 int flipip ( double * x, int n )

Flip real vector x in place.

Function flips real vector x length n in the memory.
For example real vector x length 6:

x = [0, 1, 2, 3, 4, 5]


After flipping it will be as follow:

x = [5, 4, 3, 2, 1, 0]

Parameters
 [in,out] x Pointer to the real vector x. Vector size is [n x 1]. Flipped vector will be on the same address. [in] n Length of the vector x.
Returns
RES_OK if function returns successfully.
Else error code.

Example:

double x = {0.0, 1.0, 2.0, 3.0, 4.0};
int i;
for(i = 0; i < 5; i++)
printf("%6.1f ", x[i]);
flipip(x, 5);
printf("\n");
for(i = 0; i < 5; i++)
printf("%6.1f ", x[i]);

Program result:

     0.0         1.0         2.0         3.0         4.0
4.0         3.0         2.0         1.0         0.0


Definition at line 719 of file array.c.

## ◆ flipip_cmplx()

 int flipip_cmplx ( complex_t * x, int n )

Flip complex vector x in place.

Function flips complex vector x length n in the memory
For example complex vector x length 6:

x = [0+0j, 1+1j, 2+2j, 3+3j, 4+4j, 5+5j]


After flipping it will be as follow:

x = [5+5j, 4+4j, 3+3j, 2+2j, 1+1j, 0+0j]

Parameters
 [in,out] x Pointer to the complex vector x. Vector size is [n x 1]. Flipped vector will be on the same address. [in] n Length of the vector x.
Returns
RES_OK if function returns successfully.
Else error code.

Example:

complex_t y = {{0.0, 0.0}, {1.0, 1.0}, {2.0, 2.0}, {3.0, 3.0}, {4.0, 4.0}};
for(i = 0; i < 5; i++)
printf("%6.1f%+.1fj ", RE(y[i]), IM(y[i]));
printf("\n");
for(i = 0; i < 5; i++)
printf("%6.1f%+.1fj ", RE(y[i]), IM(y[i]));

Program result:

0.0+0.0j         1.0+1.0j         2.0+2.0j         3.0+3.0j         4.0+4.0j
4.0+4.0j         3.0+3.0j         2.0+2.0j         1.0+1.0j         0.0+0.0j


Definition at line 842 of file array.c.

## ◆ linspace()

 int linspace ( double x0, double x1, int n, int type, double * x )

Function fills a vector with n linearly spaced elements between x0 and x1.

Function supports two kinds of filling according to type parameter:
Symmetric fill (parameter type=DSPL_SYMMETRIC): , , Periodic fill (parameter type=DSPL_PERIODIC): , , Parameters
 [in] x0 Start point . [in] x1 End point . [in] n Number of points x (size of vector x). [in] type Fill type: DSPL_SYMMETRIC — symmetric, DSPL_PERIODIC — periodic. [in,out] x Pointer to the output linearly spaced vector x. Vector size is [n x 1]. Memory must be allocated.
Returns
RES_OK if function returns successfully.
Else error code.
Note
Difference between symmetric and periodic filling we can understand from the follow examples.
Example 1. Periodic fill. double x; linspace(0, 5, 5, DSPL_PERIODIC, x); Values in the vector x are:
0,    1,    2,    3,    4


Example 2. Symmetric fill.
double x;
linspace(0, 5, 5, DSPL_SYMMETRIC, x);
Values in the vector x are:
0,    1.25,    2.5,    3.75,    5


Definition at line 1009 of file array.c.

## ◆ logspace()

 int logspace ( double x0, double x1, int n, int type, double * x )

Function fills a vector with n logarithmically spaced elements between and .

Function supports two kinds of filling according to type parameter:
Symmetric fill (parameter type=DSPL_SYMMETRIC): , here , Periodic fill (parameter type=DSPL_PERIODIC): , here , Parameters
 [in] x0 Start exponent value . [in] x1 End exponent value . [in] n Number of points x (size of vector x). [in] type Fill type: DSPL_SYMMETRIC — symmetric, DSPL_PERIODIC — periodic. [in,out] x Pointer to the output logarithmically spaced vector x . Vector size is [n x 1]. Memory must be allocated.
Returns
RES_OK if function returns successfully.
Else error code.
Note
Difference between symmetric and periodic filling we can understand from the follow examples.
Example 1. Periodic fill.
double x;
logspace(-2, 3, 5, DSPL_PERIODIC, x);

Values in the vector x are:

0.01,    0.1,    1,    10,    100


Example 2. Symmetric fill.

double x;
logspace(-2, 3, 5, DSPL_SYMMETRIC, x);

Values in the vector x are:

0.01    0.178    3.162    56.234    1000


Definition at line 1192 of file array.c.

## ◆ ones()

 int ones ( double * x, int n )

Function fills all real vector x by ones values.

Parameters
 [in,out] x Pointer to the vector x. Vector size is [n x 1]. All elements on this vector will be set to one. [in] n Size of vector x.
Returns
RES_OK if function returns successfully.
Else error code.

Example:

double y = {0};
int i;
ones(y, 5);
for(i = 0; i < 5; i++)
printf("%6.1f% ", y[i]);

Vector y values are:

    1.0    1.0    1.0    1.0    1.0


Definition at line 1302 of file array.c.

## ◆ verif()

 int verif ( double * x, double * y, size_t n, double eps, double * err )

Real arrays verification.

Function calculates a maximum relative error between two real arrays x and y (both length equals n): or This function can be used for algorithms verification if vector x is user algorithm result and vector y – reference vector.

Parameters
 [in] x Pointer to the first vector x. Vector size is [n x 1]. [in] y Pointer to the second vector y. Vector size is [n x 1]. [in] n Size of vectors x and y. [in] eps Relative error threshold. If error less than eps, then function returns DSPL_VERIF_SUCCESS, else DSPL_VERIF_FAILED. [in,out] err Pointer to the variable which keep maximum relative error. Pointer can be NULL, maximum error will not be returned in this case.
Returns
DSPL_VERIF_SUCCESS if maximum relative error less than eps.
Otherwise DSPL_VERIF_FAILED.

Definition at line 130 of file verification.c.

## ◆ verif_cmplx()

 int verif_cmplx ( complex_t * x, complex_t * y, size_t n, double eps, double * err )

Complex arrays verification.

Function calculates a maximum relative error between two complex arrays x and y (both length equals n): or Return DSPL_VERIF_SUCCESS if maximum relative error less than eps. Else returns DSPL_VERIF_FAILED.
This function can be used for algorithms verification if vector x is user algorithm result and vector y – reference vector.

Parameters
 [in] x Pointer to the first vector x. Vector size is [n x 1]. [in] y Pointer to the second vector y. Vector size is [n x 1]. [in] n Size of vectors x and y. [in] eps Relative error threshold. If error less than eps, then function returns DSPL_VERIF_SUCCESS, else DSPL_VERIF_FAILED. [in,out] err Pointer to the variable which keep maximum relative error. Pointer can be NULL, maximum error will not be returned in this case.
Returns
DSPL_VERIF_SUCCESS if maximum relative error less than eps.
Otherwise DSPL_VERIF_FAILED.

Definition at line 347 of file verification.c.

int DSPL_API flipip_cmplx(complex_t *x, int n)
Flip complex vector x in place.
Definition: array.c:842
int DSPL_API flipip(double *x, int n)
Flip real vector x in place.
Definition: array.c:719
#define RE(x)
Macro sets real part of the complex number.
Definition: dspl.h:359
int DSPL_API logspace(double x0, double x1, int n, int type, double *x)
Function fills a vector with n logarithmically spaced elements between and .
Definition: array.c:1192
int DSPL_API ones(double *x, int n)
Function fills all real vector x by ones values.
Definition: array.c:1302
double complex_t
Complex data type.
Definition: dspl.h:86
int DSPL_API decimate(double *x, int n, int d, double *y, int *cnt)
Real vector decimation.
Definition: array.c:445
int DSPL_API concat(void *a, size_t na, void *b, size_t nb, void *c)
Concatenate arrays a and b
Definition: array.c:315
int DSPL_API linspace(double x0, double x1, int n, int type, double *x)
Function fills a vector with n linearly spaced elements between x0 and x1.
Definition: array.c:1009
#define IM(x)
Macro sets imaginary part of the complex number.
Definition: dspl.h:417
int DSPL_API decimate_cmplx(complex_t *x, int n, int d, complex_t *y, int *cnt)
Complex vector decimation.
Definition: array.c:587