STM32/STM8技术论坛
直播中

硬汉Eric2013

9年用户 1035经验值
擅长:嵌入式技术
私信 关注
[经验]

【安富莱——DSP教程】第14章 SupportFunctions的使用(二)

第14章  SupportFunctions的使用(二)
    本期教程主要讲解支持函数中的Q7,Q15和Q31分别向其它类型数据转换。
    14.1 定点数Q7转换
    14.2 定点数Q15转换
    14.3 定点数Q31转换
    14.4 总结

回帖(4)

硬汉Eric2013

2015-6-12 11:33:07
14.1  定点数Q7转换
14.1.1  arm_q7_to_float
公式描述:
    pDst[n] = (float32_t) pSrc[n] / 128;   0 <= n < blockSize.   
函数定义如下:
    void arm_q7_to_float(q7_t * pSrc, float32_t * pDst, uint32_tblockSize)
参数定义:
     [in]    *pSrc     points to the Q7 input vector   
     [out]   *pDst    points to the floating-point outputvector   
     [in]     blockSizelength of the input vector   

14.1.2  arm_q7_to_q31
公式描述:
    pDst[n] = (q31_t) pSrc[n] << 24;   0 <= n < blockSize.   
函数定义如下:
    void arm_q7_to_q31(q7_t * pSrc, q31_t * pDst, uint32_tblockSize)
参数定义:
    [in]    *pSrc     points to the Q7 input vector   
    [out]   *pDst    points to the Q31 output vector   
    [in]    blockSize  length of the input vector   

14.1.3  arm_q7_to_q15
公式描述:
     pDst[n] = (q15_t) pSrc[n] << 8;   0 <= n < blockSize.   
函数定义如下:
    void arm_q7_to_q15(q7_t * pSrc, q15_t * pDst, uint32_tblockSize)
参数定义:
    [in]   *pSrc      points to the Q7 input vector   
    [out]  *pDst     points to the Q15 output vector   
    [in]    blockSizelength of the input vector   

14.1.4  实例讲解
实验目的:
    1. 学习SupportFunctions中Q7格式数据的转换
实验内容:
           1. 按下按键K1, 串口打印函数DSP_Q7的输出结果
实验现象:
           通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下:
14.1.png

程序设计:
  1. /*
  2. *********************************************************************************************************
  3. *    函 数 名: DSP_Q7
  4. *    功能说明: Q7格式数据向其它格式转换
  5. *    形    参:无
  6. *    返 回 值: 无
  7. *********************************************************************************************************
  8. */
  9. static void DSP_Q7(void)
  10. {
  11.      float32_t pDst[10];
  12.      uint32_t pIndex;
  13.    
  14.      q31_t pDst1[10];
  15.      q15_t pDst2[10];
  16.      q7_t  pSrc[10];
  17.    
  18.      for(pIndex = 0; pIndex < 10; pIndex++)
  19.      {
  20.          pSrc[pIndex] = rand()%128;
  21.          printf("pSrc[%d] = %drn", pIndex, pSrc[pIndex]);
  22.      }
  23.    
  24.      /*****************************************************************/
  25.      arm_q7_to_float(pSrc, pDst, 10);
  26.      for(pIndex = 0; pIndex < 10; pIndex++)
  27.      {
  28.          printf("arm_q7_to_float: pDst[%d] = %frn", pIndex, pDst[pIndex]);
  29.      }

  30.      /*****************************************************************/
  31.      arm_q7_to_q31(pSrc, pDst1, 10);
  32.      for(pIndex = 0; pIndex < 10; pIndex++)
  33.      {
  34.          printf("arm_q7_to_q31: pDst1[%d] = %drn", pIndex, pDst1[pIndex]);
  35.      }
  36.    
  37.      /*****************************************************************/
  38.      arm_q7_to_q15(pSrc, pDst2, 10);
  39.      for(pIndex = 0; pIndex < 10; pIndex++)
  40.      {
  41.          printf("arm_q7_to_q15: pDst2[%d] = %drn", pIndex, pDst2[pIndex]);
  42.      }
  43.    
  44.      /*****************************************************************/
  45.      printf("******************************************************************rn");
  46. }

举报

硬汉Eric2013

2015-6-12 11:35:00
14.2  定点数Q15转换
14.2.1  arm_q15_to_float
公式描述:
    pDst[n] = (float32_t) pSrc[n] / 32768;   0 <= n < blockSize.   
函数定义如下:
    void arm_q15_to_float(q15_t * pSrc, float32_t * pDst, uint32_tblockSize)
参数定义:
     [in]    *pSrc     points to the Q15 input vector   
     [out]   *pDst    points to the floating-point outputvector   
     [in]     blockSizelength of the input vector   

14.2.2  arm_q15_to_q31
公式描述:
    pDst[n] = (q31_t) pSrc[n] << 16;   0 <= n < blockSize.  
函数定义如下:
    void arm_q15_to_q31(q15_t * pSrc, q31_t * pDst, uint32_tblockSize)
参数定义:
    [in]    *pSrc     points to the Q15 input vector   
    [out]   *pDst    points to the Q31 output vector   
    [in]    blockSize  length of the input vector   

14.2.3  arm_q15_to_q7
公式描述:
    pDst[n] = (q7_t) pSrc[n] >> 8;   0 <= n < blockSize.  
函数定义如下:
    void arm_q7_to_q15(q7_t * pSrc, q15_t * pDst, uint32_tblockSize)
参数定义:
    [in]   *pSrc      points to the Q15 input vector   
    [out]  *pDst     points to the Q7 output vector   
    [in]    blockSizelength of the input vector   

14.2.4  实例讲解
实验目的:
    1. 学习SupportFunctions中Q15格式数据的转换
实验内容:
           1. 按下按键K1, 串口打印函数DSP_Q7的输出结果
实验现象:
           通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下:
14.2.png

程序设计:
  1. /*
  2. *********************************************************************************************************
  3. *    函 数 名: DSP_Q15
  4. *    功能说明: Q15格式数据向其它格式转换
  5. *    形    参:无
  6. *    返 回 值: 无
  7. *********************************************************************************************************
  8. */
  9. static void DSP_Q15(void)
  10. {
  11.      float32_t pDst[10];
  12.      uint32_t pIndex;
  13.    
  14.      q31_t pDst1[10];
  15.      q15_t pSrc[10];
  16.      q7_t  pDst2[10];
  17.    
  18.      for(pIndex = 0; pIndex < 10; pIndex++)
  19.      {
  20.          pSrc[pIndex] = rand()%32678;
  21.          printf("pSrc[%d] = %drn", pIndex, pSrc[pIndex]);
  22.      }
  23.    
  24.      /*****************************************************************/
  25.      arm_q15_to_float(pSrc, pDst, 10);
  26.      for(pIndex = 0; pIndex < 10; pIndex++)
  27.      {
  28.          printf("arm_q15_to_float: pDst[%d] = %frn", pIndex, pDst[pIndex]);
  29.      }

  30.      /*****************************************************************/
  31.      arm_q15_to_q31(pSrc, pDst1, 10);
  32.      for(pIndex = 0; pIndex < 10; pIndex++)
  33.      {
  34.          printf("arm_q15_to_q31: pDst1[%d] = %drn", pIndex, pDst1[pIndex]);
  35.      }
  36.    
  37.      /*****************************************************************/
  38.      arm_q15_to_q7(pSrc, pDst2, 10);
  39.      for(pIndex = 0; pIndex < 10; pIndex++)
  40.      {
  41.          printf("arm_q15_to_q7: pDst2[%d] = %drn", pIndex, pDst2[pIndex]);
  42.      }
  43.    
  44.      /*****************************************************************/
  45.      printf("******************************************************************rn");
  46. }

举报

硬汉Eric2013

2015-6-12 11:37:02
14.3  定点数Q31转换
14.3.1  arm_q31_to_float
公式描述:
    pDst[n] = (float32_t) pSrc[n] / 2147483648;   0 <= n < blockSize.   
函数定义如下:
    void arm_q31_to_float(q31_t * pSrc, float32_t * pDst, uint32_tblockSize)
参数定义:
      [in]   *pSrc      points to the Q31 input vector   
      [out]  *pDst     points to the floating-point outputvector   
     [in]   blockSize  length of the input vector   

   
14.3.2  arm_q31_to_q15
公式描述:
    pDst[n] = (q15_t) pSrc[n] >> 16;   0 <= n < blockSize.   
函数定义如下:
    void arm_q31_to_q15(q31_t * pSrc, q15_t * pDst, uint32_tblockSize)
参数定义:
    [in]    *pSrc     points to the Q31 input vector   
    [out]   *pDst    points to the Q15 output vector   
    [in]    blockSize  length of the input vector   

14.3.3  arm_q31_to_q7
公式描述:
    pDst[n] = (q7_t) pSrc[n] >> 24;   0 <= n < blockSize.     
函数定义如下:
    void arm_q31_to_q7(q31_t * pSrc, q7_t * pDst, uint32_tblockSize)
参数定义:
    [in]   *pSrc      points to the Q31 input vector   
    [out]  *pDst     points to the Q7 output vector   
    [in]    blockSizelength of the input vector   

14.3.4  实例讲解
实验目的:
    1. 学习SupportFunctions中Q31格式数据的转换
实验内容:
           1. 按下按键K1, 串口打印函数DSP_Q31的输出结果
实验现象:
           通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下:
14.3.png

程序设计:
  1. /*
  2. *********************************************************************************************************
  3. *    函 数 名: DSP_Q31
  4. *    功能说明: Q31格式数据向其它格式转换
  5. *    形    参:无
  6. *    返 回 值: 无
  7. *********************************************************************************************************
  8. */
  9. static void DSP_Q31(void)
  10. {
  11.      float32_t pDst[10];
  12.      uint32_t pIndex;
  13.    
  14.      q31_t pSrc[10];
  15.      q15_t pDst1[10];
  16.      q7_t  pDst2[10];
  17.    
  18.      for(pIndex = 0; pIndex < 10; pIndex++)
  19.      {
  20.          pSrc[pIndex] = rand();
  21.          printf("pSrc[%d] = %drn", pIndex, pSrc[pIndex]);
  22.      }
  23.    
  24.      /*****************************************************************/
  25.      arm_q31_to_float(pSrc, pDst, 10);
  26.      for(pIndex = 0; pIndex < 10; pIndex++)
  27.      {
  28.          printf("arm_q31_to_float: pDst[%d] = %frn", pIndex, pDst[pIndex]);
  29.      }

  30.      /*****************************************************************/
  31.      arm_q31_to_q15(pSrc, pDst1, 10);
  32.      for(pIndex = 0; pIndex < 10; pIndex++)
  33.      {
  34.          printf("arm_q31_to_q15: pDst1[%d] = %drn", pIndex, pDst1[pIndex]);
  35.      }
  36.    
  37.      /*****************************************************************/
  38.      arm_q31_to_q7(pSrc, pDst2, 10);
  39.      for(pIndex = 0; pIndex < 10; pIndex++)
  40.      {
  41.          printf("arm_q31_to_q7: pDst2[%d] = %drn", pIndex, pDst2[pIndex]);
  42.      }
  43.    
  44.      /*****************************************************************/
  45.      printf("******************************************************************rn");
  46. }

举报

硬汉Eric2013

2015-6-12 11:37:26
14.4        总结
本期教程就跟大家讲这么多,有兴趣的可以深入研究这些函数源码的实现。

举报

更多回帖

发帖
×
20
完善资料,
赚取积分