I continue the ARM CMSIS DSP series, this time demonstrating arm_sqrt_q15. This function takes the sqrt of a fractional input, and returns the value (by reference) and some error detection. Here is the function definition:

arm_status arm_sqrt_q15(q15_t in, q15_t * pOut)

“in” really is a Q Format of 1.15. 0 is represented as 0x0000. 1 is represented as 0x7FFF. This means that 1/2 is represented as 0x4000. The returned value is a status, ARM_MATH_SUCCESS or ARM_MATH_ARGUMENT_ERROR, self descriptive. The other returned value by reference is the result of the operation, pOut. This is also a 1.15 formatted number. Note that when taking the square root a fraction, the number should always be larger, but never greater than 1.0. Here is an example:

arm_sqrt_q15(0x4000,&jj);

1/2 is represented as 0x4000. sqrt(1/2) is approximately 0.707. The function returns 0x5A82 = 23170 / 2^15 = 0.707.

Success!

That concludes this quick example of ARM’s function arm_sqrt_q15. Here is the link to ARM’s library. Also, here is some documentation [pdf] for TI’s processors helpful in understanding their functions which translated to ARM’s.