Andes Workshop

It is currently Sun Oct 13, 2024 2:52 am

All times are UTC + 8 hours [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Q format
PostPosted: Wed Feb 24, 2016 6:44 pm 
Offline

Joined: Thu Jan 07, 2016 12:28 pm
Posts: 5
以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.


Top
 Profile Send private message E-mail  
 
 Post subject: Re: Q format
PostPosted: Thu Feb 01, 2018 5:38 pm 
Offline

Joined: Mon Dec 12, 2016 5:07 pm
Posts: 18
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;
}


Top
 Profile Send private message E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group