特别说明:完整45期数字信号处理教程,原创高性能示波器代码全开源地址:链接
* `- G$ s/ W0 v: o4 q1 c6 c% L第20章 MatrixFunctions的使用(二)
6 j( X! a- L% ^: f 本期教程主要讲解矩阵运算中的放缩,乘法和转置。 20.1 矩阵放缩 MatScale 20.2 矩阵乘法 MatMult 20.3 转置矩阵 MatTrans 20.4 总结
' r4 i/ q) T( ^5 C20.1 矩阵放缩 MatScale) |% d2 d! X6 S0 E
9 `* w$ }5 {% d) z$ w% M20.1.1 arm_mat_scale_f32公式描述: 函数定义如下: arm_status arm_mat_scale_f32( const arm_matrix_instance_f32 * pSrc, float32_t scale, arm_matrix_instance_f32 * pDst) 参数定义: [in] *pSrc points to input matrix structure [in] scale scale factor to be applied [out] *pDst points to output matrix structure return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code> " I4 l% n3 D6 n+ ^
20.1.2 arm_mat_scale_q31函数定义如下: arm_status arm_mat_scale_q31( const arm_matrix_instance_q31 * pSrc, q31_t scaleFract, int32_t shift, arm_matrix_instance_q31 * pDst) 参数定义: [in] *pSrc points to input matrix [in] scaleFract fractional portion of the scale factor [in] shift number of bits to shift the result by [out] *pDst points to output matrix structure return The function returns either 注意事项: 1. 两个1.31格式的数据相乘产生2.62格式的数据,最终结果要做偏移和饱和运算产生1.31格式数据。 2. 定点数的最终放缩比例计算是:scale = scaleFract * 2^shift.
/ r; f4 M% u# J, ?20.1.3 arm_mat_scale_q15函数定义如下: arm_status arm_mat_scale_q15( const arm_matrix_instance_q15 * pSrc, q15_t scaleFract, int32_t shift, arm_matrix_instance_q15 * pDst) 参数定义: [in,out] *S points to an instance of the floating-point matrix structure. [in] nRows number of rows in the matrix. [in] nColumns number of columns in the matrix. [in] *pData points to the matrix data array. 注意事项: 1. 两个1.15格式的数据相乘产生2.30格式的数据,最终结果要做偏移和饱和运算产生1.15格式数据。 2. 定点数的最终放缩比例计算是:scale = scaleFract * 2^shift.
) `) x7 a* Z! ], O0 v20.1.4 实例讲解实验目的: 1. 学习MatrixFunctions中矩阵的放缩 实验内容: 1. 按下按键K1, 串口打印函数DSP_MatScale的输出结果 实验现象: 通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下: 程序设计: - /*
g4 _2 ?* y& ^+ q - *********************************************************************************************************
/ i; D2 X3 T' n# a) q' U1 [# ^1 B8 ` - * 函 数 名: DSP_MatScale2 @/ D6 k/ R' h( Y
- * 功能说明: 矩阵放缩) w G5 D8 s1 i! V
- * 形 参:无1 a1 H, ?0 v7 ~7 O' q" N7 e6 j
- * 返 回 值: 无/ X! l* A2 W2 |7 }
- *********************************************************************************************************9 y; E/ m8 \# u& u- P" I0 G0 Y, }
- */$ g# b! @+ H/ ^& M- O
- static void DSP_MatScale(void)
0 ~. s, C! N' p' B, s - {
# U; ?4 `; {) H& D3 E9 k, ^ - uint8_t i;
$ g; b0 _5 z' `$ J - /****浮点数数组******************************************************************/9 p/ \" {. o+ n; C: j t& D
- float32_t pDataA[9] = {1.1f, 1.1f, 2.1f, 2.1f, 3.1f, 3.1f, 4.1f, 4.1f, 5.1f};
0 o0 B* @0 y$ ^% j+ b - float32_t scale = 1.1f;# G. _$ M" }7 \ m. l: \
- float32_t pDataDst[9];4 ~ \3 b7 r V0 w9 K: Z
- arm_matrix_instance_f32 pSrcA; //3行3列数据
7 D* P$ P1 C) i2 | - arm_matrix_instance_f32 pDst;
5 ^2 `, u5 L2 w8 v/ O- S2 U - /****定点数Q31数组******************************************************************/
# g% y9 N. V' r0 A: p - q31_t pDataA1[9] = {1, 1, 2, 2, 3, 3, 4, 4, 5};
& W/ f+ ]( j/ O1 j - q31_t scaleFract = 10;3 l/ Y2 O. O* Z7 r7 c! R# t
- int32_t shift = 0;. d* y, s5 }2 k' m% v$ ]
- q31_t pDataDst1[9];
1 s( o6 [$ E% o$ e- K - arm_matrix_instance_q31 pSrcA1; //3行3列数据
8 ? q4 ]3 ?" N6 }, O9 g% M - arm_matrix_instance_q31 pDst1;. T ?2 ^, K' i k2 k% L
- /****定点数Q15数组******************************************************************/
+ u5 U' ?- j. D2 V - q15_t pDataA2[9] = {1, 1, 2, 2, 3, 3, 4, 4, 5};
5 ^5 u5 `8 n6 o - q15_t scaleFract1 = 10;
5 k' w! A4 u4 w1 ]; `+ {% g- G: D9 W1 \! ` - int32_t shift1 = 0;
) w7 S9 s0 ]% ? - q15_t pDataDst2[9];
' R4 a, z) [ _ U- l4 R - arm_matrix_instance_q15 pSrcA2; //3行3列数据8 \/ k) C* i1 r1 E3 e+ @8 V
- arm_matrix_instance_q15 pDst2;
9 b. w: N) `* {% Y - /****浮点数***********************************************************************/
/ b! |' t# |; d4 `$ p/ T+ E - pSrcA.numCols = 3;% G4 R7 C4 c1 {
- pSrcA.numRows = 3;
' {. @+ N6 l# b( v, W - pSrcA.pData = pDataA;' }' {) w+ ]1 `6 w) \
- ; Q3 U6 Z* V" t8 J; X3 W; ]! @
- pDst.numCols = 3;
8 f$ e- V7 M3 ?: e- w - pDst.numRows = 3;
* L. k/ ^4 q/ G2 G b - pDst.pData = pDataDst;
* j0 c% N. v* q2 Z; B% i1 ~ - printf("****浮点数******************************************\r\n");; E- X; l9 W- V5 v! w
- arm_mat_scale_f32(&pSrcA, scale, &pDst);
, X$ b9 R# G! }: P5 x* ^9 L - for(i = 0; i < 9; i++)0 d# z% F2 n6 N6 |/ B( Z) d b8 e2 N
- {
! x7 O/ e9 y8 X, ~2 O3 j - printf("pDataDst[%d] = %f\r\n", i, pDataDst[i]);
O6 r4 [ L& O, K9 M - }
" p" \) D* ~# t* t5 k - /****定点数Q31***********************************************************************/# l/ N; V( X8 _; a9 m
- pSrcA1.numCols = 3;8 Q* O; Q; r- w+ w$ o
- pSrcA1.numRows = 3;
8 M$ A' Y1 e% W @, H - pSrcA1.pData = pDataA1;% i3 ^! y; `" p: ]# Q( O
- pDst1.numCols = 3;4 J8 h2 [# W) p# `4 }" J7 p
- pDst1.numRows = 3;
' ^9 B$ w& M6 @7 G$ H3 e2 y5 A - pDst1.pData = pDataDst1;
% p) `3 @2 B, Z - printf("****定点数Q31******************************************\r\n");; u7 `# }$ ?$ ?& ~) I7 G( d' a
- arm_mat_scale_q31(&pSrcA1, scaleFract, shift, &pDst1);
! C' i0 P# ~3 P! i: @" Q; s; _ - for(i = 0; i < 9; i++)
' J4 j! k$ M& |; b2 m5 f - {4 l* x( c' ~" j5 ^. _! m
- printf("pDataDst1[%d] = %d\r\n", i, pDataDst1[i]);
0 u/ s' T0 a5 X& i; l9 s2 j - }% P7 F! i3 C! J9 _& C3 L8 f8 p9 r
- /****定点数Q15***********************************************************************/
: g" u: J7 x0 ?) ?# f' z3 S8 r - pSrcA2.numCols = 3;
, o$ V; [0 W" g% C - pSrcA2.numRows = 3;' b r6 G7 Q& r+ P
- pSrcA2.pData = pDataA2;! S% R7 j0 I+ ~1 `4 K7 K
- pDst2.numCols = 3;
! e8 j7 r. Y& h I/ @: \* C% } - pDst2.numRows = 3;" _- F2 t0 U" k. Q# L* X
- pDst2.pData = pDataDst2;
( c/ j% Y: x! K) y+ t% }4 o - printf("****定点数Q15******************************************\r\n");" @' x* W5 ?: D" x# ?9 o
- arm_mat_scale_q15(&pSrcA2, scaleFract1, shift1, &pDst2);3 X: D* T$ l$ g, @( i" B. p
- for(i = 0; i < 9; i++)1 ~1 Q8 r- H6 e7 i+ ^
- { G( p& M' }) P9 i P% W+ i
- printf("pDataDst2[%d] = %d\r\n", i, pDataDst2[i]);4 w! C3 X. ~/ Y: P1 R
- }: {% C& n5 Y% j0 r
- }
复制代码1. 下面通过matlab来实现矩阵的放缩:
5 | j) X8 l" V+ y
$ i: j) H6 l1 h% m+ ]2 ? |
20.2.1 arm_mat_mult_f32
20.2.2 arm_mat_mult_q31
20.2.3 arm_mat_mult_q15
20.2.4 arm_mat_mult_fast_q31
20.2.5 arm_mat_mult_fast_q15
20.2.6 实例讲解
20.3.1 arm_mat_trans_f32
20.3.2 arm_mat_trans_q31
20.3.3 arm_mat_trans_q15
20.3.4 实例讲解