Logo
MSP DSP Library
Complex Numbers

Complex numbers are represented as pairs of consecutive data where the even indices are the real inputs and the odd indices are the imaginary inputs. The length passed to complex DSPLib functions is the number of complex data pairs, meaning the functions assume twice the length has been allocated for complex data storage. An example of how complex data arrays can be allocated and referenced using some of the available macros is below.

// Complex vector length
#define CMPLX_VECTOR_LENGTH 64
// Complex data arrays
_q15 src[CMPLX_VECTOR_LENGTH*2];
_q15 dst[CMPLX_VECTOR_LENGTH*2];
void myFunction(void)
{
_q15 *srcPtr;
uint16_t length;
msp_status status;
// Initialize source
srcPtr = src;
length = CMPLX_VECTOR_LENGTH;
while (length--) {
CMPLX_REAL(srcPtr) = 0;
CMPLX_IMAG(srcPtr) = 0;
srcPtr += CMPLX_INCREMENT;
}
// Complex add: dst = src + src;
params.length = CMPLX_VECTOR_LENGTH;
status = msp_cmplx_add_q15(&params, src, src, dst);
return;
}

For a more detailed look at working with complex numbers please see the following code examples that use complex data types.