你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

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

[复制链接]
baiyongbin2009 发布时间:2015-3-24 11:08
本帖最后由 baiyongbin2009 于 2015-3-24 11:13 编辑

特别说明:完整45期数字信号处理教程,原创高性能示波器代码全开源地址:链接
第13章 SupportFunctions的使用(一)

    本期教程主要讲解支持函数中的数据拷贝,数据赋值和浮点数转换为定点数。
    13.1 数据拷贝 Copy
    13.2 数据填充 Fill
    13.3 浮点数转定点数 Float to Fix
    13.4 总结

13.1 数据拷贝Copy
这部分函数用于数据拷贝,公式描述如下:
    pDst[n] = pSrc[n];   0 <= n < blockSize.   
13.1.1 arm_copy_f32
函数定义如下:
    void arm_copy_f32(float32_t * pSrc, float32_t * pDst, uint32_t blockSize)
参数定义:
    [in]   *pSrc     points to input vector   
    [out]  *pDst    points to output vector   
    [in]   blockSize length of the input vector   
13.1.2 arm_copy_q31
此函数的使用比较简单,函数定义如下:
    void arm_copy_q31(q31_t * pSrc, q31_t * pDst, uint32_t blockSize)
参数定义:
     [in]   *pSrc     points to input vector   
     [out]  *pDst    points to output vector   
     [in]   blockSize length of the input vector         
13.1.3 arm_copy_q15
函数定义如下:
    void arm_copy_q15(q15_t * pSrc, q15_t * pDst, uint32_t blockSize)
参数定义:
      [in]   *pSrc     points to input vector   
      [out]  *pDst    points to output vector   
      [in]   blockSize length of the input vector  
13.1.4 arm_copy_q7
函数定义如下:
    void arm_copy_q7(q7_t * pSrc, 7_t * pDst, int32_t blockSize)
参数定义:
     [in]   *pSrc     points to input vector   
     [out]  *pDst    points to output vector   
     [in]   blockSize length of the input vector         
13.1.5 实例讲解
实验目的:
    1. 学习SupportFunctions中的数据拷贝
实验内容:
    1. 按下按键K1, 串口打印函数DSP_Copy的输出结果
实验现象:
    通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下:
13.1.png
程序设计:
  1. /*
  2. *********************************************************************************************************
  3. *        函 数 名: DSP_Copy
  4. *        功能说明: 数据拷贝
  5. *        形    参:无
  6. *        返 回 值: 无
  7. *********************************************************************************************************
  8. */
  9. static void DSP_Copy(void)
  10. {
  11. float32_t pSrc[10] = {0.6557,  0.0357,  0.8491,  0.9340, 0.6787,  0.7577,  0.7431,  0.3922,  0.6555,  0.1712};
  12. float32_t pDst[10];
  13. uint32_t pIndex;
  14. q31_t pSrc1[10];
  15. q31_t pDst1[10];
  16. q15_t pSrc2[10];
  17. q15_t pDst2[10];
  18. q7_t pSrc3[10];
  19. q7_t pDst3[10];
  20. for(pIndex = 0; pIndex < 10; pIndex++)
  21. {
  22. printf("pSrc[%d] = %f\r\n", pIndex, pSrc[pIndex]);
  23. }
  24. arm_copy_f32(pSrc, pDst, 10);
  25. for(pIndex = 0; pIndex < 10; pIndex++)
  26. {
  27. printf("arm_copy_f32: pDst[%d] = %f\r\n", pIndex, pDst[pIndex]);
  28. }

  29. /*****************************************************************/
  30. for(pIndex = 0; pIndex < 10; pIndex++)
  31. {
  32. pSrc1[pIndex] = rand();
  33. printf("pSrc1[%d] = %d\r\n", pIndex, pSrc1[pIndex]);
  34. }
  35. arm_copy_q31(pSrc1, pDst1, 10);
  36. for(pIndex = 0; pIndex < 10; pIndex++)
  37. {
  38. printf("arm_copy_q31: pDst1[%d] = %d\r\n", pIndex, pDst1[pIndex]);
  39. }
  40. /*****************************************************************/
  41. for(pIndex = 0; pIndex < 10; pIndex++)
  42. {
  43. pSrc2[pIndex] = rand()%32768;
  44. printf("pSrc2[%d] = %d\r\n", pIndex, pSrc2[pIndex]);
  45. }
  46. arm_copy_q15(pSrc2, pDst2, 10);
  47. for(pIndex = 0; pIndex < 10; pIndex++)
  48. {
  49. printf("arm_copy_q15: pDst2[%d] = %d\r\n", pIndex, pDst2[pIndex]);
  50. }
  51. /*****************************************************************/
  52. for(pIndex = 0; pIndex < 10; pIndex++)
  53. {
  54. pSrc3[pIndex] = rand()%128;
  55. printf("pSrc3[%d] = %d\r\n", pIndex, pSrc3[pIndex]);
  56. }
  57. arm_copy_q7(pSrc3, pDst3, 10);
  58. for(pIndex = 0; pIndex < 10; pIndex++)
  59. {
  60. printf("arm_copy_q7: pDst3[%d] = %d\r\n", pIndex, pDst3[pIndex]);
  61. }
  62. /*****************************************************************/
  63. printf("******************************************************************\r\n");
  64. }
复制代码


收藏 评论5 发布时间:2015-3-24 11:08

举报

5个回答
baiyongbin2009 回答时间:2015-3-24 11:11:05
13.2 数据填充Fill
这部分函数用于数据填充,公式描述如下:
    pDst[n] = value;   0 <= n < blockSize.  
13.2.1 arm_fill_f32
函数定义如下:
    void arm_fill_f32(float32_t value, float32_t * pDst, uint32_t blockSize)
参数定义:
     [in]       value input value to be filled   
     [out]      *pDst points to output vector   
     [in]       blockSize length of the output vector   
13.2.2 arm_fill_q31
此函数的使用比较简单,函数定义如下:
    void arm_fill_q31(q31_t value, q31_t * pDst, uint32_t blockSize)
参数定义:
     [in]       value input value to be filled   
     [out]      *pDst points to output vector   
     [in]       blockSize length of the output vector   

13.2.3 arm_fill_q15
函数定义如下:
    void arm_fill_q15(q15_t value, q15_t * pDst, uint32_t blockSize)
参数定义:
     [in]       value input value to be filled   
     [out]      *pDst points to output vector   
     [in]       blockSize length of the output vector   

13.2.4 arm_fill_q7
函数定义如下:
    void arm_fill_q7(q7_t value, q7_t * pDst, uint32_t blockSize)
参数定义:
     [in]       value input value to be filled   
     [out]      *pDst points to output vector   
     [in]       blockSize length of the output vector   

13.2.5 实例讲解
实验目的:
    1. 学习SupportFunctions中的数据填充
实验内容:
    1. 按下按键K2, 串口打印函数DSP_Fill的输出结果
实验现象:
    通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下:
13.2.png
程序设计:
  1. /*
  2. *********************************************************************************************************
  3. *        函 数 名: DSP_Fill
  4. *        功能说明: 数据填充
  5. *        形 参:无
  6. *        返 回 值: 无
  7. *********************************************************************************************************
  8. */
  9. static void DSP_Fill(void)
  10. {
  11. float32_t pDst[10];
  12. uint32_t pIndex;
  13. q31_t pDst1[10];
  14. q15_t pDst2[10];
  15. q7_t pDst3[10];

  16. arm_fill_f32(3.33f, pDst, 10);
  17. for(pIndex = 0; pIndex < 10; pIndex++)
  18. {
  19. printf("arm_fill_f32: pDst[%d] = %f\r\n", pIndex, pDst[pIndex]);
  20. }

  21. /*****************************************************************/
  22. arm_fill_q31(0x11111111, pDst1, 10);
  23. for(pIndex = 0; pIndex < 10; pIndex++)
  24. {
  25. printf("arm_fill_q31: pDst1[%d] = %x\r\n", pIndex, pDst1[pIndex]);
  26. }
  27. /*****************************************************************/
  28. arm_fill_q15(0x1111, pDst2, 10);
  29. for(pIndex = 0; pIndex < 10; pIndex++)
  30. {
  31. printf("arm_fill_q15: pDst2[%d] = %x\r\n", pIndex, pDst2[pIndex]);
  32. }
  33. /*****************************************************************/
  34. arm_fill_q7(0x11, pDst3, 10);
  35. for(pIndex = 0; pIndex < 10; pIndex++)
  36. {
  37. printf("arm_fill_q7: pDst3[%d] = %x\r\n", pIndex, pDst3[pIndex]);
  38. }
  39. /*****************************************************************/
  40. printf("******************************************************************\r\n");
  41. }
复制代码


baiyongbin2009 回答时间:2015-3-24 11:12:38
13.3 浮点数转定点数Float to Fix 13.3.1 arm_float_to_q31
公式描述:
    pDst[n] = (q31_t)(pSrc[n] * 2147483648);   0 <= n < blockSize
函数定义如下:
    void arm_float_to_q31(float32_t * pSrc, q31_t * pDst, uint32_t blockSize)
参数定义:
    [in]    *pSrc     points to the floating-point input vector   
    [out]  *pDst     points to the Q31 output vector   
    [in]    blockSize length of the input vector
注意事项:
    1. 这个函数使用了饱和运算。
    2. 输出结果的范围是[0x80000000 0x7FFFFFFF]
13.3.2 arm_float_to_q15
公式描述:
    pDst[n] = (q15_t)(pSrc[n] * 32768);   0 <= n < blockSize.   
函数定义如下:
     void arm_float_to_q15(float32_t * pSrc, q15_t * pDst, uint32_t blockSize)
参数定义:
    [in]    *pSrc     points to the floating-point input vector   
    [out]  *pDst     points to the Q15 output vector   
    [in]    blockSize length of the input vector
注意事项:
    1. 这个函数使用了饱和运算。
    2. 输出结果的范围是[0x8000 0x7FFF]
13.3.3 arm_float_to_q7
公式描述:
    pDst[n] = (q7_t)(pSrc[n] * 128);   0 <= n < blockSize.   
函数定义如下:
    void arm_float_to_q7(float32_t * pSrc, q7_t * pDst, uint32_t blockSize)
参数定义:
    [in]    *pSrc     points to the floating-point input vector   
    [out]  *pDst     points to the Q7 output vector   
    [in]    blockSize length of the input vector
注意事项:
    1. 这个函数使用了饱和运算。
    2. 输出结果的范围是[0x80 0x7F]
13.3.4 实例讲解
实验目的:
    1. 学习SupportFunctions中的浮点数转定点数
实验内容:
    1. 按下按键K3, 串口打印函数DSP_FloatToFix的输出结果
实验现象:
    通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下:
13.3.png
程序设计:
  1. /*
  2. *********************************************************************************************************
  3. *        函 数 名: DSP_FloatToFix
  4. *        功能说明: 浮点数转定点数
  5. *        形 参:无
  6. *        返 回 值: 无
  7. *********************************************************************************************************
  8. */
  9. static void DSP_FloatToFix(void)
  10. {
  11. float32_t pSrc[10] = {0.6557, 0.0357, 0.8491, 0.9340, 0.6787, 0.7577, 0.7431, 0.3922, 0.6555, 0.1712};
  12. uint32_t pIndex;
  13. q31_t pDst1[10];
  14. q15_t pDst2[10];
  15. q7_t pDst3[10];
  16. for(pIndex = 0; pIndex < 10; pIndex++)
  17. {
  18. printf("pSrc[%d] = %f\r\n", pIndex, pSrc[pIndex]);
  19. }
  20. /*****************************************************************/
  21. arm_float_to_q31(pSrc, pDst1, 10);
  22. for(pIndex = 0; pIndex < 10; pIndex++)
  23. {
  24. printf("arm_float_to_q31: pDst[%d] = %d\r\n", pIndex, pDst1[pIndex]);
  25. }
  26. /*****************************************************************/
  27. arm_float_to_q15(pSrc, pDst2, 10);
  28. for(pIndex = 0; pIndex < 10; pIndex++)
  29. {
  30. printf("arm_float_to_q15: pDst1[%d] = %d\r\n", pIndex, pDst2[pIndex]);
  31. }
  32. /*****************************************************************/
  33. arm_float_to_q7(pSrc, pDst3, 10);
  34. for(pIndex = 0; pIndex < 10; pIndex++)
  35. {
  36. printf("arm_float_to_q7: pDst2[%d] = %d\r\n", pIndex, pDst3[pIndex]);
  37. }
  38. /*****************************************************************/
  39. printf("******************************************************************\r\n");
  40. }
复制代码
13.4 总结
    本期教程就跟大家讲这么多,有兴趣的可以深入研究这些函数源码的实现。

kqh1120 回答时间:2015-3-24 11:31:32
3.gif 学习了啊
小蚂蚁快溜跑 回答时间:2015-3-24 13:18:04
不懂,帮顶
wamcncn 回答时间:2015-3-24 17:34:40
谢谢分享

所属标签

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版