Just an example of the matlab error with kWaveTransducer/delay_mask making inactive elements in the middle of the array:
clear all;
% close all;
clearvars;
% ========================================================================
% simulation settings
% ========================================================================
DATA_CAST = 'single'; % set to 'single' or 'gpuArray-single' to speed up computations
MASK_PLANE = 'xy'; % set to 'xy' or 'xz' to generate the beam pattern in different planes
% MASK_PLANE = 'xz';
filename = strcat('k-Wave-Log-',strrep(strrep(char(datetime),':','-'),' ','-'));
nfig=0;
%% ========================================================================
% parameters
% =========================================================================
f0 = 5.2e6; % transducer center frequency [Hz]
c0 = 1480; % sound speed in medium [m/s]
rho0 = 1000; % density of medium [kg/m^3]
p0 = 0.25e6; % pressure at front face [Pa]
nelmt = 192; % number of elements
kerf = 0.0230/1000; % kerf of element [m]
width = 0.2/1000; % width of element [m]
lengt = 6/1000; % length of element [m]
focus_ele = 40e-3;%20e-3; %1e12/1000;%80e-3; % focus distance in elevation [m]
focus_azy = 20e-3;%20e-3; %1e12/1000;%300e-3; % focus distance in azymuth [m]
steer_ang = 0; % steering angle [°]
depth = 40e-3; % depth of field [m]
nper = 2;%4;%10; % number of periods for excitation
param.dx = 1e-4;%c0/f0/6;% 1*kerf; %width/4; %1*kerf; % cell size of grid [m]
%% ========================================================================
% DEFINE THE ULTRASOUND TRANSDUCER
% =========================================================================
transducer.number_elements = nelmt;
transducer.element_width = round(width/param.dx); % [grid points]
transducer.element_length = round(lengt/param.dx); % [grid points]
transducer.element_spacing = round(kerf/param.dx); % [grid points]
transducer.radius = Inf; % [m] -> currently only Inf is supported
transducer.sound_speed = c0;
transducer.focus_distance = focus_azy;
transducer.steering_angle = steer_ang;
transducer.elevation_focus_distance = focus_ele;
transducer.transmit_apodization = 'Rectangular';
transducer.receive_apodization = 'Rectangular';
% transducer.active_elements = ones(transducer.number_elements,1);
transducer_width = transducer.number_elements * transducer.element_width ...
+ (transducer.number_elements - 1) * transducer.element_spacing; % calculate the width of the transducer in grid points
%% ========================================================================
% DEFINE THE K-WAVE GRID
% =========================================================================
%create the grid
NX = ceil(depth/param.dx)+2;
NY = transducer.number_elements*(transducer.element_width+transducer.element_spacing)+2;
NZ = transducer.element_length+2;
% set the size of the perfectly matched layer (PML)
PML_X_SIZE = 10; % [grid points]
PML_Y_SIZE = 10; % [grid points]
PML_Z_SIZE = 10; % [grid points]
% set total number of grid points not including the PML
% Nx = NX;
Nx = NX;
Ny = NY;
Nz = NZ;
% set desired grid size in the x-direction not including the PML
x = depth; % [m]
% spacing between the grid points
dx = param.dx; % [m]
dy = dx; % [m]
dz = dx; % [m]
% create the k-space grid
kgrid = kWaveGrid(Nx, dx, Ny, dy, Nz, dz);
disp(['grid size = [',num2str(Nx),',',num2str(Ny),',',num2str(Nz),'] = ',num2str(Nx*Ny*Nz),' cells']);
%% ========================================================================
% DEFINE THE MEDIUM PARAMETERS
% =========================================================================
% define the properties of the propagation medium
%
% If the nonlinearity parameter medium.BonA is not set, the simulation is assumed to be linear,
% and linear governing equations are solved. Similarly, if the absorption parameters medium.alpha_coeff
% and medium.alpha_power are not set, the simulation is assumed to be lossless
%% water
medium.sound_speed = c0;
medium.density = rho0;
% medium.BonA = 4.96; % non-linearity parameter
% medium.alpha_coeff = 2.17e-3; % power law absorption coefficient [dB/MHz^y/cm]
% medium.alpha_power = 2;
% create the time array
t_end = 1.0*Nx*dx/c0+(nper+1)/f0; % [s]
kgrid.t_array = makeTime(kgrid,medium.sound_speed,[], t_end);
disp(['Fs = ',num2str(round(1/kgrid.dt)/1e6),' MHz']);
%% ========================================================================
% DEFINE THE INPUT SIGNAL
% =========================================================================
source_strength = p0;
signal = p0/rho0/c0*sin(2*pi*f0*kgrid.t_array);
gate = find(kgrid.t_array <= nper/f0);
if (mod(length(gate),2) ~= 0)
gate = gate(1:end-1);
end
window = zeros(size(kgrid.t_array));
window(gate) = tukeywin(length(gate),0.5); %hanning(length(gate));
signal = signal.*window;
input_signal = signal;
figure
tps = (0:length(input_signal)-1)*kgrid.dt;
plot(tps*1e6,input_signal);
grid
title('front face');
xlabel('time (µs)');
ylabel('normal velocity (m/s)');
%% ========================================================================
% SET THE ULTRASOUND TRANSDUCER
% =========================================================================
%use this to position the transducer in the middle of the computational grid
transducer.position = round([1, Ny/2 - transducer_width/2, Nz/2 - transducer.element_length/2]);
% define the transducer elements that are currently active
% transducer.active_elements = ones(transducer.number_elements, 1);
% Inactive center of the array
transducer.active_elements = zeros(transducer.number_elements, 1);
transducer.active_elements(1:64) = 1;
transducer.active_elements(129:192) = 1;
% append input signal used to drive the transducer
transducer.input_signal = input_signal;
% create the transducer using the defined settings
transducer = kWaveTransducer(kgrid, transducer);
% print out transducer properties
transducer.properties;
%display the transducer using a 3D voxel plot
transducer.plot;
%% =========================================================================
% DEFINE SENSOR MASK
% =========================================================================
% define a sensor mask through the central plane
sensor.mask = zeros(Nx, Ny, Nz);
switch MASK_PLANE
case 'xy'
% define mask
sensor.mask(:, :, (Nz)/2) = 1;
% store y axis properties
Nj = Ny;
j_vec = kgrid.y_vec;
j_label = 'y';
case 'xz'
% define mask
sensor.mask(:, (Ny)/2, :) = 1;
% store z axis properties
Nj = Nz;
j_vec = kgrid.z_vec;
j_label = 'z';
end
% set the record mode such that only the peak values are stored
sensor.record = {'p_min', 'p_max'};
%% ========================================================================
% RUN THE SIMULATION
% =========================================================================
source = transducer;
% set the input settings
input_args = {'DisplayMask', transducer.all_elements_mask, ...
'PMLInside', false, 'PlotPML', false, 'PMLSize', [PML_X_SIZE, PML_Y_SIZE, PML_Z_SIZE], ...
'DataCast', DATA_CAST, 'DataRecast', true, 'PlotScale', [-1, 1] * source_strength};
% run the simulation
sensor_data = kspaceFirstOrder3D(kgrid, medium, transducer, sensor, input_args{:});
At this phase a have matlab error:
Index exceeds the number of array elements (128).
Error in kWaveTransducer/delay_mask (line 985)
mask(active_elements_index) = delay_times(indexed_active_elements_mask_copy(active_elements_index));
Error in kWaveTransducer/get.input_signal (line 578)
delay_mask = obj.delay_mask;
Error in kspaceFirstOrder_inputChecking (line 1166)
transducer_input_signal = source.input_signal;
Error in kspaceFirstOrder3D (line 574)
kspaceFirstOrder_inputChecking;
Error in kWave_GE9LD_2_test (line 251)
sensor_data = kspaceFirstOrder3D(kgrid, medium, transducer, sensor, input_args{:});