经过两天的熟悉以及小伙伴的指导,蹒跚着开始了程序的实(测)现(试)
有了一些常用的矩阵运算,基本上就可以实现一个煎蛋的波束形成代码了。
在VS上写矩阵比matlab痛苦很多,
matlab:
R = signal_d'*signal_d;
for i = 1:length(theta)
a_s = exp(-jay*2*pi*f0*[0:N-1]*d/c*sin(theta(i)*pi/180));
beam(i,temp3) = a_s *(R) *a_s';
end
VS:
for(i_theta=0;i_theta<n_theta;i_theta++)
{
a_sReal = cos(-2*PI*ula_id*f0*d/c*sin(theta*PI/180));
a_simag = sin(-2*PI*ula_id*f0*d/c*sin(theta*PI/180));
a_s = af::complex(a_sReal,a_simag );
a_sT =transpose(a_s);
temp_p = matmul(a_s,R_data);
p_data = matmul(temp_p,a_sT);
p_data_abs = af::abs(p_data);
theta = theta + 0.5;
test_data.push_back(af::sum<double>(p_data_abs*p_data_abs));//类型转换
}
真的是很久没写过这些程序了,总结一点心得:
1.用来做循环的量很多时候重复利用了,但是没有在适当的适合置零。导致在之后的循环中,出错。
2.测试用的数据不宜太对称了。不然结果可能出乎意料。
3.用arrayfire or C写虚数好麻烦。要先写实部,再写虚部,再用af::complex(shibu,xubu)把实部虚部组合起来