%先初始化
f0=2.5e6; % 换能器中心频率 [Hz]
fs=100e6; % 仿真使用的采样频率
c=1540; % 声速 [m/s]
lambda=c/f0; % 波长 [m]
width=(0.32-0.05)/1000; % 阵元宽度
element_height=20/1000; % 阵元高度 [m]
kerf=0.05/1000; % 阵元间隙宽度 [m]
Ne=64; % 阵元数量
focus=[0 0 52]/1000; % 固定焦点位置 [m]
focal_depth=focus(3); % 焦点深度
array_size=(kerf+width)*Ne; % 阵元总宽度
dz=1/(2*f0)*c/2; % 距离方向分辨单元
set_sampling(fs);
xmit_aperture = xdc_linear_array(Ne,width,element_height,kerf,1,1,focus);
receive_aperture = xdc_linear_array(Ne,width,element_height,kerf,1,10,[0 0 10000000000000000000000000000000000000]);
channel_pos_tmp=xdc_get(xmit_aperture,'rect');
channel_pos=channel_pos_tmp(8,:);
%假设脉冲响应为正弦波,为提高性能,增加汉宁窗,使用函数 xdc_impulse 为发射、接收换能器设置脉冲响应。
impulse_response=cos(2*pi*f0*(0:1/fs:2/f0));
impulse_response=impulse_response.*hanning(max(size(impulse_response)))';
xdc_impulse(xmit_aperture, impulse_response);
xdc_impulse(receive_aperture, impulse_response);
%产生激励信号 excitation,使用函数 xdc_excitation 为发射换能器设置激励。
excitation=cos(2*pi*f0*(0:1/fs:1/f0));
xdc_excitation(xmit_aperture, excitation);
%使用函数 xdc_apodization 设置发射的所有通道幅度权值为 1,即不用变迹。
apo_vector=ones(1,Ne);
xdc_apodization(xmit_aperture,0,apo_vector);
%下面将分别仿真发射和接收波束形成。
%发射波束形成
SL=91; % 相控阵扫描线数为 91 线
ln_num=46; % 以垂直方向即中间扫描线为例
d_th=2*sin(45/180*pi)/(SL-1); % 相控阵扫描线夹角正弦值相等
sin_th=sin(-45/180*pi)+(ln_num-1)*d_th;
th=asin(sin_th);
focus_pt = [focal_depth * sin(th) 0 focal_depth*cos(th)];
delay_tx = -1*(sqrt((channel_pos-focus_pt(1)).^2+focus_pt(3)^2)-focal_depth)/c;
toff_c=delay_tx; %以换能器中心为参考点,使用函数xdc_focus_times 为发射换能器设置延时参数
xdc_focus_times(xmit_aperture,0,(toff_c));
%使用函数 calc_hp 计算出声场的声压分布情况。
fp=zeros(100,100);
for x=1:100
for z=1:100[hp,start_time] = calc_hp(xmit_aperture,[(x-51)*0.2/1000, 0,(z+10)*1/1000;]);
fp(z,x)=max(hp(:,1));
end
end
%接收图像
Nt=3; % 目标个数为 3
phantom_positions=[0/1000 0 15/1000; 0/1000 0 28/1000; 0/1000 0 40/1000];
phantom_amplitudes=ones(Nt,1)*20;
%开始接收图像,按顺序分别计算每条扫描线的接收信号,由于相控阵每条扫描线偏转角不同,每条扫描线都需要重新计算发射延时参数,再使用函数 calc_scat 计算出目标散射回波合成的信号
%设置动态聚焦扫描线起始点 :
xdc_center_focus(xmit_aperture,[0 0 0]);
xdc_center_focus(receive_aperture,[0 0 0]);
%按顺序分别计算每条扫描线的发射延时参数,以前面指定的发射焦点位置为参考点来计算发射延时
%使用函数 xdc_focus_times 为发射换能器设置延时参数,用来控制发射波束。
%使用函数 xdc_apodization 设置发射的所有通道幅度加权系数,使用函数 calc_scat 计算出所有的发射和接收阵元共同作用产生的目标散射回波信号,把回波信号数据保存在 image_data。
for i=1:SL
sin_th(i)=sin(-45/180*pi)+(i-1)*d_th;
th=asin(sin_th(i));
focus_pt = [focal_depth * sin(th) 0 focal_depth*cos(th)];
delay_tx(i,:)=-1*(sqrt((channel_pos-focus_pt(1)).^2+focus_pt(3)^2)-focal_depth)/c;
toff_c=delay_tx(i,:);
xdc_focus_times(xmit_aperture,0,(toff_c));
xdc_apodization(xmit_aperture,0,apo_vector);
[v,t1]=calc_scat(xmit_aperture,receive_aperture, phantom_positions,phantom_amplitudes);
image_data(1:max(size(v)),i)=v;
times(i)=t1;
end
%最后对回波数据进行对齐处理、对数压缩和灰阶范围较正,显示的图像如图 4 所示。
min_sample=min(times)*fs;
max_sample=max(times)*fs;
[n,m]=size(image_data);
n=n+(max_sample-min_sample);
for i=1:SL
rf_env=abs(hilbert([zeros(round(times(i)*fs-min_sample,0),1);
image_data(:,i)]));
env(i,1:max(size(rf_env)))=rf_env';
end
env=env/max(max(env));
env=log(env+0.1);
env=env-min(min(env));
env=64*env/max(max(env));
figure;
image(env);
colormap(gray(64));
%释放为换能器分配的资源。
xdc_free (xmit_aperture) ;
xdc_free (receive_aperture) ;