第18章 ComplexMathFunctions的使用(二)
本期教程主要讲解复数运算中的模平方,复数乘法和复数乘实数的求解。
18.1 复数模平方ComplexMagSquared
18.2 复数乘法ComplexMultComplex
18.3 复数乘实数ComplexMultComplex
18.4 总结
18.1 复数模平方 ComplexMagSquared
18.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;
}
函数定义如下:
voidarm_cmplx_mag_squared_f32(float32_t * pSrc, float32_t * pDst, uint32_tnumSamples)
参数定义:
[in] *pSrc points to the complex input vector
[out] *pDst pointsto the real output vector
[in] numSamples number of complex samples in the inputvector
注意事项:
1. 数组pSrc和pDst中存储的数据格式是(实部,虚部,实部,虚部……………)
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;
}
函数定义如下:
voidarm_cmplx_mag_squared_q31(q31_t * pSrc, q31_t * pDst, uint32_t numSamples)
参数定义:
[in] *pSrc points to the complex input vector
[out] *pDst pointsto the real output vector
[in] numSamples number of complex samples in the inputvector
注意事项:
1. 数组pSrc和pDst中存储的数据格式是(实部,虚部,实部,虚部……………)
18.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;
}
函数定义如下:
voidarm_cmplx_mag_squared_q15(q15_t * pSrc, q15_t * pDst, uint32_t numSamples)
参数定义:
[in] *pSrc points to the complex input vector
[out] *pDst pointsto the real output vector
[in] numSamples number of complex samples in the inputvector
注意事项:
1. 数组pSrc和pDst中存储的数据格式是(实部,虚部,实部,虚部……………)
18.1.4 实例讲解
实验目的:
1. 学习ComplexMathFunctions中模平方的求解
实验内容:
1. 按下按键K1, 串口打印函数DSP_MagSquared的输出结果
实验现象:
通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下:
程序设计:
- /*
- *********************************************************************************************************
- * 函 数 名: DSP_MagSquared
- * 功能说明: 复数模的平方
- * 形 参:无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- static void DSP_MagSquared(void)
- {
- uint8_t i;
- float32_t pSrc[10] = {1.1f, 1.1f, 2.1f, 2.1f, 3.1f, 3.1f, 4.1f, 4.1f, 5.1f, 5.1f};
- float32_t pDst[10];
-
- q31_t pSrc1[10] = {1*268435456, 1*268435456, 2*268435456, 2*268435456, 3*268435456, 3*268435456,
- 4*268435456, 4*268435456, 5*268435456, 5*268435456};
- q31_t pDst1[10];
-
- q15_t pSrc2[10] = {5000, 10000, 15000, 20000, 25000, 5000, 10000, 15000, 20000, 25000};
- q15_t pDst2[10];
-
- /***浮点数模平方*******************************************************************************/
- arm_cmplx_mag_squared_f32(pSrc, pDst, 5);
- for(i = 0; i < 5; i++)
- {
- printf("pDst[%d] = %f\r\n", i, pDst[i]);
- }
-
- /***定点数模平方Q31*******************************************************************************/
- arm_cmplx_mag_squared_q31(pSrc1, pDst1, 5);
- for(i = 0; i < 5; i++)
- {
- printf("pDst1[%d] = %d\r\n", i, pDst1[i]);
- }
-
- /***定点数模平方Q15*******************************************************************************/
- arm_cmplx_mag_squared_q15(pSrc2, pDst2, 5);
- for(i = 0; i < 5; i++)
- {
- printf("pDst2[%d] = %d\r\n", i, pDst2[i]);
- }
- }
18.2 复数乘法 ComplexMultComplex
18.2.1 arm_cmplx_mult_cmplx_f32
公式描述:
for(n=0;n<numSamples; n++) {
pDst[(2*n)+0] = pSrcA[(2*n)+0] * pSrcB[(2*n)+0] - pSrcA[(2*n)+1] *pSrcB[(2*n)+1];
pDst[(2*n)+1] = pSrcA[(2*n)+0] * pSrcB[(2*n)+1] + pSrcA[(2*n)+1] *pSrcB[(2*n)+0];
}
函数定义如下:
voidarm_cmplx_mult_cmplx_f32(
float32_t * pSrcA,
float32_t * pSrcB,
float32_t * pDst,
uint32_t numSamples)
参数定义:
[in] *pSrcA points to the first input vector
[in] *pSrcB points to the second input vector
[out] *pDst points to the output vector
[in] numSamples number of complex samples in eachvector
注意事项:
1. 数组pSrcA, pSrcB和pDst中存储的数据格式是(实部,虚部,实部,虚部……………)
18.2.2 arm_ cmplx_mult_cmplx_q31
公式描述:
for(n=0;n<numSamples; n++) {
pDst[(2*n)+0] = pSrcA[(2*n)+0] * pSrcB[(2*n)+0] - pSrcA[(2*n)+1] *pSrcB[(2*n)+1];
pDst[(2*n)+1] = pSrcA[(2*n)+0] * pSrcB[(2*n)+1] + pSrcA[(2*n)+1] *pSrcB[(2*n)+0];
}
函数定义如下:
voidarm_cmplx_mult_cmplx_q31(
q31_t * pSrcA,
q31_t * pSrcB,
q31_t * pDst,
uint32_t numSamples)
参数定义:
[in] *pSrc points to the complex input vector
[out] *pDst pointsto the real output vector
[in] numSamples number of complex samples in the inputvector
注意事项:
1. 数组pSrcA, pSrcB和pDst中存储的数据格式是(实部,虚部,实部,虚部……………)
18.2.3 arm_cmplx_mult_cmplx_q15
公式描述:
for(n=0;n<numSamples; n++) {
pDst[(2*n)+0] = pSrcA[(2*n)+0] * pSrcB[(2*n)+0] - pSrcA[(2*n)+1] *pSrcB[(2*n)+1];
pDst[(2*n)+1] = pSrcA[(2*n)+0] * pSrcB[(2*n)+1] + pSrcA[(2*n)+1] *pSrcB[(2*n)+0];
}
函数定义如下:
voidarm_cmplx_mult_cmplx_q15(
q15_t * pSrcA,
q15_t * pSrcB,
q15_t * pDst,
uint32_t numSamples)
参数定义:
[in] *pSrc points to the complex input vector
[out] *pDst pointsto the real output vector
[in] numSamples number of complex samples in the inputvector
注意事项:
1. 数组pSrcA, pSrcB和pDst中存储的数据格式是(实部,虚部,实部,虚部……………)
18.2.4 实例讲解
实验目的:
1. 学习ComplexMathFunctions中复数乘法的求解
实验内容:
1. 按下按键K2, 串口打印函数DSP_CmplxMult的输出结果
实验现象:
通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下:
程序设计:
- /*
- *********************************************************************************************************
- * 函 数 名: DSP_CmplxMult
- * 功能说明: 复数乘法
- * 形 参:无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- static void DSP_CmplxMult(void)
- {
- uint8_t i;
- float32_t pSrcA[10] = {1.1f, 1.2f, 2.1f, 2.2f, 3.1f, 3.2f, 4.1f, 4.2f, 5.1f, 5.2f};
- float32_t pSrcB[10] = {1.2f, 1.2f, 2.2f, 2.2f, 3.2f, 3.2f, 4.2f, 4.2f, 5.2f, 5.2f};
- float32_t pDst[10];
-
- q31_t pSrcA1[10] = {1*268435456, 1*268435456, 2*268435456, 2*268435456, 3*268435456, 3*268435456,
- 4*268435456, 4*268435456, 5*268435456, 5*268435456};
- q31_t pSrcB1[10] = {1*268435456, 1*268435456, 2*268435456, 2*268435456, 3*268435456, 3*268435456,
- 4*268435456, 4*268435456, 5*268435456, 5*268435456};
- q31_t pDst1[10];
-
- q15_t pSrcA2[10] = {5000, 10000, 15000, 20000, 25000, 5000, 10000, 15000, 20000, 25000};
- q15_t pSrcB2[10] = {6000, 11000, 15000, 20000, 25000, 5000, 10000, 15000, 20000, 25000};
- q15_t pDst2[10];
-
- /***浮点数乘法*******************************************************************************/
- arm_cmplx_mult_cmplx_f32(pSrcA, pSrcB, pDst, 5);
- for(i = 0; i < 5; i++)
- {
- printf("pDst[%d] = %f %fj\r\n", i, pDst[2*i], pDst[2*i+1]);
- }
-
- /***定点数乘法Q31*******************************************************************************/
- arm_cmplx_mult_cmplx_q31(pSrcA1, pSrcB1, pDst1, 5);
- for(i = 0; i < 5; i++)
- {
- printf("pDst1[%d] = %d %dj\r\n", i, pDst1[2*i], pDst1[2*i+1]);
- }
-
- /***定点数乘法Q15*******************************************************************************/
- arm_cmplx_mult_cmplx_q15(pSrcA2, pSrcB2, pDst2, 5);
- for(i = 0; i < 5; i++)
- {
- printf("pDst1[%d] = %d %dj\r\n", i, pDst2[2*i], pDst2[2*i+1]);
- }
- }
18.3 复数乘实数 ComplexMultComplex
18.3.1 arm_cmplx_mult_cmplx_f32
公式描述:
for(n=0;n<numSamples; n++) {
pCmplxDst[(2*n)+0] = pSrcCmplx[(2*n)+0] *pSrcReal[n];
pCmplxDst[(2*n)+1] = pSrcCmplx[(2*n)+1] *pSrcReal[n];
}
函数定义如下:
void arm_cmplx_mult_real_f32(
float32_t * pSrcCmplx,
float32_t * pSrcReal,
float32_t * pCmplxDst,
uint32_t numSamples)
参数定义:
[in] *pSrcCmplx points to the complexinput vector
[in] *pSrcReal points to the realinput vector
[out] *pCmplxDst points to the complexoutput vector
[in] numSamples number of samples ineach vector
注意事项:
1. 数组pSrcCmplx, pCmplxDst中存储的数据格式是(实部,虚部,实部,虚部……………)
18.3.2 arm_ cmplx_mult_cmplx_q31
公式描述:
for(n=0;n<numSamples; n++) {
pCmplxDst[(2*n)+0] = pSrcCmplx[(2*n)+0] *pSrcReal[n];
pCmplxDst[(2*n)+1] = pSrcCmplx[(2*n)+1] *pSrcReal[n];
}
函数定义如下:
voidarm_cmplx_mult_real_q31(
q31_t * pSrcCmplx,
q31_t * pSrcReal,
q31_t * pCmplxDst,
uint32_t numSamples)
参数定义:
[in] *pSrcCmplx points to the complex input vector
[in] *pSrcReal points to the real input vector
[out] *pCmplxDst points to the complex output vector
[in] numSamples number of samples in each vector
注意事项:
1. 数组pSrcCmplx, pCmplxDst中存储的数据格式是(实部,虚部,实部,虚部……………)
18.3.3 arm_cmplx_mult_cmplx_q15
公式描述:
for(n=0; n<numSamples; n++) {
pCmplxDst[(2*n)+0] = pSrcCmplx[(2*n)+0] *pSrcReal[n];
pCmplxDst[(2*n)+1] = pSrcCmplx[(2*n)+1] *pSrcReal[n];
}
函数定义如下:
voidarm_cmplx_mult_real_q15(
q15_t * pSrcCmplx,
q15_t * pSrcReal,
q15_t * pCmplxDst,
uint32_t numSamples)
参数定义:
[in] *pSrcCmplx points to the complex input vector
[in] *pSrcReal points to the real input vector
[out] *pCmplxDst points to the complex output vector
[in] numSamples number of samples in each vector
注意事项:
1. 数组pSrcCmplx, pCmplxDst中存储的数据格式是(实部,虚部,实部,虚部……………)
18.3.4 实例讲解
实验目的:
1. 学习ComplexMathFunctions中复数乘法的求解
实验内容:
1. 按下按键K3, 串口打印函数DSP_CmplxMultReal的输出结果
实验现象:
通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下:
程序设计:
- /*
- *********************************************************************************************************
- * 函 数 名: DSP_CmplxMultReal
- * 功能说明: 复数乘实数
- * 形 参:无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- static void DSP_CmplxMultReal(void)
- {
- uint8_t i;
- float32_t pSrcCmplx[10] = {1.1f, 1.2f, 2.1f, 2.2f, 3.1f, 3.2f, 4.1f, 4.2f, 5.1f, 5.2f};
- float32_t pSrcReal[5] = {1.2f, 1.2f, 2.2f, 2.2f, 3.2f};
- float32_t pCmplxDst[10];
-
- q31_t pSrcCmplx1[10] = {1*268435456, 1*268435456, 2*268435456, 2*268435456, 3*268435456, 3*268435456,
- 4*268435456, 4*268435456, 5*268435456, 5*268435456};
- q31_t pSrcReal1[10] = {1*268435456, 1*268435456, 2*268435456, 2*268435456, 3*268435456};
- q31_t pCmplxDst1[10];
-
- q15_t pSrcCmplx2[10] = {14000, 16000, 20000, 20000, 30000, 31000, 12000, 13000, 14000, 25000};
- q15_t pSrcReal2[10] = {15000, 17000, 20000, 20000, 30000};
- q15_t pCmplxDst2[10];
-
- /***浮点数*******************************************************************************/
- arm_cmplx_mult_cmplx_f32(pSrcCmplx, pSrcReal, pCmplxDst, 5);
- for(i = 0; i < 5; i++)
- {
- printf("pCmplxDst[%d] = %f %fj\r\n", i, pCmplxDst[2*i], pCmplxDst[2*i+1]);
- }
-
- /***定点数Q31*******************************************************************************/
- arm_cmplx_mult_cmplx_q31(pSrcCmplx1, pSrcReal1, pCmplxDst1, 5);
- for(i = 0; i < 5; i++)
- {
- printf("pCmplxDst1[%d] = %d %dj\r\n", i, pCmplxDst1[2*i], pCmplxDst1[2*i+1]);
- }
-
- /***定点数Q15*******************************************************************************/
- arm_cmplx_mult_cmplx_q15(pSrcCmplx2, pSrcReal2, pCmplxDst2, 5);
- for(i = 0; i < 5; i++)
- {
- printf("pCmplxDst2[%d] = %d %dj\r\n", i, pCmplxDst2[2*i], pCmplxDst2[2*i+1]);
- }
- }
18.4 总结
本期教程就跟大家讲这么多,有兴趣的可以深入研究下算法的具体实现。