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

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

[复制链接]
baiyongbin2009 发布时间:2015-3-25 11:08
特别说明:完整45期数字信号处理教程,原创高性能示波器代码全开源地址:链接4 [# n4 j2 o( |3 }0 c) U4 d6 ^
第14章 SupportFunctions的使用(二)

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

: i4 `. `& o  b7 S* g1 @+ O14.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   
3 R) b: n# r( Y- a
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   
  q9 b, V5 @% Z- I
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   

1 Y, s, a& _3 w. Q5 P/ Z
14.1.4 实例讲解
实验目的:
    1. 学习SupportFunctions中Q7格式数据的转换
实验内容:
    1. 按下按键K1, 串口打印函数DSP_Q7的输出结果
实验现象:
    通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下:
14.1.png
程序设计:
  1. /*8 ^0 ^  w3 x/ Y7 a: X
  2. *********************************************************************************************************
    & t! C% r* i, J8 }/ O
  3. *        函 数 名: DSP_Q7' G, e, K6 o& x- m
  4. *        功能说明: Q7格式数据向其它格式转换
    " q8 h4 B/ U, b& S7 N! x
  5. *        形    参:无
    8 A+ r5 l2 w0 ?$ S
  6. *        返 回 值: 无
    : f0 G, g  B. V0 |* ~1 p
  7. *********************************************************************************************************
    / R( ~+ j1 E1 i5 P" P3 A
  8. */
      ]+ N' h# F) O: k8 ?; Q: q
  9. static void DSP_Q7(void)! e  G4 l: f% w; p
  10. {
    8 M  H' I1 ~2 R* @5 K6 }
  11. float32_t pDst[10];2 I3 H" I% R6 x9 b( v2 A( t) S0 u
  12. uint32_t pIndex;
    " q5 _2 Y5 i" _+ E  _+ c7 S
  13. q31_t pDst1[10];
    & |; y/ e) j/ X, _
  14. q15_t pDst2[10];
    / Q8 o  r$ j# j  g- V0 Q0 Q& a
  15. q7_t  pSrc[10];* Z* U" ?6 ?$ h0 P% S8 I; y
  16. for(pIndex = 0; pIndex < 10; pIndex++)- m8 {! w: [# m5 ?
  17. {
    1 A! M0 @! h' o
  18. pSrc[pIndex] = rand()%128;
    3 X- x3 v6 {4 W+ X2 ^
  19. printf("pSrc[%d] = %d\r\n", pIndex, pSrc[pIndex]);
    3 @# I' h5 n; B1 d+ Q. h
  20. }8 ~/ w/ t1 P& L/ Q: o$ x
  21. /*****************************************************************/0 M  u2 Z- C0 a2 D1 M1 Z
  22. arm_q7_to_float(pSrc, pDst, 10);( K, K7 P+ |4 v5 [% f  H
  23. for(pIndex = 0; pIndex < 10; pIndex++)
    . |# V+ c% I2 [% @4 l' ~
  24. {
    + I+ Z& }" ]& @1 A) v, t9 ?
  25. printf("arm_q7_to_float: pDst[%d] = %f\r\n", pIndex, pDst[pIndex]);
    : _" Z7 f9 k3 _7 G( o
  26. }8 X  a) {. T) _0 `! e0 N

  27. 9 \0 J. T( P5 o/ |1 q' N+ S" @7 x
  28. /*****************************************************************/+ }4 _8 {% f( f  I1 e
  29. arm_q7_to_q31(pSrc, pDst1, 10);* |6 v4 ^$ o0 {: m$ O2 W
  30. for(pIndex = 0; pIndex < 10; pIndex++)
    $ N# V/ y+ Q' x/ W
  31. {" D( ]+ m0 n& V/ W6 `1 \
  32. printf("arm_q7_to_q31: pDst1[%d] = %d\r\n", pIndex, pDst1[pIndex]);
    7 M% Z9 |* `5 a. r
  33. }2 e. G6 p* E) q8 k- D# [0 \6 K
  34. /*****************************************************************/
    ( A) j/ |1 y. Z7 c
  35. arm_q7_to_q15(pSrc, pDst2, 10);2 O* b! \4 l; h# _% V+ f. g
  36. for(pIndex = 0; pIndex < 10; pIndex++)
    , ?6 e) @1 k0 _, s% f8 x1 j7 f
  37. {
    9 J1 S# l4 M0 R# E5 A' y# @
  38. printf("arm_q7_to_q15: pDst2[%d] = %d\r\n", pIndex, pDst2[pIndex]);
    % ~# k. I: g- [' S; R! a6 D4 @
  39. }
    " v/ r" w0 d2 t/ Z" p" E7 }
  40. /*****************************************************************/) J7 B# ?2 @# j$ g8 A, l
  41. printf("******************************************************************\r\n");
    - F  w. N# \+ ^! b+ @+ u
  42. }
复制代码
赞 收藏 评论3 发布时间:2015-3-25 11:08

举报

3个回答
baiyongbin2009 回答时间:2015-3-25 11:09:07
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   

( F' s  C0 c# Q( |) J# ^
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   

. R1 U5 T3 x0 `8 o3 w; d) F
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   
8 ^8 X# V/ N+ C
14.2.4 实例讲解
实验目的:
    1. 学习SupportFunctions中Q15格式数据的转换
实验内容:
    1. 按下按键K1, 串口打印函数DSP_Q7的输出结果
实验现象:
    通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下:
14.2.png
程序设计:
  1. /*4 A3 F4 f9 u0 y3 s3 Q
  2. *********************************************************************************************************5 i4 u3 h, I- e* r
  3. *        函 数 名: DSP_Q15
    % T7 u0 n) j7 m0 T$ w7 W
  4. *        功能说明: Q15格式数据向其它格式转换( ?! Q/ i( M% G- T; e0 L3 M6 {
  5. *        形 参:无
    + q1 F, M$ o7 d5 ~
  6. *        返 回 值: 无: M- O, ~6 z- Y( L0 S, s
  7. *********************************************************************************************************5 c2 d; G$ x8 {" W; Z2 f! S
  8. */
    " w: v  A0 O9 l2 H  u: |. [
  9. static void DSP_Q15(void)' y+ y% B' y! O
  10. {  P1 Q' O. B/ H) b. L
  11. float32_t pDst[10];
    ! M7 h% M# O- y8 j0 m  g: k$ b
  12. uint32_t pIndex;! M, v: }) k2 C- ?
  13. q31_t pDst1[10];- ]( p) q$ N) o) n
  14. q15_t pSrc[10];. f( g$ ^6 Z2 v# W' }
  15. q7_t pDst2[10];
    - s( U3 M+ I7 U4 P3 J
  16. for(pIndex = 0; pIndex < 10; pIndex++)
    & [# S; c( L3 D4 j
  17. {
      S1 b8 E! v4 z( u& Z
  18. pSrc[pIndex] = rand()%32678;
    3 C5 w8 {' O& H# B: k
  19. printf("pSrc[%d] = %d\r\n", pIndex, pSrc[pIndex]);
    + x7 ^, v% O0 \) R0 S
  20. }
    8 D: }& A, J9 y2 a6 @% l
  21. /*****************************************************************/- G; K/ l2 m! l& {% }
  22. arm_q15_to_float(pSrc, pDst, 10);
    : z7 P- Y& P% S8 \  }
  23. for(pIndex = 0; pIndex < 10; pIndex++)
      O4 G# |  u+ J8 I$ d! m" y
  24. {" i$ K! @" d5 x: V! ^1 \- L0 U& z
  25. printf("arm_q15_to_float: pDst[%d] = %f\r\n", pIndex, pDst[pIndex]);* ^5 z8 e7 s* c% ~$ i" R
  26. }- [$ Q& r/ Z4 ^9 o- w$ C# \" U% v$ y

  27. # v$ S8 [$ @, @& l
  28. /*****************************************************************/
    - Z9 K: Q) E+ p. [7 m
  29. arm_q15_to_q31(pSrc, pDst1, 10);
    2 J' T1 t9 q5 s0 c; x
  30. for(pIndex = 0; pIndex < 10; pIndex++)
    2 N3 N0 y4 C  T: v) K& u8 i* S
  31. {
      W9 e8 d* _& [, j
  32. printf("arm_q15_to_q31: pDst1[%d] = %d\r\n", pIndex, pDst1[pIndex]);& p" O0 z/ G4 \. {* E7 F% j
  33. }
    " A5 V" H: E# M" X  T- W+ Z
  34. /*****************************************************************/. a& G4 R! q5 G3 _; A; L
  35. arm_q15_to_q7(pSrc, pDst2, 10);
    . h' J* w4 U6 J. S& ~7 {2 I
  36. for(pIndex = 0; pIndex < 10; pIndex++)
      _, f+ \/ J1 x0 F
  37. {
    ) x, \; G" |& O. v7 o! T4 x- `; Q3 f
  38. printf("arm_q15_to_q7: pDst2[%d] = %d\r\n", pIndex, pDst2[pIndex]);% C% k5 [. \1 i7 ?/ e; H
  39. }6 y  i% ~4 G. x0 v& q1 N8 c" m
  40. /*****************************************************************/
    ( t' q5 }  P6 N. I3 |) c
  41. printf("******************************************************************\r\n");2 @! l7 k7 y0 Z
  42. }
复制代码

& y$ O, T1 P' e/ L# M

5 M% e) r0 h2 o
baiyongbin2009 回答时间:2015-3-25 11:09:31
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      

. v$ V( ^" m$ b7 x/ W) q3 K7 A# Q
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   
2 }) {/ b: w! b+ f6 y7 u
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   
- p0 v- l3 L* x( A; C) Z
14.3.4 实例讲解
实验目的:
    1. 学习SupportFunctions中Q31格式数据的转换
实验内容:
    1. 按下按键K1, 串口打印函数DSP_Q31的输出结果
实验现象:
    通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下:
14.3.png
程序设计:
  1. /*
    " ?$ P+ J+ x0 J
  2. *********************************************************************************************************
    6 Y! i1 ^8 Y3 V; n  B4 \
  3. *        函 数 名: DSP_Q31
    - _: {4 G0 Z% o3 q
  4. *        功能说明: Q31格式数据向其它格式转换0 V0 W+ s" T# l
  5. *        形 参:无
    9 W% |) X' V7 z! R$ V
  6. *        返 回 值: 无
    % q4 N3 W$ e2 B9 x* d
  7. *********************************************************************************************************
    " ]! I" U3 h. }& E5 z
  8. */
    , l" k# p+ m. G5 s
  9. static void DSP_Q31(void)
    + e& k! R' p! H( S0 v% b4 s5 J
  10. {
    ' T0 f6 L# i; G
  11. float32_t pDst[10];, W% z3 G- }6 m4 H2 Y
  12. uint32_t pIndex;
    9 \, h% b7 U  L/ z4 N
  13. q31_t pSrc[10];+ x: h; b) S3 M* R9 z5 p
  14. q15_t pDst1[10];( G; t+ s* W  i9 h" U9 w, E
  15. q7_t pDst2[10];. |% u' }( b) c( B% [! l0 c; D
  16. for(pIndex = 0; pIndex < 10; pIndex++); i6 w- F. e" S9 P  @
  17. {
    ' |* p# E6 \& a9 S
  18. pSrc[pIndex] = rand();- o9 |% m5 V" h' Z( j
  19. printf("pSrc[%d] = %d\r\n", pIndex, pSrc[pIndex]);7 ^" o4 ~1 ]9 h) E- H
  20. }
    1 j7 F& }& @+ w8 S9 _2 }
  21. /*****************************************************************/* L& u3 `8 S) X  |1 W" M3 X
  22. arm_q31_to_float(pSrc, pDst, 10);
    / B& y+ @" I, K4 W% K4 L
  23. for(pIndex = 0; pIndex < 10; pIndex++)- q7 C( z: o4 X# m- R
  24. {! A6 X2 Q, P6 w# e; ~
  25. printf("arm_q31_to_float: pDst[%d] = %f\r\n", pIndex, pDst[pIndex]);( Y, x6 ?4 C2 m
  26. }
    7 [! X' ^% }# g- C

  27.   k; c4 B" P; q5 l( ~
  28. /*****************************************************************/
    # C' Y! n& h2 p8 g, y
  29. arm_q31_to_q15(pSrc, pDst1, 10);7 P1 T! k' j% {1 p1 c3 |
  30. for(pIndex = 0; pIndex < 10; pIndex++)# L$ g+ e) p. `6 D' Y2 s
  31. {% n4 @: x2 u6 C1 Y9 H
  32. printf("arm_q31_to_q15: pDst1[%d] = %d\r\n", pIndex, pDst1[pIndex]);3 d1 H* [& D! k" `( u- h( G* T
  33. }
    ' t  W3 R$ V: ^6 [2 G
  34. /*****************************************************************/
      [4 o3 z" {; g" A& S
  35. arm_q31_to_q7(pSrc, pDst2, 10);
    + O: W$ O3 ~$ K
  36. for(pIndex = 0; pIndex < 10; pIndex++)
    - [, h2 B* r% U0 {
  37. {& F& O) b0 p& }8 I; E* O6 A
  38. printf("arm_q31_to_q7: pDst2[%d] = %d\r\n", pIndex, pDst2[pIndex]);8 `$ t/ m8 O) }  E
  39. }; q; W; H' ~! a6 y- e3 l2 O
  40. /*****************************************************************/+ k7 p) \8 |5 m! Z) b; e/ E
  41. printf("******************************************************************\r\n");
    - I& r' V( y: r7 {- V/ e
  42. }
复制代码
14.4 总结
    本期教程就跟大家讲这么多,有兴趣的可以深入研究这些函数源码的实现。
+ u, M6 ]: Y$ F' Y) X  Z
小蚂蚁快溜跑 回答时间:2015-3-25 13:35:15
学习。。。。看不懂
关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
人形机器人运动控制、感知与智能配电
半导体创新技术与应用方向
EE架构与软件定义汽车
12V/48V 汽车智能配电(SPD)
区域控制单元(ZCU)与分区架构
关注我们
st-img 微信公众号
st-img 手机版