东方耀AI技术分享

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 1744|回复: 1
打印 上一主题 下一主题

[C/C++] gr cpu指令加速库volk使用复共轭相乘

[复制链接]

1365

主题

1856

帖子

1万

积分

管理员

Rank: 10Rank: 10Rank: 10

积分
14441
QQ
跳转到指定楼层
楼主
发表于 2021-7-14 15:37:45 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式





gr cpu指令加速库volk使用复共轭相乘


  1. #include <iostream>
  2. #include <volk/volk.h>
  3. #include <complex>
  4. #include <vector>

  5. using namespace std;

  6. typedef std::complex<float> gr_complex;   //这个float精度与fftwf一致

  7. void print_vector_complex(std::vector<gr_complex>& v){
  8.     for(std::vector<gr_complex>::iterator it=v.begin();it!=v.end();it++){
  9.         cout << "value of complex: real=" << (*it).real() << ",imag=" << (*it).imag() << endl;
  10.     }

  11. }



  12. void main_jjj(){
  13.     int noutput_items = 10;
  14.     std::vector<gr_complex> out;   //这是容器对象 vector动态数组
  15.     std::vector<gr_complex> in_1;
  16.     std::vector<gr_complex> in_2;

  17.     out.resize(noutput_items);
  18.     in_1.resize(noutput_items);  // 这样就不能.push_back()了
  19.     in_2.resize(noutput_items);


  20.     // 输入的数据  赋值
  21.     for(int i=0;i<noutput_items; i++){
  22.         //d_hold_in.push_back(gr_complex(i, 0));
  23.         //d_hold_in[i] = gr_complex(i,i+10);
  24.         in_1[i] = gr_complex(i, i);
  25.         in_2[i] = gr_complex(i+5, i);
  26.     }


  27.     cout << "输入数据赋初值in_1:" << endl;
  28.     print_vector_complex(in_1);

  29.     cout << "输入数据赋初值in_2:" << endl;
  30.     print_vector_complex(in_2);


  31.     //target_link_libraries(main -lvolk)
  32.     //typedef std::complex<float>   lv_32fc_t;  只能是复数
  33.     //参数类型(lv_32fc_t *, const lv_32fc_t *, const lv_32fc_t *, unsigned int)
  34.     // 函数作用:复数数组与复数数组相乘 就是对应元素复数相乘的结果  这个可能优化了
  35.     // volk_32fc_x2_multiply_32fc(
  36.     //             &out[0],  //容器对象首元素的地址   只有这个变了  *out
  37.     //             &in_1[0],  //     *in1
  38.     //             &in_2[0],   //  没变     *in2
  39.     //             noutput_items);

  40.     //volk_32fc_x2_multiply_conjugate_32fc(out, in0, in1, noi);
  41.     // 函数作用:in1*in2的复共轭=out
  42.     volk_32fc_x2_multiply_conjugate_32fc(
  43.                 &out[0],  //容器对象首元素的地址   只有这个变了  *out
  44.                 &in_1[0],  //     *in1
  45.                 &in_2[0],   //  没变     *in2
  46.                 noutput_items);
  47.     cout << "经过volk_32fc_x2_multiply_conjugate_32fc函数之后【in1*in2的复共轭=out】:" << endl;


  48.     cout << "输出结果out【只有这个变了】:" << endl;
  49.     print_vector_complex(out);


  50. }

  51. //gr cpu指令加速库volk使用复共轭相乘

  52. int main(){
  53.     main_jjj();    //自己改成 好理解
  54.     return 0;
  55. }


复制代码


9_volk.png (210.07 KB, 下载次数: 81)

9_volk.png
让天下人人学会人工智能!人工智能的前景一片大好!
回复

使用道具 举报

0

主题

98

帖子

200

积分

中级会员

Rank: 3Rank: 3

积分
200
沙发
发表于 2021-11-23 19:35:36 | 只看该作者
让天下人人学会人工智能!人工智能的前景一片大好!
回复

使用道具 举报

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

本版积分规则

QQ|Archiver|手机版|小黑屋|人工智能工程师的摇篮 ( 湘ICP备2020019608号-1 )

GMT+8, 2024-5-28 01:01 , Processed in 0.188988 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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