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 \(10^{x_0}\) and \(10^{x_1}\). More...
 
int DSPL_API ones (double *x, int n)
 Function fills all real vector x by ones values. More...
 
int DSPL_API sum (double *x, int n, double *s)
 
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...
 

Detailed Description

Function Documentation

◆ 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 \(x(i)\), \(i = 0,1,\ldots n\) to the \(y(i)\), accordint to equation:

\[ y(i) = k_x x(i) + d_x, \qquad k_x = \frac{h}{x_{\textrm{max}} - x_{\textrm{min}}}. \]

All values of the vector x between \(x_{\textrm{min}}\) and \(x_{\textrm{max}}\), transforms to the vector y between \(d_x\) and \(h + d_x\). Parameter \(d_x\) 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]xPointer to the input vector x.
Vector size is [n x 1].

[in]nSize of vector x.

[in]xminParameter \(x_{\textrm{min}}\).

[in]xmaxParameter \(x_{\textrm{min}}\).
Value xmax must be more than xmin.

[in]dxDisplacement after transformation.
This parameter must have output vector y dimensions (pixels, centimeters).

[in]hHeight of vector y after transforming between dx and h+dx.

[out]yPointer 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.
Author
Sergey Bakhurin www.dsplib.org

Definition at line 171 of file array_scale_lin.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]aPointer to the first array a.
Array a size is na bytes.

[in]naArray a size (bytes).

[in]bPointer to the second array b.
Array b size is nb bytes.

[in]nbArray a size (bytes).

[out]cPointer 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[3] = {1.0, 2.0, 3.0};
double b[2] = {4.0, 5.0};
double c[5];
concat((void*)a, 3*sizeof(double), (void*)b, 2*sizeof(double), (void*)c);
int DSPL_API concat(void *a, size_t na, void *b, size_t nb, void *c)
Concatenate arrays a and b
Definition: concat.c:146

Vector c keeps follow data:

c = [1.0, 2.0, 3.0, 4.0, 5.0]
Author
Sergey Bakhurin www.dsplib.org

Definition at line 146 of file concat.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]xPointer to the input real vector x.
Vector x size is [n x 1].

[in]nSize of input vector x.

[in]dDecimation coefficient.
Each d-th vector will be copy from vector x to the output vector y.

[out]yPointer to the output decimated vector y.
Output vector size is [n/d x 1] will be copy to the address cnt.
[out]cntAddress 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[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);
int DSPL_API decimate(double *x, int n, int d, double *y, int *cnt)
Real vector decimation.
Definition: decimate.c:140

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]
Author
Sergey Bakhurin www.dsplib.org

Definition at line 140 of file decimate.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]xPointer to the input complex vector x.
Vector x size is [n x 1].

[in]nSize of input vector x.

[in]dDecimation coefficient.
Each d-th vector will be copy from vector x to the output vector y.

[out]yPointer 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]cntAddress 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[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);
int DSPL_API decimate_cmplx(complex_t *x, int n, int d, complex_t *y, int *cnt)
Complex vector decimation.

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]
Author
Sergey Bakhurin www.dsplib.org

Definition at line 144 of file decimate_cmplx.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]xPointer to the real vector x.
Vector size is [n x 1].
Flipped vector will be on the same address.

[in]nLength of the vector x.

Returns
RES_OK if function returns successfully.
Else error code.

Example:

double x[5] = {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]);
int DSPL_API flipip(double *x, int n)
Flip real vector x in place.
Definition: flipip.c:133


Program result:

     0.0         1.0         2.0         3.0         4.0
     4.0         3.0         2.0         1.0         0.0
Author
Sergey Bakhurin www.dsplib.org

Definition at line 133 of file flipip.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]xPointer to the complex vector x.
Vector size is [n x 1].
Flipped vector will be on the same address.
[in]nLength of the vector x.

Returns
RES_OK if function returns successfully.
Else error code.

Example:

complex_t y[5] = {{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]));
int DSPL_API flipip_cmplx(complex_t *x, int n)
Flip complex vector x in place.
Definition: flipip_cmplx.c:132
#define RE(x)
Macro sets real part of the complex number.
Definition: dspl.h:420
double complex_t[2]
Complex data type.
Definition: dspl.h:86
#define IM(x)
Macro sets imaginary part of the complex number.
Definition: dspl.h:478


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
Author
Sergey Bakhurin www.dsplib.org

Definition at line 132 of file flipip_cmplx.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):
\(x(k) = x_0 + k \cdot dx\), \(dx = \frac{x_1 - x_0}{n-1}\), \(k = 0 \ldots n-1.\)

Periodic fill (parameter type=DSPL_PERIODIC):
\(x(k) = x_0 + k \cdot dx\), \(dx = \frac{x_1 - x_0}{n}\), \(k = 0 \ldots n-1.\)

Parameters
[in]x0Start point \(x_0\).

[in]x1End point \(x_1\).

[in]nNumber of points x (size of vector x).

[in]typeFill type:
DSPL_SYMMETRIC — symmetric,
DSPL_PERIODIC — periodic.

[in,out]xPointer 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[5]; linspace(0, 5, 5, DSPL_PERIODIC, x); Values in the vector x are:
0,    1,    2,    3,    4


Example 2. Symmetric fill.
double x[5];
linspace(0, 5, 5, DSPL_SYMMETRIC, x);
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: linspace.c:169
Values in the vector x are:
0,    1.25,    2.5,    3.75,    5
Author
Sergey Bakhurin www.dsplib.org

Definition at line 169 of file linspace.c.

◆ logspace()

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

Function fills a vector with n logarithmically spaced elements between \(10^{x_0}\) and \(10^{x_1}\).


Function supports two kinds of filling according to type parameter:
Symmetric fill (parameter type=DSPL_SYMMETRIC):
\(x(k) = 10^{x_0} \cdot dx^k\), here \(dx = \sqrt[n-1]{10^{x_1 - x_0}}\), \(k = 0 \ldots n-1.\)

Periodic fill (parameter type=DSPL_PERIODIC):
\(x(k) = 10^{x_0} \cdot dx^k\), here \(dx = \sqrt[n]{10^{x_1 - x_0}}\), \(k = 0 \ldots n-1.\)

Parameters
[in]x0Start exponent value \(x_0\).

[in]x1End exponent value \(x_1\).

[in]nNumber of points x (size of vector x).

[in]typeFill type:
DSPL_SYMMETRIC — symmetric,
DSPL_PERIODIC — periodic.

[in,out]xPointer 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[5];
logspace(-2, 3, 5, DSPL_PERIODIC, x);
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: logspace.c:178

Values in the vector x are:

0.01,    0.1,    1,    10,    100



Example 2. Symmetric fill.

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

Values in the vector x are:

0.01    0.178    3.162    56.234    1000
Author
Sergey Bakhurin www.dsplib.org

Definition at line 178 of file logspace.c.

◆ ones()

int ones ( double *  x,
int  n 
)

Function fills all real vector x by ones values.


Parameters
[in,out]xPointer to the vector x.
Vector size is [n x 1].
All elements on this vector will be set to one.

[in]nSize of vector x.

Returns
RES_OK if function returns successfully.
Else error code.

Example:

double y[5] = {0};
int i;
ones(y, 5);
for(i = 0; i < 5; i++)
printf("%6.1f% ", y[i]);
int DSPL_API ones(double *x, int n)
Function fills all real vector x by ones values.
Definition: ones.c:103


Vector y values are:

    1.0    1.0    1.0    1.0    1.0
Author
Sergey Bakhurin www.dsplib.org

Definition at line 103 of file ones.c.

◆ sum()

int sum ( double *  x,
int  n,
double *  s 
)

Author
Sergey Bakhurin www.dsplib.org

Definition at line 43 of file sum.c.

Referenced by mean(), mean_cmplx(), stat_std(), and stat_std_cmplx().

◆ 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):

\[ e = \max \left( \frac{|x(k) - y(k)| }{ |x(k)|} \right), \quad if \quad |x(k)| > 0, \]

or

\[ e = \max(|x(k) - y(k)| ), ~\qquad if \quad~|x(k)| = 0, \]

This function can be used for algorithms verification if vector x is user algorithm result and vector y – reference vector.

Parameters
[in]xPointer to the first vector x.
Vector size is [n x 1].

[in]yPointer to the second vector y.
Vector size is [n x 1].

[in]nSize of vectors x and y.

[in]epsRelative error threshold.
If error less than eps, then function returns DSPL_VERIF_SUCCESS, else DSPL_VERIF_FAILED.

[in,out]errPointer 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.
Author
Sergey Bakhurin www.dsplib.org

Definition at line 130 of file verif.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):

\[ e = \max \left( \frac{|x(k) - y(k)| }{ |x(k)|} \right), \quad if \quad |x(k)| > 0, \]

or

\[ e = \max(|x(k) - y(k)| ), ~\qquad if \quad~|x(k)| = 0, \]

Return DSPL_VERIF_SUCCESS if maximum relative error \( e\) 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]xPointer to the first vector x.
Vector size is [n x 1].

[in]yPointer to the second vector y.
Vector size is [n x 1].

[in]nSize of vectors x and y.

[in]epsRelative error threshold.
If error less than eps, then function returns DSPL_VERIF_SUCCESS, else DSPL_VERIF_FAILED.

[in,out]errPointer 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.
Author
Sergey Bakhurin www.dsplib.org

Definition at line 141 of file verif_cmplx.c.