硬汉嵌入式论坛

 找回密码
 立即注册
查看: 3959|回复: 2
收起左侧

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

[复制链接]

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
发表于 2015-3-25 10:52:23 | 显示全部楼层 |阅读模式
特别说明:完整45期数字信号处理教程,原创高性能示波器代码全开源地址:链接
第14章 SupportFunctions的使用(二)


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

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_t blockSize)
参数定义:
     [in]    *pSrc     points to the Q7 input vector   
    [out]   *pDst    points to the floating-point output vector   
     [in]    blockSize length 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_t blockSize)
参数定义:
    [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_t blockSize)
参数定义:
    [in]   *pSrc      points to the Q7 input vector   
    [out]  *pDst     points to the Q15 output vector   
    [in]    blockSize length of the input vector   

14.1.4 实例讲解

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

程序设计:
  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. q31_t pDst1[10];
  14. q15_t pDst2[10];
  15. q7_t  pSrc[10];
  16. for(pIndex = 0; pIndex < 10; pIndex++)
  17. {
  18. pSrc[pIndex] = rand()%128;
  19. printf("pSrc[%d] = %d\r\n", pIndex, pSrc[pIndex]);
  20. }
  21. /*****************************************************************/
  22. arm_q7_to_float(pSrc, pDst, 10);
  23. for(pIndex = 0; pIndex < 10; pIndex++)
  24. {
  25. printf("arm_q7_to_float: pDst[%d] = %f\r\n", pIndex, pDst[pIndex]);
  26. }
  27. /*****************************************************************/
  28. arm_q7_to_q31(pSrc, pDst1, 10);
  29. for(pIndex = 0; pIndex < 10; pIndex++)
  30. {
  31. printf("arm_q7_to_q31: pDst1[%d] = %d\r\n", pIndex, pDst1[pIndex]);
  32. }
  33. /*****************************************************************/
  34. arm_q7_to_q15(pSrc, pDst2, 10);
  35. for(pIndex = 0; pIndex < 10; pIndex++)
  36. {
  37. printf("arm_q7_to_q15: pDst2[%d] = %d\r\n", pIndex, pDst2[pIndex]);
  38. }
  39. /*****************************************************************/
  40. printf("******************************************************************\r\n");
  41. }
复制代码
14.1.png
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
 楼主| 发表于 2015-3-25 10:54:17 | 显示全部楼层
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_t blockSize)
参数定义:
     [in]    *pSrc     points to the Q15 input vector   
     [out]   *pDst    points to the floating-point output vector   
     [in]    blockSize length 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_t blockSize)
参数定义:
   [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_t blockSize)
参数定义:
    [in]   *pSrc      points to the Q15 input vector   
    [out]  *pDst     points to the Q7 output vector   
    [in]    blockSize length 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. q31_t pDst1[10];
  14. q15_t pSrc[10];
  15. q7_t pDst2[10];
  16. for(pIndex = 0; pIndex < 10; pIndex++)
  17. {
  18. pSrc[pIndex] = rand()%32678;
  19. printf("pSrc[%d] = %drn", pIndex, pSrc[pIndex]);
  20. }
  21. /*****************************************************************/
  22. arm_q15_to_float(pSrc, pDst, 10);
  23. for(pIndex = 0; pIndex < 10; pIndex++)
  24. {
  25. printf("arm_q15_to_float: pDst[%d] = %frn", pIndex, pDst[pIndex]);
  26. }
  27. /*****************************************************************/
  28. arm_q15_to_q31(pSrc, pDst1, 10);
  29. for(pIndex = 0; pIndex < 10; pIndex++)
  30. {
  31. printf("arm_q15_to_q31: pDst1[%d] = %drn", pIndex, pDst1[pIndex]);
  32. }
  33. /*****************************************************************/
  34. arm_q15_to_q7(pSrc, pDst2, 10);
  35. for(pIndex = 0; pIndex < 10; pIndex++)
  36. {
  37. printf("arm_q15_to_q7: pDst2[%d] = %drn", pIndex, pDst2[pIndex]);
  38. }
  39. /*****************************************************************/
  40. printf("******************************************************************rn");
  41. }
复制代码


努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
 楼主| 发表于 2015-3-25 10:55:46 | 显示全部楼层
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_t blockSize)
参数定义:
     [in]   *pSrc      points to the Q31 input vector   
     [out]  *pDst     points to the floating-point output vector   
     [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_t blockSize)
参数定义:
    [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_t blockSize)
参数定义:
    [in]   *pSrc      points to the Q31 input vector   
    [out]  *pDst     points to the Q7 output vector   
    [in]    blockSize length 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. q31_t pSrc[10];
  14. q15_t pDst1[10];
  15. q7_t pDst2[10];
  16. for(pIndex = 0; pIndex < 10; pIndex++)
  17. {
  18. pSrc[pIndex] = rand();
  19. printf("pSrc[%d] = %drn", pIndex, pSrc[pIndex]);
  20. }
  21. /*****************************************************************/
  22. arm_q31_to_float(pSrc, pDst, 10);
  23. for(pIndex = 0; pIndex < 10; pIndex++)
  24. {
  25. printf("arm_q31_to_float: pDst[%d] = %frn", pIndex, pDst[pIndex]);
  26. }
  27. /*****************************************************************/
  28. arm_q31_to_q15(pSrc, pDst1, 10);
  29. for(pIndex = 0; pIndex < 10; pIndex++)
  30. {
  31. printf("arm_q31_to_q15: pDst1[%d] = %drn", pIndex, pDst1[pIndex]);
  32. }
  33. /*****************************************************************/
  34. arm_q31_to_q7(pSrc, pDst2, 10);
  35. for(pIndex = 0; pIndex < 10; pIndex++)
  36. {
  37. printf("arm_q31_to_q7: pDst2[%d] = %drn", pIndex, pDst2[pIndex]);
  38. }
  39. /*****************************************************************/
  40. printf("******************************************************************rn");
  41. }
复制代码


14.4 总结


    本期教程就跟大家讲这么多,有兴趣的可以深入研究这些函数源码的实现。
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-4 15:53 , Processed in 0.165509 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表