硬汉嵌入式论坛

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

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

[复制链接]

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
发表于 2015-3-24 10:51:45 | 显示全部楼层 |阅读模式
特别说明:完整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光盘里面有此软件)查看打印信息现象如下:

程序设计:
  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. }
复制代码
13.1.png
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
 楼主| 发表于 2015-3-24 10:54:59 | 显示全部楼层
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] = %frn", 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] = %xrn", 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] = %xrn", 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] = %xrn", pIndex, pDst3[pIndex]);
  38. }
  39. /*****************************************************************/
  40. printf("******************************************************************rn");
  41. }
复制代码
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
 楼主| 发表于 2015-3-24 10:58:16 | 显示全部楼层
13.4 浮点数转定点数Float to Fix

13.4.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.4.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.4.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.4.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] = %frn", 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] = %drn", 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] = %drn", 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] = %drn", pIndex, pDst3[pIndex]);
  37. }
  38. /*****************************************************************/
  39. printf("******************************************************************rn");
  40. }
复制代码

13.4 总结

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-4 18:54 , Processed in 0.341936 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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