I am trying to simulate a linear array which I can do for 3D case using the following example:
http://www.k-wave.org/documentation/example_at_linear_array_transducer.php
However, I was trying to modify it for 2D case as following:
clearvars;
% =========================================================================
% DEFINE LITERALS
% =========================================================================
% select which k-Wave code to run
% 1: MATLAB CPU code
% 2: MATLAB GPU code
% 3: C++ code
% 4: CUDA code
model = 2;
% medium parameters
c0 =1540; % sound speed [m/s]
cs1 = 5; % shear wave speed
alpha0_p1 = 0.002; % absorption coefficient for water % [dB/(MHz^2 cm)]
alpha0_s1 = 0.002; % absorption coefficient for water (shear)
rho0 = 1000; % density [kg/m^3]
%define acrylic layer_tissue
cp2 = 2750; % Longitudinal wave speed
cs2 = 1150; % shear wave speed
rho2 = 1180; %density
%alpha0_p2 = 0.5; % absorption coefficient
%alpha0_s2 = 0.5; % absorption coefficient
alpha0_p2 = 1.58; % absorption coefficient % [dB/(MHz^2 cm)]
alpha0_s2 = 0.016; % absorption coefficient
% source parameters
source_f0 =1e6; % source frequency [Hz]
source_amp = 1e6; % source pressure [Pa]
source_cycles = 12; % number of toneburst cycles %12
source_focus = 35e-3; % focal length [m]
element_num = 90; % number of elements
element_width = 0.25e-3; % width [m]
element_length = 7e-3; % elevation height [m]
element_pitch = 0.3e-3; % pitch [m]0.03mm
% transducer position
translation = [0, 0];
rotation = [0, 0];
% grid parameters
grid_size_x = 40e-3; % [m]
grid_size_y = 20e-3; % [m]
% grid_size_z = 40e-3; % [m]
% computational parameters
ppw = 4; % number of points per wavelength
t_end = 35e-6; % total compute time [s]
cfl = 0.1; % CFL number
% =========================================================================
% RUN SIMULATION
% =========================================================================
% --------------------
% GRID
% --------------------
% calculate the grid spacing based on the PPW and F0
% dx = 2*c0 / (ppw * source_f0); % [m]
dx= 1.9250e-04;
% compute the size of the grid
Nx = roundEven(grid_size_x / dx);
Ny = roundEven(grid_size_y / dx);
% Nz = roundEven(grid_size_z / dx);
% create the computational grid
% kgrid = kWaveGrid(Nx, dx, Ny, dx, Nz, dx);
kgrid = kWaveGrid(Nx, dx, Ny, dx);
% create the time array
kgrid.makeTime(c0, cfl, t_end);
% --------------------
% SOURCE
% --------------------
% set indices for each element
if rem(element_num, 2)
ids = (1:element_num) - ceil(element_num/2);
else
ids = (1:element_num) - (element_num + 1)/2;
end
% set time delays for each element to focus at source_focus
time_delays = -(sqrt((ids .* element_pitch).^2 + source_focus.^2) - source_focus) ./ c0;
time_delays = time_delays - min(time_delays);
time_delays = 1*time_delays;
% create time varying source signals (one for each physical element)
source_sig = source_amp .* toneBurst(1/kgrid.dt, source_f0, source_cycles, 'SignalOffset', round(time_delays / kgrid.dt));
% create empty kWaveArray
karray = kWaveArray('BLITolerance', 0.05, 'UpsamplingRate', 10);
Unfortunately, I am getting the following error:
Expected input number 4, theta, to be an array with number of elements equal to 1.
Error in kWaveArray/addRectElement (line 715)
validateattributes(theta, {'numeric'}, {'finite', 'real', 'numel', theta_length}, 'addRectElement', 'theta', 4);
Any suggestion on resolving it is highly appreciated.