简体   繁体   English

Q7 到 Q15 转换

[英]Q7 to Q15 conversion

I want to convert number in Q7 format to number in Q15 format using function available in CMSIS Library (void arm_q7_to_q15).我想使用 CMSIS 库中可用的 function (void arm_q7_to_q15) 将 Q7 格式的数字转换为 Q15 格式的数字。 Here is the beginning of this function:这是这个 function 的开头:

/**    
 * @brief Converts the elements of the Q7 vector to Q15 vector.    
 * @param[in]       *pSrc points to the Q7 input vector    
 * @param[out]      *pDst points to the Q15 output vector   
 * @param[in]       blockSize length of the input vector    
 * @return none.    
*/

void arm_q7_to_q15(
  q7_t * pSrc,
  q15_t * pDst,
  uint32_t blockSize)

I don't know how to define variables for this function. I'd tried to define them like this:我不知道如何为这个 function 定义变量。我试过这样定义它们:

q7_t a = 0.78125; //what number should I define here 0.78125 or 01100100 (in q7)?
q15_t b;
uint32_t bs; //bs=? what number should I define here?

My main function:我的主function:

int main (void)
{
arm_q7_to_q15(a,b,bs);
}

Thank you for helping me.感谢你们对我的帮助。

Pointer to psrc must be a vector of size bs by type q7 .指向 psrc 的指针必须是类型为q7的大小为bs的向量。 (exactly is q7_t a[bs] ) bs must be unsigned 32 bit integer. What sholud be a ? (恰好是q7_t a[bs]bs必须是无符号的 32 位 integer。a 应该a什么? This must be between -1 to 1, since it have only one bit just for sign.这必须在 -1 到 1 之间,因为它只有一位用于符号。 and its precision <7> indicate It's absolute minimum value is 1/(2^7).其精度 <7> 表示它的绝对最小值为 1/(2^7)。

It mean's a=1 will consequence in q7 a become actually 1/(2^7).这意味着 a=1 将导致 q7 a实际上变为 1/(2^7)。

Stored decimal->  Stored bin  ->fractional

a=1           -> `0b00000001` -> 1/(2^7)=0.0078125

a=2           -> `0b00000010` -> 2/(2^7)

a=3           -> `0b00000011` -> 3/(2^7)

...

a=n           -> `0b00000000` -> n/(2^7)

a=128         -> `0b01111111` -> (128/(2^7))=1

And your must not exceed 2^7 you can test what will and q7_t is in compiler known by int8_t.而且你不能超过 2^7 你可以测试 int8_t 已知的编译器中的 will 和 q7_t。 Because of this you can estimate what will hppen if a exceed 2^7.因此,您可以估计如果超过 2^7 会发生什么。 And since 1 of 8 bit's assigned to sign.并且由于 8 位中的 1 位被分配给符号。 The fraction presicion become 7. And it called Q1.7 and Q7 for shorthand.小数精度变为7,简称为Q1.7、Q7。 (1 in Q is part for sign and integer value) (Q中的1是符号部分和integer值)

If you want to convert your data you must first convert to float (using cast or mathematical operation between float varibales) then convert them to Q by support function. And note float number can be even larger than one, the float are scientific view on number in base of two, x*2^f, memory have three part s,x,f and s is sign.如果你想转换你的数据,你必须首先转换为浮点数(在浮点变量之间使用强制转换或数学运算)然后通过支持 function 将它们转换为 Q。注意浮点数甚至可以大于一,浮点数是数字的科学观点以二为底,x*2^f, memory 有三部分 s,x,f 并且 s 是符号。 Other note is that Q's are always round to floor!(as I've perceived)另一个注意事项是 Q 总是圆到地板!(正如我所感知的那样)

There is a good example for better understanding:有一个很好的例子可以更好地理解:

  float32_t arrf[6]={0.01,0.1,1,10,100,1000};
  float32_t arrf2[6];
  q15_t     arrq[6]={1,10,100,1000,10000,
          0b0111111111111111/*32767*/};
  q15_t     arrq2[6];
  q15_t     arrq3[6];
  q15_t     arrq4[6];
  q15_t     arrq5[6];
  q15_t     arrq6[6];

  uint16_t  arru[6]={0};

  arm_scale_f32(arrf,0.7,arrf2,6);
  arm_scale_q15(arrq,1024,0,arrq2,6);
  arm_scale_q15(arrq,1,15,arrq3,6);
  arm_scale_q15(arrq,4000,0,arrq4,6);
  arm_scale_q15(arrq,8000,0,arrq5,6);
  arm_scale_q15(arrq,32767,0,arrq6,6);

Answer:回答:

arrf2= 0.00699999975,0.0700000003,0.699999988,7,70.700 arrq2= 0,0,3,31,312,1023 arrq3= 1,10,100,1000,10000,32767 arrq4= 0,1,12,122,1220,3999 arrq5= 0,2,24,244,2441,7999 arrq6= 0,9,99,999,9999,32766 arrf2= 0.00699999975,0.0700000003,0.699999988,7,70.700 arrq2= 0,0,3,31,312,1023 arrq3= 1,10,100,1000,10000,32767 arrq4= 0,1,12,120,122,925,922 24,244,2441,7999 arrq6= 0,9,99,999,9999,32766

And it's important to know:重要的是要知道: q7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM