This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

precision of arm_cmplx_mag_q31()

Hello,

I started to use the CMSIM DSP library and  I have a question regarding the function "arm_cmplx_mag_q31()" that computes the complex magnitude. The function is basically implemented by the code below. Don't we loose about half of the precision by squaring and shifting the intermediate result by 33 bits? If I use the function with small numbers the result is obviously always zero or am I understanding something wrong? Are there any alternative ways in CMSIS to get the magnitude with the same precision as the input values?

/* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */
real = *pSrc++;
imag = *pSrc++;
acc0 = (q31_t) (((q63_t) real * real) >> 33);
acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
/* store the result in 2.30 format in the destination buffer. */
arm_sqrt_q31(acc0 + acc1, pDst++);

        

Regards

Matthias

  • The function might be able to be improved by adding acc0 and acc1 before downshifting all 33 bits  (would have to downshift once or saturate the addition).  Or if a sqrt q63 was written, then the precision could be maintained longer.  I'll look into it, and see if an improved version can make it in a future release.

    You might implement your own q63 sqrt in the mean time if you want to use it in your project