|
gr cpu指令加速库volk使用复共轭相乘
- #include <iostream>
- #include <volk/volk.h>
- #include <complex>
- #include <vector>
- using namespace std;
- typedef std::complex<float> gr_complex; //这个float精度与fftwf一致
- void print_vector_complex(std::vector<gr_complex>& v){
- for(std::vector<gr_complex>::iterator it=v.begin();it!=v.end();it++){
- cout << "value of complex: real=" << (*it).real() << ",imag=" << (*it).imag() << endl;
- }
- }
- void main_jjj(){
- int noutput_items = 10;
- std::vector<gr_complex> out; //这是容器对象 vector动态数组
- std::vector<gr_complex> in_1;
- std::vector<gr_complex> in_2;
- out.resize(noutput_items);
- in_1.resize(noutput_items); // 这样就不能.push_back()了
- in_2.resize(noutput_items);
- // 输入的数据 赋值
- for(int i=0;i<noutput_items; i++){
- //d_hold_in.push_back(gr_complex(i, 0));
- //d_hold_in[i] = gr_complex(i,i+10);
- in_1[i] = gr_complex(i, i);
- in_2[i] = gr_complex(i+5, i);
- }
- cout << "输入数据赋初值in_1:" << endl;
- print_vector_complex(in_1);
- cout << "输入数据赋初值in_2:" << endl;
- print_vector_complex(in_2);
- //target_link_libraries(main -lvolk)
- //typedef std::complex<float> lv_32fc_t; 只能是复数
- //参数类型(lv_32fc_t *, const lv_32fc_t *, const lv_32fc_t *, unsigned int)
- // 函数作用:复数数组与复数数组相乘 就是对应元素复数相乘的结果 这个可能优化了
- // volk_32fc_x2_multiply_32fc(
- // &out[0], //容器对象首元素的地址 只有这个变了 *out
- // &in_1[0], // *in1
- // &in_2[0], // 没变 *in2
- // noutput_items);
- //volk_32fc_x2_multiply_conjugate_32fc(out, in0, in1, noi);
- // 函数作用:in1*in2的复共轭=out
- volk_32fc_x2_multiply_conjugate_32fc(
- &out[0], //容器对象首元素的地址 只有这个变了 *out
- &in_1[0], // *in1
- &in_2[0], // 没变 *in2
- noutput_items);
- cout << "经过volk_32fc_x2_multiply_conjugate_32fc函数之后【in1*in2的复共轭=out】:" << endl;
- cout << "输出结果out【只有这个变了】:" << endl;
- print_vector_complex(out);
- }
- //gr cpu指令加速库volk使用复共轭相乘
- int main(){
- main_jjj(); //自己改成 好理解
- return 0;
- }
复制代码
|
|