libdspl-2.0
Digital Signal Processing Algorithm Library
Math statistic functions.

Functions

int DSPL_API xcorr_cmplx (complex_t *x, int nx, complex_t *y, int ny, int flag, int nr, complex_t *r, double *t)
 Estimates the cross-correlation vector for complex discrete-time sequences x and y. More...
 
int DSPL_API find_max_abs (double *a, int n, double *m, int *ind)
 Find maximum absolute value from the real vector a More...
 
int DSPL_API xcorr (double *x, int nx, double *y, int ny, int flag, int nr, double *r, double *t)
 Estimates the cross-correlation vector for real discrete-time sequences x and y. More...
 

Detailed Description

Function Documentation

◆ find_max_abs()

int find_max_abs ( double *  a,
int  n,
double *  m,
int *  ind 
)

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.

Parameters
[in]aPointer to the real vector a.
Vector size is [n x 1].

[in]nSize of the input vector a.

[out]mPointer to the variable which keeps vector a maximum absolute value.
Pointer can be NULL, maximum value will not return in this case.

[out]indPointer to the variable which keeps index of a maximum absolute value inside vector a.
Pointer can be NULL, index will not return in this case.

Returns
RES_OK if function calculates successfully, else code error.

Example:

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);

As result the variable m will keep value 5, and variable ind will keep 2.

Author
Sergey Bakhurin www.dsplib.org

Definition at line 123 of file statistic.c.

◆ xcorr()

int xcorr ( double *  x,
int  nx,
double *  y,
int  ny,
int  flag,
int  nr,
double *  r,
double *  t 
)

Estimates the cross-correlation vector for real discrete-time sequences x and y.


Estimate the cross correlation $\widehat{r}_{xy}(k)$ of vector arguments x and y or estimate autocorrelation vector if $x = y $.

Cross-correlation vector is defined as:

\[ \widehat{r}_{xy}(k) = \frac{1}{N-k} \sum\limits_{n = 0}^{N-k-1} x(n+k)y^*(n), \qquad 0 \leq k <N; \]

\[ \widehat{r}_{xy}(k) = \frac{1}{N+k} \sum\limits_{n = 0}^{N+k-1} y^*(n-k)x(n), \qquad -N < k < 0. \]

here $ N = \max(n_x, n_y) $.

This function uses the FFT algorithm to estimate the scaled correlation vector:

\[ \breve{r}_{xy}(k) = \operatorname{IFFT}\Big[ \operatorname{FFT}\big[ \mathbf{x} \big] \operatorname{FFT}^*\big[ \mathbf{y} \big] \Big] \]

Parameters
[in]xPointer to the discrete-time vector x.
Vector size is [nx x 1].

[in]nxSize of vector x.

[in]yPointer to the discrete-time vector y.
Vector size is [ny x 1].

[in]nySize of vector y.

[in]flagFlag specifies the type of scaling applied to the correlation vector $\breve{r}_{xy}(k)$.
Is one of:
DSPL_XCORR_NOSCALE unscaled correlation vector from IFFT output $\breve{r}_{xy}(k)$;
DSPL_XCORR_BIASED biased correlation vector $\breve{r}_{xy}(k)/N $;
DSPL_XCORR_UNBIASED unbiased correlation vector $\widehat{r}_{xy}(k) = \frac{\breve{r}_{xy}(k)}{N-|k|} $;

[in]nrMaximum correlation lag.
Correlation vector $\widehat{r}_{xy}(k)$ is calculated for $ k= -n_r,\,\, -n_r +1, \ldots n_r$.

[out]rPointer to the cross-correlation or autocorrelation vector.
Vector size is [(2*nr+1) x 1].
Memory must be allocated.

[out]rPointer to the cross-correlation argument vector
$ k= -n_r,\,\, -n_r +1, \ldors n_r$.
Vector size is [(2*nr+1) x 1].
Pointer can be NULL.

Returns
RES_OK if function returns successfully.
Else code error.
Author
Sergey Bakhurin www.dsplib.org

Definition at line 214 of file xcorr.c.

◆ xcorr_cmplx()

int DSPL_API xcorr_cmplx ( complex_t x,
int  nx,
complex_t y,
int  ny,
int  flag,
int  nr,
complex_t r,
double *  t 
)

Estimates the cross-correlation vector for complex discrete-time sequences x and y.


int xcorr_cmplx(complex_t* x, int nx, complex_t* y, int ny, int flag, int nr, complex_t* r, double* t) Estimate the cross correlation $\widehat{r}_{xy}(k)$ of vector arguments x and y or estimate autocorrelation vector if $x = y $.

Cross-correlation vector is defined as:

\[ \widehat{r}_{xy}(k) = \frac{1}{N-k} \sum\limits_{n = 0}^{N-k-1} x(n+k)y^*(n), \qquad 0 \leq k <N; \]

\[ \widehat{r}_{xy}(k) = \frac{1}{N+k} \sum\limits_{n = 0}^{N+k-1} y^*(n-k)x(n), \qquad -N < k < 0. \]

here $ N = \max(n_x, n_y) $.

This function uses the FFT algorithm to estimate the scaled correlation vector:

\[ \breve{r}_{xy}(k) = \operatorname{IFFT}\Big[ \operatorname{FFT}\big[ \mathbf{x} \big] \operatorname{FFT}^*\big[ \mathbf{y} \big] \Big] \]

Parameters
[in]xPointer to the discrete-time vector x.
Vector size is [nx x 1].

[in]nxSize of vector x.

[in]yPointer to the discrete-time vector y.
Vector size is [ny x 1].

[in]nySize of vector y.

[in]flagFlag specifies the type of scaling applied to the correlation vector $\breve{r}_{xy}(k)$.
Is one of:
DSPL_XCORR_NOSCALE unscaled correlation vector from IFFT output $\breve{r}_{xy}(k)$;
DSPL_XCORR_BIASED biased correlation vector $\breve{r}_{xy}(k)/N $;
DSPL_XCORR_UNBIASED unbiased correlation vector $\widehat{r}_{xy}(k) = \frac{\breve{r}_{xy}(k)}{N-|k|} $;

[in]nrMaximum correlation lag.
Correlation vector $\widehat{r}_{xy}(k)$ is calculated for $ k= -n_r,\,\, -n_r +1, \ldots n_r$.

[out]rPointer to the cross-correlation or autocorrelation vector.
Vector size is [(2*nr+1) x 1].
Memory must be allocated.

[out]rPointer to the cross-correlation argument vector
$ k= -n_r,\,\, -n_r +1, \ldors n_r$.
Vector size is [(2*nr+1) x 1].
Pointer can be NULL.

Returns
RES_OK if function returns successfully.
Else code error.
Author
Sergey Bakhurin www.dsplib.org

Definition at line 449 of file xcorr.c.

int DSPL_API find_max_abs(double *a, int n, double *m, int *ind)
Find maximum absolute value from the real vector a
Definition: statistic.c:123