特别说明:完整45期数字信号处理教程,原创高性能示波器代码全开源地址:链接
3 N! j4 x5 {. `6 R" H" Z% j7 a第18章 ComplexMathFunctions的使用(二)
6 f6 u( Z8 r/ _8 R8 s; J3 z' L4 D 本期教程主要讲解复数运算中的模平方,复数乘法和复数乘实数的求解。 18.1 复数模平方 ComplexMagSquared 18.2 复数乘法 ComplexMultComplex 18.3 复数乘实数 ComplexMultComplex 18.4 总结 . {* \! K: H) r, ]" Z! t
18.1 复数模平方 ComplexMagSquared18.1.1 arm_cmplx_mag_squared_f32公式描述: for(n=0; n<numSamples; n++) { pDst[n] = pSrc[(2*n)+0]^2 + pSrc[(2*n)+1]^2; } 函数定义如下: void arm_cmplx_mag_squared_f32(float32_t * pSrc, float32_t * pDst, uint32_t numSamples) 参数定义: [in] *pSrc points to the complex input vector [out] *pDst points to the real output vector [in] numSamples number of complex samples in the input vector 注意事项: 1. 数组pSrc和pDst中存储的数据格式是(实部,虚部,实部,虚部……………) $ Q- x& a/ L4 o4 r- s# E
18.1.2 arm_cmplx_mag_squared_q31公式描述: for(n=0; n<numSamples; n++) { pDst[n] = pSrc[(2*n)+0]^2 + pSrc[(2*n)+1]^2; } 函数定义如下: void arm_cmplx_mag_squared_q31(q31_t * pSrc, q31_t * pDst, uint32_t numSamples) 参数定义: [in] *pSrc points to the complex input vector [out] *pDst points to the real output vector [in] numSamples number of complex samples in the input vector 注意事项: 1. 数组pSrc和pDst中存储的数据格式是(实部,虚部,实部,虚部……………)
* g6 u( _% w& l18.1.3 arm_cmplx_mag_squared_q15公式描述: for(n=0; n<numSamples; n++) { pDst[n] = pSrc[(2*n)+0]^2 + pSrc[(2*n)+1]^2; } 函数定义如下: void arm_cmplx_mag_squared_q15(q15_t * pSrc, q15_t * pDst, uint32_t numSamples) 参数定义: [in] *pSrc points to the complex input vector [out] *pDst points to the real output vector [in] numSamples number of complex samples in the input vector 注意事项: 1. 数组pSrc和pDst中存储的数据格式是(实部,虚部,实部,虚部……………)
/ ^- i8 R; @9 e5 p18.1.4 实例讲解实验目的: 1. 学习ComplexMathFunctions中模平方的求解 实验内容: 1. 按下按键K1, 串口打印函数DSP_MagSquared的输出结果 实验现象: 通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下: 程序设计: - /*
1 x+ z' y6 v; m+ o8 Z - *********************************************************************************************************
. g6 L/ L" E1 M7 a' M - * 函 数 名: DSP_MagSquared
) a& g& \" a4 Y! ~2 z; a1 k* w - * 功能说明: 复数模的平方8 n: ]2 c/ U+ z5 t y& z' d
- * 形 参:无
- r& d5 n" y z& _& r - * 返 回 值: 无$ D! W' n% c9 Q
- *********************************************************************************************************4 g) t2 t9 o" G4 Y" @$ _' u
- */ |# u4 F9 e+ }- O0 u" c
- static void DSP_MagSquared(void)
6 i0 O: f5 u! O x: q c - {, y# G6 e$ B- L! g
- uint8_t i;! [) s. a/ `8 T8 W- s
- float32_t pSrc[10] = {1.1f, 1.1f, 2.1f, 2.1f, 3.1f, 3.1f, 4.1f, 4.1f, 5.1f, 5.1f};
+ M: N( R" U' S, s) h. Z - float32_t pDst[10];% u$ o5 P6 E$ ]% \! v& b V) }2 A
- q31_t pSrc1[10] = {1*268435456, 1*268435456, 2*268435456, 2*268435456, 3*268435456, 3*268435456, 2 I* Q; {3 I! x# j0 w2 r1 H
- 4*268435456, 4*268435456, 5*268435456, 5*268435456};& x g* ^* s. i( X% n6 l! u! x
- q31_t pDst1[10];
% f# @+ M2 F! U. i -
2 C4 @2 t0 T' N% K3 ]5 a" d# Y - q15_t pSrc2[10] = {5000, 10000, 15000, 20000, 25000, 5000, 10000, 15000, 20000, 25000};& O" Z$ _: U! a7 _; H
- q15_t pDst2[10];
5 I' @& d6 Z7 k0 }/ u - /***浮点数模平方*******************************************************************************/' J7 Y6 D1 W1 w# d# P
- arm_cmplx_mag_squared_f32(pSrc, pDst, 5);
' y7 g/ l; m( A3 L - for(i = 0; i < 5; i++)
9 k4 j5 S: w2 ^7 ^1 {3 b+ M5 ? - {
5 e% E8 k% ^2 ~1 l* F, c% }4 L4 D - printf("pDst[%d] = %f\r\n", i, pDst[i]);
3 _. @* v1 x3 _( L0 W" p - }
6 b1 ?. T# K2 n+ z3 I - /***定点数模平方Q31*******************************************************************************/
. {4 ~7 e/ V, | - arm_cmplx_mag_squared_q31(pSrc1, pDst1, 5);
& v5 w) i z1 r% C; b% z& B. h - for(i = 0; i < 5; i++)' z6 R" p% [6 d
- {
+ e. F) H7 l; b9 W! A8 q - printf("pDst1[%d] = %d\r\n", i, pDst1[i]);
0 n, S4 |6 x d1 \4 P7 B7 K: s3 ^ - }
Z1 V8 I$ y, H1 v) r4 r - /***定点数模平方Q15*******************************************************************************/: d% d7 w9 D* g* [9 |: X
- arm_cmplx_mag_squared_q15(pSrc2, pDst2, 5);' m( E. |2 A: Q% q- S
- for(i = 0; i < 5; i++)
4 V( b/ n5 |1 |8 |2 } - {
G" I D$ w+ F) @8 T - printf("pDst2[%d] = %d\r\n", i, pDst2[i]);
5 |% U2 X1 `1 L+ Y2 r - }) }" R" ?" |- h& v3 C+ I* n3 n
- }
复制代码
0 x. [& U# z. C9 i5 d |
" h- Y& r# \/ \ w8 V0 z
18.2.1 arm_cmplx_mult_cmplx_f32
18.2.2 arm_ cmplx_mult_cmplx_q31
18.2.3 arm_cmplx_mult_cmplx_q15
0 G% q% _2 w5 p: Z0 ^9 i( C5 x4 v; a
18.2.4 实例讲解
" G- J" J; {, {% x4 [
18.3.1 arm_cmplx_mult_cmplx_f32
18.3.2 arm_ cmplx_mult_cmplx_q31
18.3.3 arm_cmplx_mult_cmplx_q15
18.3.4 实例讲解
18.4 总结
* R1 Y; X5 o \) d