席萌0209 发表于 2015-3-30 10:14:05

【安富莱DSP教程】第18章 ComplexMathFunctions的使用(二)

特别说明:完整45期数字信号处理教程,原创高性能示波器代码全开源地址:链接
第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 = 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)
参数定义:
    *pSrc points to the complex input vector      
    *pDst points to the real output vector      
    numSamples number of complex samples in the input vector
注意事项:
    1. 数组pSrc和pDst中存储的数据格式是(实部,虚部,实部,虚部……………)

18.1.2 arm_cmplx_mag_squared_q31

公式描述:
    for(n=0; n<numSamples; n++) {      
            pDst = 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)
参数定义:
    *pSrc points to the complex input vector      
    *pDst points to the real output vector      
    numSamples number of complex samples in the input vector
注意事项:
    1. 数组pSrc和pDst中存储的数据格式是(实部,虚部,实部,虚部……………)

18.1.3 arm_cmplx_mag_squared_q15

公式描述:
    for(n=0; n<numSamples; n++) {      
            pDst = 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)
参数定义:
    *pSrc points to the complex input vector      
    *pDst points to the real output vector      
    numSamples number of complex samples in the input vector
注意事项:
    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 = {1.1f, 1.1f, 2.1f, 2.1f, 3.1f, 3.1f, 4.1f, 4.1f, 5.1f, 5.1f};
float32_t pDst;
q31_t pSrc1 = {1*268435456, 1*268435456, 2*268435456, 2*268435456, 3*268435456, 3*268435456,
                  4*268435456, 4*268435456, 5*268435456, 5*268435456};
q31_t pDst1;

q15_t pSrc2 = {5000, 10000, 15000, 20000, 25000,5000, 10000, 15000, 20000, 25000};
q15_t pDst2;
/***浮点数模平方*******************************************************************************/
arm_cmplx_mag_squared_f32(pSrc, pDst, 5);
for(i = 0; i < 5; i++)
{
printf("pDst[%d] = %f\r\n", i, pDst);
}
/***定点数模平方Q31*******************************************************************************/
arm_cmplx_mag_squared_q31(pSrc1, pDst1, 5);
for(i = 0; i < 5; i++)
{
printf("pDst1[%d] = %d\r\n", i, pDst1);
}
/***定点数模平方Q15*******************************************************************************/
arm_cmplx_mag_squared_q15(pSrc2, pDst2, 5);
for(i = 0; i < 5; i++)
{
printf("pDst2[%d] = %d\r\n", i, pDst2);
}
}

席萌0209 发表于 2015-3-30 10:18:07

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];      
    }
函数定义如下:
    void arm_cmplx_mult_cmplx_f32(
      float32_t * pSrcA,
      float32_t * pSrcB,
      float32_t * pDst,
      uint32_t numSamples)
参数定义:
    *pSrcA points to the first input vector      
    *pSrcB points to the second input vector      
    *pDst points to the output vector      
    numSamples number of complex samples in each vector   
注意事项:
    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];      
    }
函数定义如下:
    void arm_cmplx_mult_cmplx_q31(
      q31_t * pSrcA,
      q31_t * pSrcB,
      q31_t * pDst,
      uint32_t numSamples)
参数定义:
    *pSrc points to the complex input vector      
    *pDst points to the real output vector      
    numSamples number of complex samples in the input vector
注意事项:
    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];      
    }
函数定义如下:
    void arm_cmplx_mult_cmplx_q15(
      q15_t * pSrcA,
       q15_t * pSrcB,
       q15_t * pDst,
      uint32_t numSamples)
参数定义:
    *pSrc points to the complex input vector      
    *pDst points to the real output vector      
    numSamples number of complex samples in the input vector
注意事项:
    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 = {1.1f, 1.2f, 2.1f, 2.2f, 3.1f, 3.2f, 4.1f, 4.2f, 5.1f, 5.2f};
float32_t pSrcB = {1.2f, 1.2f, 2.2f, 2.2f, 3.2f, 3.2f, 4.2f, 4.2f, 5.2f, 5.2f};
float32_t pDst;
q31_t pSrcA1 = {1*268435456, 1*268435456, 2*268435456, 2*268435456, 3*268435456, 3*268435456,
                  4*268435456, 4*268435456, 5*268435456, 5*268435456};
q31_t pSrcB1 = {1*268435456, 1*268435456, 2*268435456, 2*268435456, 3*268435456, 3*268435456,
                  4*268435456, 4*268435456, 5*268435456, 5*268435456};
q31_t pDst1;
q15_t pSrcA2 = {5000, 10000, 15000, 20000, 25000,5000, 10000, 15000, 20000, 25000};
q15_t pSrcB2 = {6000, 11000, 15000, 20000, 25000,5000, 10000, 15000, 20000, 25000};
q15_t pDst2;
/***浮点数乘法*******************************************************************************/
arm_cmplx_mult_cmplx_f32(pSrcA, pSrcB, pDst, 5);
for(i = 0; i < 5; i++)
{
printf("pDst[%d] = %f %fjrn", i, pDst, pDst);
}
/***定点数乘法Q31*******************************************************************************/
arm_cmplx_mult_cmplx_q31(pSrcA1, pSrcB1, pDst1, 5);
for(i = 0; i < 5; i++)
{
printf("pDst1[%d] = %d %djrn", i, pDst1, pDst1);
}
/***定点数乘法Q15*******************************************************************************/
arm_cmplx_mult_cmplx_q15(pSrcA2, pSrcB2, pDst2, 5);
for(i = 0; i < 5; i++)
{
printf("pDst1[%d] = %d %djrn", i, pDst2, pDst2);
}
}

席萌0209 发表于 2015-3-30 10:22:17

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;      
         pCmplxDst[(2*n)+1] = pSrcCmplx[(2*n)+1] * pSrcReal;      
   }    
函数定义如下:
    void arm_cmplx_mult_real_f32(
      float32_t * pSrcCmplx,
      float32_t * pSrcReal,
      float32_t * pCmplxDst,
      uint32_t numSamples)
参数定义:
   *pSrcCmplx points to the complex input vector      
   *pSrcReal     points to the real input vector      
   *pCmplxDst points to the complex output vector      
   numSamples number of samples in each 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;      
         pCmplxDst[(2*n)+1] = pSrcCmplx[(2*n)+1] * pSrcReal;      
   }
函数定义如下:
    void arm_cmplx_mult_real_q31(
      q31_t * pSrcCmplx,
      q31_t * pSrcReal,
      q31_t * pCmplxDst,
      uint32_t numSamples)
参数定义:
    *pSrcCmplx points to the complex input vector      
    *pSrcReal     points to the real input vector      
    *pCmplxDst points to the complex output vector      
    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;      
         pCmplxDst[(2*n)+1] = pSrcCmplx[(2*n)+1] * pSrcReal;      
   }
函数定义如下:
    void arm_cmplx_mult_real_q15(
      q15_t * pSrcCmplx,
      q15_t * pSrcReal,
      q15_t * pCmplxDst,
      uint32_t numSamples)
参数定义:
    *pSrcCmplx points to the complex input vector      
    *pSrcReal     points to the real input vector      
    *pCmplxDst points to the complex output vector      
    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 = {1.1f, 1.2f, 2.1f, 2.2f, 3.1f, 3.2f, 4.1f, 4.2f, 5.1f, 5.2f};
float32_t pSrcReal = {1.2f, 1.2f, 2.2f, 2.2f, 3.2f};
float32_t pCmplxDst;
q31_t pSrcCmplx1 = {1*268435456, 1*268435456, 2*268435456, 2*268435456, 3*268435456, 3*268435456,
                  4*268435456, 4*268435456, 5*268435456, 5*268435456};
q31_t pSrcReal1 = {1*268435456, 1*268435456, 2*268435456, 2*268435456, 3*268435456};
q31_t pCmplxDst1;
q15_t pSrcCmplx2 = {14000, 16000, 20000, 20000, 30000, 31000, 12000, 13000, 14000, 25000};
q15_t pSrcReal2 ={15000, 17000, 20000, 20000, 30000};
q15_t pCmplxDst2;
/***浮点数*******************************************************************************/
arm_cmplx_mult_cmplx_f32(pSrcCmplx, pSrcReal, pCmplxDst, 5);
for(i = 0; i < 5; i++)
{
printf("pCmplxDst[%d] = %f %fjrn", i, pCmplxDst, pCmplxDst);
}
/***定点数Q31*******************************************************************************/
arm_cmplx_mult_cmplx_q31(pSrcCmplx1, pSrcReal1, pCmplxDst1, 5);
for(i = 0; i < 5; i++)
{
printf("pCmplxDst1[%d] = %d %djrn", i, pCmplxDst1, pCmplxDst1);
}
/***定点数Q15*******************************************************************************/
arm_cmplx_mult_cmplx_q15(pSrcCmplx2, pSrcReal2, pCmplxDst2, 5);
for(i = 0; i < 5; i++)
{
printf("pCmplxDst2[%d] = %d %djrn", i, pCmplxDst2, pCmplxDst2);
}
}

18.4 总结

    本期教程就跟大家讲这么多,有兴趣的可以深入研究下算法的具体实现。
页: [1]
查看完整版本: 【安富莱DSP教程】第18章 ComplexMathFunctions的使用(二)