下载K-wave包
文件路径k-wave-toolbox-version-1.4\k-Wave\examples\example_pr_2D_TR_circular_sensor.m
matlab版本R2023b
下载之后 用matlab打开所在文件夹,然后将整个文件夹及其子文件夹添加到路径
因为版本原因 Imageload已经不再用了 所以改成imread
p0 = p0_magnitude * imread('EXAMPLE_source_two.bmp');
根据example_pr_2D_TR_circular_sensor.m文件改成声源是一个圆形的肿瘤,传感器只有三个,没有噪声的正演图,并绘制出三个传感器得到的data。
1. 肿瘤位置大小设置
% 定义肿瘤的半径和中心位置
tumor_radius = 1e-3; % 肿瘤半径 [m]
tumor_center_x = (Nx / 2); % 肿瘤中心 x 坐标
tumor_center_y = (Ny / 2); % 肿瘤中心 y 坐标
% 将圆形肿瘤的形状添加到初始压力分布中
for i = 1:Nx
for j = 1:Ny
% 计算当前点到肿瘤中心的距离
distance = sqrt((i - tumor_center_x)^2 + (j - tumor_center_y)^2);
% 如果距离小于或等于肿瘤半径,则将该点的压力设置为 1
if distance <= tumor_radius
p0(i, j) = 1;
end
end
end
2. 传感器个数
num_sensor_points = 3;
3. 删除反演的过程
4. 加入绘制sensor_data的图(注意 这里的sensor_data是一个矩阵,得转置一下才能让每行的数据生成一条曲线)
% plot the simulated sensor data
figure;
plot(sensor_data')
给出完整代码
% assign the grid size and create the computational grid
PML_size = 20; % size of the PML in grid points
Nx = 256 - 2 * PML_size; % number of grid points in the x direction
Ny = 256 - 2 * PML_size; % number of grid points in the y direction
x = 10e-3; % total grid size [m]
y = 10e-3; % total grid size [m]
dx = x / Nx; % grid point spacing in the x direction [m]
dy = y / Ny; % grid point spacing in the y direction [m]
kgrid = kWaveGrid(Nx, dx, Ny, dy);
% 定义肿瘤的半径和中心位置
tumor_radius = 1e-3; % 肿瘤半径 [m]
tumor_center_x = (Nx / 2); % 肿瘤中心 x 坐标
tumor_center_y = (Ny / 2); % 肿瘤中心 y 坐标
% 创建一个与网格大小相同的零矩阵作为初始压力分布
p0 = zeros(Nx, Ny);
% 将圆形肿瘤的形状添加到初始压力分布中
for i = 1:Nx
for j = 1:Ny
% 计算当前点到肿瘤中心的距离
distance = sqrt((i - tumor_center_x)^2 + (j - tumor_center_y)^2);
% 如果距离小于或等于肿瘤半径,则将该点的压力设置为 1
if distance <= tumor_radius
p0(i, j) = 1;
end
end
end
% resize the input image to the desired number of grid points
p0 = resize(p0, [Nx, Ny]);
% smooth the initial pressure distribution and restore the magnitude
p0 = smooth(p0, true);
% assign to the source structure
source.p0 = p0;
% define the properties of the propagation medium
medium.sound_speed = 1500; % [m/s]
% define a centered Cartesian circular sensor
sensor_radius = 4.5e-3; % [m]
sensor_angle = 3*pi/2; % [rad]
sensor_pos = [0, 0]; % [m]
num_sensor_points = 3;
cart_sensor_mask = makeCartCircle(sensor_radius, num_sensor_points, sensor_pos, sensor_angle);
% assign to sensor structure
sensor.mask = cart_sensor_mask;
% create the time array
kgrid.makeTime(medium.sound_speed);
% set the input options
input_args = {'Smooth', false, 'PMLInside', false, 'PlotPML', false};
% run the simulation
sensor_data = kspaceFirstOrder2D(kgrid, medium, source, sensor, input_args{:});
% plot the initial pressure and sensor distribution
figure;
imagesc(kgrid.y_vec * 1e3, kgrid.x_vec * 1e3, p0 + cart2grid(kgrid, cart_sensor_mask), [-1, 1]);
colormap(getColorMap);
ylabel('x-position [mm]');
xlabel('y-position [mm]');
axis image;
% plot the simulated sensor data
figure;
plot(sensor_data')