libdspl-2.0
Digital Signal Processing Algorithm Library
DSPL-2.0 data types.

This group describes DSPL-2.0 data types and functions and macros for data types conversion. More...

Macros

#define RE(x)   (x[0])
 Macro sets real part of the complex number. More...
 
#define IM(x)   (x[1])
 Macro sets imaginary part of the complex number. More...
 
#define ABSSQR(x)   ((SQR(RE(x))) + (SQR(IM(x))))
 The macro returns the square of the modulus of a complex number x. More...
 

Typedefs

typedef double complex_t[2]
 Complex data type. More...
 

Functions

int DSPL_API cmplx2re (complex_t *x, int n, double *re, double *im)
 Separate complex vector to the real and image vectors. More...
 
int DSPL_API re2cmplx (double *x, int n, complex_t *y)
 Convert real array to the complex array. More...
 

Detailed Description

This group describes DSPL-2.0 data types and functions and macros for data types conversion.

Macro Definition Documentation

◆ ABSSQR

#define ABSSQR (   x)    ((SQR(RE(x))) + (SQR(IM(x))))

The macro returns the square of the modulus of a complex number x.


Square of the modulus of a complex number $ x = a + j b $ equals:

\[ |x|^2 = x x^* = a^2 + b^2. \]

Example:

double y;
RE(z) = 1.0;
IM(z) = -2.0;
y = ABSSQR(z);

Variable z = 1-2j, here j - imaginary unit, but variable y = 5.

Definition at line 474 of file dspl.h.

◆ IM

#define IM (   x)    (x[1])

Macro sets imaginary part of the complex number.


Example:

RE(z) = 1.0;
IM(z) = -2.0;

Variable z = 1-2j, here j - imaginary unit.

This macro can be used to return imaginary part of the complex number:

complex_t z = {3.0, -4.0};
double r;
r = IM(z);

In this example z = 3-4i, but variable r will keep -4.

Definition at line 418 of file dspl.h.

◆ RE

#define RE (   x)    (x[0])

Macro sets real part of the complex number.


Example:

RE(z) = 1.0;
IM(z) = -2.0;

Variable z = 1-2j, here j - imaginary unit.

This macro can be used to return real part of the complex number:

complex_t z = {3.0, -4.0};
double r;
r = RE(z);

In this example z = 3-4i, but variable r will keep 3.

Definition at line 360 of file dspl.h.

Typedef Documentation

◆ complex_t

complex_t

Complex data type.


libdspl-2.0 describes complex numbers data type as an array of two double elements. First element sets real part, second — imaginary part.

For example:

z[0] = 1.0;
z[1] = -2.0;

Variable z = 1-2j, here j - imaginary unit.

For the convenience of working with complex numbers implemented special macros: RE, IM, ABSSQR

Definition at line 86 of file dspl.h.

Function Documentation

◆ cmplx2re()

int cmplx2re ( complex_t x,
int  n,
double *  re,
double *  im 
)

Separate complex vector to the real and image vectors.


Function fills re and im vectors corresponds to real and image parts of the input complex array x.

Parameters
[in]x
Pointer to the real complex vector.
Vector size is [n x 1].

[in]n
Size of the input complex vector x and real and image vectors re and im.

[out]re
Pointer to the real part vector.
Vector size is [n x 1].
Memory must be allocated.

[out]im
Pointer to the image part vector.
Vector size is [n x 1].
Memory must be allocated.

Returns
RES_OK if function converts complex vector successfully.
Else code error.
Example:
complex_t x[3] = {{1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}};
double re[3], im[3];
cmplx2re(x, 3, re, im);

Vectors re and im will contains:

re[0] = 1.0; im[0] = 2.0;
re[1] = 3.0; im[1] = 4.0;
re[2] = 5.0; im[2] = 6.0;
Author
Sergey Bakhurin. www.dsplib.org

Definition at line 130 of file complex.c.

Referenced by conv_fft(), and xcorr().

◆ re2cmplx()

int re2cmplx ( double *  x,
int  n,
complex_t y 
)

Convert real array to the complex array.


Function copies the vector x to the real part of vector y. Image part of the vector y sets as zero.
So complex vector contains data:
y[i] = x[i] + j0, here i = 0,1,2 ... n-1

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

[in]nSize of the real vector x and complex vector y.

[out]yPointer to the complex vector y.
Vector size is [n x 1].
Memory must be allocated.

Returns
RES_OK if function returns successfully.
Else code error:
Example:
double x[3] = {1.0, 2.0, 3.0};
complex_t y[3];
re2cmplx(x, 3, y);

Vector y will keep:

    y[0] = 1+0j;
    y[1] = 2+0j;
    y[2] = 3+0j.
Author
Sergey Bakhurin. www.dsplib.org

Definition at line 246 of file complex.c.

Referenced by conv_fft(), fft(), freqs(), freqz(), and xcorr().

#define RE(x)
Macro sets real part of the complex number.
Definition: dspl.h:359
int DSPL_API re2cmplx(double *x, int n, complex_t *y)
Convert real array to the complex array.
Definition: complex.c:246
int DSPL_API cmplx2re(complex_t *x, int n, double *re, double *im)
Separate complex vector to the real and image vectors.
Definition: complex.c:130
double complex_t[2]
Complex data type.
Definition: dspl.h:86
#define ABSSQR(x)
The macro returns the square of the modulus of a complex number x.
Definition: dspl.h:473
#define IM(x)
Macro sets imaginary part of the complex number.
Definition: dspl.h:417