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

CMSIS DSP Library

Note: This was originally posted on 27th November 2012 at http://forums.arm.com

Hi,

I am new user to CMSIS. I have gone through the DSP library function. I am interested in fixed point arithemetic.

As per the documentation, i have understood that Q7, Q15 and Q31 formats are only supported. Is that correct ?


I would like to multiply different Q formats. Example : For multiplication, input 1 is Q17, input2 is Q 27 and output required is Q19.

How can we use the DSP library functions such as arm_mult_q31 for the example mentioned ?
  • Note: This was originally posted on 27th November 2012 at http://forums.arm.com

    Why do you want to mix and match lots of Q formats?

    Because you always end up doing format conversion you pretty rapidly accumulate error, so it's not entirely sure what you hope to achieve.

    The Q7, Q15, and Q31 formats are chosen because they always encode a value between -1 and 1. Q7 is encoded in a byte value, Q15 as a short, and Q32 as a long. In each case you get N-1 fractional bits plus a single integer bit (effectively only acting as a 2's complement sign bit for these formats), so the only difference is effective precision of the fractional part.

    The advantage of this approach is that if you multiply two numbers together there is little normalization to do (you are guaranteed to only get one integer bit out). As soon as you allow multiple integer bits then you need to rescale the inputs and outputs (worst case in a format with N integer bits you get 2N integer bits in the output), and you start accumulating error and generating values you cannot actually legally encode in your format. This is very hard to encapsulate in any library, and is often the "wrong solution" because it has so many corner cases.

    HTH,
    Iso
  • Note: This was originally posted on 28th November 2012 at http://forums.arm.com

    I agree with your comments.

    But in previous, we worked with IQmath library provided by TI. This IQ math library allows the user to multiply different Q formats and allows takes about rounding and saturation of the result.

    My question whether this CMSIS DSP libarary provides the same capabilities as IQmath ?
  • Note: This was originally posted on 28th November 2012 at http://forums.arm.com


    I agree with your comments.

    But in previous, we worked with IQmath library provided by TI. This IQ math library allows the user to multiply different Q formats and allows takes about rounding and saturation of the result.

    My question whether this CMSIS DSP libarary provides the same capabilities as IQmath ?



    Hi Jags,
    The CMSIS DSP library has been optimized using the underlying data types that are supported by the Cortex-M4 (8-bit, 16-bit, and 32-bit integers as well as floating-point).  This gives the best execution time.  The CMSIS library is quite a bit higher in level than the IQMath library and provides functions like FFTs, filters, matrix operations, etc.  The CMSIS functions typically operate on blocks of data.  If you are looking to do low-level math operations, like individual multiplications and additions, then you're best off defining your own macros which perform the operation and do the shifting necessary to mix different Q data types.

    That said, it is possible to use the CMSIS functions to perform mixed Q arithmetic.  You just need to keep in mind exactly which Q formats are used and do additional shifting, as needed.  In your example of multiplying Q17 by Q27 to yield a Q19 result I would approach as follows:

    Let A represent the vector of Q17 values.  Each value is 18 bits and you should place them into the high 18 bits of a 32-bit word. 
    Similarly let B represent the Q27 input data.  Each value is 28 bits and you should place them into the high 28 bits of a 32-bit word.
    Then perform a Q31 multiplication using the function arm_mult_q31().  This will generated a Q31 result.  If you want a Q19 output then you should take the high 20-bits of the result.

    Would this work?