Andes Workshop
http://forum.andestech.com/

Q format
http://forum.andestech.com/viewtopic.php?f=25&t=952
Page 1 of 1

Author:  Tina [ Wed Feb 24, 2016 6:44 pm ]
Post subject:  Q format

以Q15為例:
Q15 也可以直接給 10進制的值。
不過較不建議這樣給,因為會不知道實際的值。
使用者較容易瞭解的寫法如下。
q15_t q15value = 0.12345 * 32768;

因為 DSP library 中Q15 函式的參數也都是 Q15,
所以運算就直接用,不用轉換成float再算。

以Q13為例:
The final format is Q13. It can simply show as (0x4000 * 0x2000 + 0x2000 * 0x1000) >> 17 = 0x500.

Author:  Hubert Chung [ Thu Feb 01, 2018 5:38 pm ]
Post subject:  Re: Q format

q值是介於-1和1之間,小於1,[-1, 1),當使用時,雖說q15當於int16,一般不建議直接給值,因為它相對的值可能會很小,當使用者把這些值放入dsp的運算function中時,常常得到結果為0。所以應以轉換的方式給值,如
q15value = convert_float_to_q15(0.123);
由上式可知q15value的值是0.123

在demo-dsp.tgz中有轉換公式
Code:
static inline q15_t convert_float_to_q15(float x)
{
   q31_t q31;
   q15_t q15;
   x *= 32768.0f;
   x += (x < 0.0f ? -0.5f : 0.5f);
   q31 = (q31_t)x;
   if (q31 >= 32768)
   {
      q15 = INT16_MAX;
   }
   else if (q31 <= -32768)
   {
      q15 = INT16_MIN;
   }
   else
   {
      q15 = (q15_t)q31;
   }
   return q15;
}

Page 1 of 1 All times are UTC + 8 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/