libdspl-2.0
Digital Signal Processing Algorithm Library
|
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] x Pointer to the input vector x
.
Vector size is[n x 1]
.
[in] n Size of vector x
.
[in] xmin Parameter \(x_{\textrm{min}}\).
[in] xmax Parameter \(x_{\textrm{min}}\).
Valuexmax
must be more thanxmin
.
[in] dx Displacement after transformation.
This parameter must have output vectory
dimensions (pixels, centimeters).
[in] h Height of vector y
after transforming betweendx
andh+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 tox
. Velues of vectorx
will be rewritten in this case.
- Returns
RES_OK
if function returns successfully.
Else code error.
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] a Pointer to the first array a
.
Arraya
size isna
bytes.
[in] na Array a
size (bytes).
[in] b Pointer to the second array b
.
Arrayb
size isnb
bytes.
[in] nb Array a
size (bytes).
[out] c Pointer to the concatenation result array c
.
Arrayc
size isna + 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:
Vector c
keeps follow data:
c = [1.0, 2.0, 3.0, 4.0, 5.0]
◆ 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
.
Vectorx
size is[n x 1]
.
[in] n Size of input vector x
.
[in] d Decimation coefficient.
Each d-th vector will be copy from vectorx
to the output vectory
.
[out] y Pointer to the output decimated vector y
.
Output vector size is[n/d x 1]
will be copy to the addresscnt
.
[out] cnt Address which will keep decimated vector y
size.
Pointer can beNULL
, vectory
will not return in this case.
- Returns
RES_OK
if function calculated successfully.
Else code error.
Two-times decimation example:
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 140 of file decimate.c.
◆ decimate_cmplx()
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
.
Vectorx
size is[n x 1]
.
[in] n Size of input vector x
.
[in] d Decimation coefficient.
Each d-th vector will be copy from vectorx
to the output vectory
.
[out] y Pointer to the output decimated vector y
.
Output vector size is[n/d x 1]
will be copy to the addresscnt
.
Memory must be allocated.
[out] cnt Address which will keep decimated vector y
size.
Pointer can beNULL
, vectory
will not return in this case.
- Returns
RES_OK
if function calculated successfully.
Else code error.
Two-times complex vector decimation example:
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 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] 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:
Program result:
0.0 1.0 2.0 3.0 4.0 4.0 3.0 2.0 1.0 0.0
◆ 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:
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 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] x0 Start point \(x_0\).
[in] x1 End point \(x_1\).
[in] n Number of points x
(size of vectorx
).
[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[5]; linspace(0, 5, 5, DSPL_PERIODIC, x); Values in the vectorx
are:0, 1, 2, 3, 4
Example 2. Symmetric fill.Values in the vectordouble 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:169x
are:0, 1.25, 2.5, 3.75, 5
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] x0 Start exponent value \(x_0\).
[in] x1 End exponent value \(x_1\).
[in] n Number of points x
(size of vectorx
).
[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[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.
Values in the vector x
are:
0.01 0.178 3.162 56.234 1000
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] 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:
Vector y
values are:
1.0 1.0 1.0 1.0 1.0
◆ sum()
int sum | ( | double * | x, |
int | n, | ||
double * | s | ||
) |
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] 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
andy
.
[in] eps Relative error threshold.
If error less thaneps
, then function returnsDSPL_VERIF_SUCCESS
, elseDSPL_VERIF_FAILED
.
[in,out] err Pointer to the variable which keep maximum relative error.
Pointer can beNULL
, maximum error will not be returned in this case.
- Returns
DSPL_VERIF_SUCCESS
if maximum relative error less thaneps
.
OtherwiseDSPL_VERIF_FAILED
.
◆ verif_cmplx()
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] 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
andy
.
[in] eps Relative error threshold.
If error less thaneps
, then function returnsDSPL_VERIF_SUCCESS
, elseDSPL_VERIF_FAILED
.
[in,out] err Pointer to the variable which keep maximum relative error.
Pointer can beNULL
, maximum error will not be returned in this case.
- Returns
DSPL_VERIF_SUCCESS
if maximum relative error less thaneps
.
OtherwiseDSPL_VERIF_FAILED
.
Definition at line 141 of file verif_cmplx.c.
Generated on Wed Jan 5 2022 12:44:37 for libdspl-2.0 by 1.9.2