2

I am trying to understand exactly how to do this. I know how fixed point and floating point notations work, but I was wondering how I can convert from int32 to q31 or f32.
If I understand q31 correctly it leaves 31 bits for the fractional part and one bit for the whole part, and f32 is just floating point notation.

I'm trying to figure out how can I efficiently convert between the two?

I am using the ARM CMSIS dsp Library and there are source codes to convert between q31 and f32 but I am receiving the data as int16 or int32. I'm assuming converting from int to floating point is cumbersome in comparison to going from int to fixed point so using ARM's libraries is my best be for speed I'm assuming. That being said if q31 does indeed operate this way (and I'm hoping its signed) could I just say

    q31num=int32;

and leave it at that? any help would be greatly appreciated.

thanks in advance!

-scarlson

scarlso9
  • 195
  • 3
  • 14
  • Can't you simply cast ? – kiwixz Jul 13 '15 at 19:45
  • 1
    To convert an integer to [q31](https://en.wikipedia.org/wiki/Q_(number_format))`, are not values > 1 overflow? Or maybe you want it scaled by some unmentioned value? – chux - Reinstate Monica Jul 13 '15 at 19:51
  • I should add an update that as long as all the values are relative to each other I do not care about their actual values, just the relative values. I am taking in values from an ADC and trying to input them into the ARM CMSIS dsp libraries fft code which operates on either floating or fixed point values only. – scarlso9 Jul 13 '15 at 19:53
  • @iKiWiXz that is what I am wondering. . – scarlso9 Jul 13 '15 at 19:54
  • @chux if I understand q31 notation allows for values up to but not equal to 2 at least for unsigned q31, maybe for signed q31 it does not allow values greater than 1. – scarlso9 Jul 13 '15 at 19:56
  • 1
    What is the implicit scale factor associated with the data you are receiving as `int32_t`? Since the data is received as `int32_t`, a signed type, a reasonable assumption is that the Q1.31 format in question is signed as well, but there is no way for us to know this for sure. – njuffa Jul 13 '15 at 22:45
  • This can help: https://stackoverflow.com/q/71361635/7224685 – mohammadsdtmnd Mar 06 '22 at 04:35

0 Answers0