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

How to prepare ADC data for Q31_t CMSIS DSP functions?

Hi to you all,
I've another post on the forum (here's the link Process ADC data, moved by DMA, using CMSIS DSP: what's the right way? ), but since I think I made some small steps forward I felt I could be a little more specific. I hope this won't be a problem.

Actually I'm trying to extract the MAX from a q31_t (Note that: typedef int32_t q31_t) array filled by the ADCHS in my LPC4370 lpc link2 board, using the arm_max_q31 function (here for reference: Maximum).
The problem is that the 12bit ADC supplies data in Two's Complement format, but the library is misunderstanding it (ora at least I think so).
For instance: 

111111111111

Should be

-1

but actually is read by the CMSIS Function as

4095

and therefore is always recognized as the MAX value.

Do I need to manually convert all the samples one-by-one? This seems to be extremely slow, and since I've some real-time requirements I need the fastest way to do this maths.
Any help would be highly appreciated since I'm stuck here.

Thanks,
Andrea

Parents
  • Hello Abet,

    In your example, 4095 would be -1 if you were using a 12 bit data type.  However you are using a 32bit data type (q31_t).  You need to upshift your data to make sense in the q31_t format.  In this case by 20 bits.  y = x << 20.  You might also use q15_t as your input data is only 12 bits anyways, and the q15_t library is sometimes faster than q31_t due to SIMD.  You could use the arm_shift_q15 function to quickly upshift all of your data in one go before calling arm_max_q15.

    I would recommend doing some googling to understand how the q31_t, q15_t, int32_t, int16_t data types all work, as your question implies a degree of unfamiliarity.

    Cheers,

    Dan

Reply
  • Hello Abet,

    In your example, 4095 would be -1 if you were using a 12 bit data type.  However you are using a 32bit data type (q31_t).  You need to upshift your data to make sense in the q31_t format.  In this case by 20 bits.  y = x << 20.  You might also use q15_t as your input data is only 12 bits anyways, and the q15_t library is sometimes faster than q31_t due to SIMD.  You could use the arm_shift_q15 function to quickly upshift all of your data in one go before calling arm_max_q15.

    I would recommend doing some googling to understand how the q31_t, q15_t, int32_t, int16_t data types all work, as your question implies a degree of unfamiliarity.

    Cheers,

    Dan

Children