硬汉嵌入式论坛

 找回密码
 立即注册
查看: 3435|回复: 2
收起左侧

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

[复制链接]

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
发表于 2015-3-30 10:14:05 | 显示全部楼层 |阅读模式
特别说明:完整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[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中存储的数据格式是(实部,虚部,实部,虚部……………

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中存储的数据格式是(实部,虚部,实部,虚部……………

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;        
     }
函数定义如下:
    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中存储的数据格式是(实部,虚部,实部,虚部……………

18.1.4 实例讲解

实验目的:
   1. 学习ComplexMathFunctions中模平方的求解
实验内容:
    1. 按下按键K1, 串口打印函数DSP_MagSquared的输出结果
实验现象:
    通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下:

程序设计:
  1. /*
  2. *********************************************************************************************************
  3. *    函 数 名: DSP_MagSquared
  4. *    功能说明: 复数模的平方
  5. *    形    参:无
  6. *    返 回 值: 无
  7. *********************************************************************************************************
  8. */
  9. static void DSP_MagSquared(void)
  10. {
  11. uint8_t i;
  12. float32_t pSrc[10] = {1.1f, 1.1f, 2.1f, 2.1f, 3.1f, 3.1f, 4.1f, 4.1f, 5.1f, 5.1f};
  13. float32_t pDst[10];
  14. q31_t pSrc1[10] = {1*268435456, 1*268435456, 2*268435456, 2*268435456, 3*268435456, 3*268435456,
  15.                     4*268435456, 4*268435456, 5*268435456, 5*268435456};
  16. q31_t pDst1[10];
  17. q15_t pSrc2[10] = {5000, 10000, 15000, 20000, 25000,  5000, 10000, 15000, 20000, 25000};
  18. q15_t pDst2[10];
  19. /***浮点数模平方*******************************************************************************/
  20. arm_cmplx_mag_squared_f32(pSrc, pDst, 5);
  21. for(i = 0; i < 5; i++)
  22. {
  23. printf("pDst[%d] = %f\r\n", i, pDst[i]);
  24. }
  25. /***定点数模平方Q31*******************************************************************************/
  26. arm_cmplx_mag_squared_q31(pSrc1, pDst1, 5);
  27. for(i = 0; i < 5; i++)
  28. {
  29. printf("pDst1[%d] = %d\r\n", i, pDst1[i]);
  30. }
  31. /***定点数模平方Q15*******************************************************************************/
  32. arm_cmplx_mag_squared_q15(pSrc2, pDst2, 5);
  33. for(i = 0; i < 5; i++)
  34. {
  35. printf("pDst2[%d] = %d\r\n", i, pDst2[i]);
  36. }
  37. }
复制代码
18.1.jpg
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
 楼主| 发表于 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)
参数定义:
    [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 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)
参数定义:
    [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. 数组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)
参数定义:
    [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. 数组pSrcA, pSrcB和pDst中存储的数据格式是(实部,虚部,实部,虚部……………

18.2.4 实例讲解

实验目的:
    1. 学习ComplexMathFunctions中复数乘法的求解
实验内容:
    1. 按下按键K2, 串口打印函数DSP_CmplxMult的输出结果
实验现象:
    通过窗口上位机软件SecureCRT(V5光盘里面有此软件)查看打印信息现象如下:
18.2.jpg

程序设计:
  1. /*
  2. *********************************************************************************************************
  3. *    函 数 名: DSP_CmplxMult
  4. *    功能说明: 复数乘法
  5. *    形    参:无
  6. *    返 回 值: 无
  7. *********************************************************************************************************
  8. */
  9. static void DSP_CmplxMult(void)
  10. {
  11. uint8_t i;
  12. float32_t pSrcA[10] = {1.1f, 1.2f, 2.1f, 2.2f, 3.1f, 3.2f, 4.1f, 4.2f, 5.1f, 5.2f};
  13. float32_t pSrcB[10] = {1.2f, 1.2f, 2.2f, 2.2f, 3.2f, 3.2f, 4.2f, 4.2f, 5.2f, 5.2f};
  14. float32_t pDst[10];
  15. q31_t pSrcA1[10] = {1*268435456, 1*268435456, 2*268435456, 2*268435456, 3*268435456, 3*268435456,
  16.                     4*268435456, 4*268435456, 5*268435456, 5*268435456};
  17. q31_t pSrcB1[10] = {1*268435456, 1*268435456, 2*268435456, 2*268435456, 3*268435456, 3*268435456,
  18.                     4*268435456, 4*268435456, 5*268435456, 5*268435456};
  19. q31_t pDst1[10];
  20. q15_t pSrcA2[10] = {5000, 10000, 15000, 20000, 25000,  5000, 10000, 15000, 20000, 25000};
  21. q15_t pSrcB2[10] = {6000, 11000, 15000, 20000, 25000,  5000, 10000, 15000, 20000, 25000};
  22. q15_t pDst2[10];
  23. /***浮点数乘法*******************************************************************************/
  24. arm_cmplx_mult_cmplx_f32(pSrcA, pSrcB, pDst, 5);
  25. for(i = 0; i < 5; i++)
  26. {
  27. printf("pDst[%d] = %f %fjrn", i, pDst[2*i], pDst[2*i+1]);
  28. }
  29. /***定点数乘法Q31*******************************************************************************/
  30. arm_cmplx_mult_cmplx_q31(pSrcA1, pSrcB1, pDst1, 5);
  31. for(i = 0; i < 5; i++)
  32. {
  33. printf("pDst1[%d] = %d %djrn", i, pDst1[2*i], pDst1[2*i+1]);
  34. }
  35. /***定点数乘法Q15*******************************************************************************/
  36. arm_cmplx_mult_cmplx_q15(pSrcA2, pSrcB2, pDst2, 5);
  37. for(i = 0; i < 5; i++)
  38. {
  39. printf("pDst1[%d] = %d %djrn", i, pDst2[2*i], pDst2[2*i+1]);
  40. }
  41. }
复制代码
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
 楼主| 发表于 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[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 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.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];        
     }
函数定义如下:
    void arm_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];        
     }
函数定义如下:
    void arm_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光盘里面有此软件)查看打印信息现象如下:
18.3.jpg

程序设计:
  1. /*
  2. *********************************************************************************************************
  3. *    函 数 名: DSP_CmplxMultReal
  4. *    功能说明: 复数乘实数
  5. *    形    参:无
  6. *    返 回 值: 无
  7. *********************************************************************************************************
  8. */
  9. static void DSP_CmplxMultReal(void)
  10. {
  11. uint8_t i;
  12. float32_t pSrcCmplx[10] = {1.1f, 1.2f, 2.1f, 2.2f, 3.1f, 3.2f, 4.1f, 4.2f, 5.1f, 5.2f};
  13. float32_t pSrcReal[5] = {1.2f, 1.2f, 2.2f, 2.2f, 3.2f};
  14. float32_t pCmplxDst[10];
  15. q31_t pSrcCmplx1[10] = {1*268435456, 1*268435456, 2*268435456, 2*268435456, 3*268435456, 3*268435456,
  16.                     4*268435456, 4*268435456, 5*268435456, 5*268435456};
  17. q31_t pSrcReal1[10] = {1*268435456, 1*268435456, 2*268435456, 2*268435456, 3*268435456};
  18. q31_t pCmplxDst1[10];
  19. q15_t pSrcCmplx2[10] = {14000, 16000, 20000, 20000, 30000, 31000, 12000, 13000, 14000, 25000};
  20. q15_t pSrcReal2[10] =  {15000, 17000, 20000, 20000, 30000};
  21. q15_t pCmplxDst2[10];
  22. /***浮点数*******************************************************************************/
  23. arm_cmplx_mult_cmplx_f32(pSrcCmplx, pSrcReal, pCmplxDst, 5);
  24. for(i = 0; i < 5; i++)
  25. {
  26. printf("pCmplxDst[%d] = %f %fjrn", i, pCmplxDst[2*i], pCmplxDst[2*i+1]);
  27. }
  28. /***定点数Q31*******************************************************************************/
  29. arm_cmplx_mult_cmplx_q31(pSrcCmplx1, pSrcReal1, pCmplxDst1, 5);
  30. for(i = 0; i < 5; i++)
  31. {
  32. printf("pCmplxDst1[%d] = %d %djrn", i, pCmplxDst1[2*i], pCmplxDst1[2*i+1]);
  33. }
  34. /***定点数Q15*******************************************************************************/
  35. arm_cmplx_mult_cmplx_q15(pSrcCmplx2, pSrcReal2, pCmplxDst2, 5);
  36. for(i = 0; i < 5; i++)
  37. {
  38. printf("pCmplxDst2[%d] = %d %djrn", i, pCmplxDst2[2*i], pCmplxDst2[2*i+1]);
  39. }
  40. }
复制代码

18.4 总结

    本期教程就跟大家讲这么多,有兴趣的可以深入研究下算法的具体实现。
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-4 23:45 , Processed in 0.236536 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表