Hi Margot,
If you are using the C++ code, the situation is slightly different. In this case, sensor_data
will contain one time trace for every grid point that forms part of the active elements of your transducer (rather than one time trace per element). If your transducer elements contain more than one grid point (which they normally will), then further processing is required to put the C++ output data in the correct format before using the scan_line
method. An additional method called combine_sensor_data
has been added to the kWaveTransducer
class ready for the next release. I have also copied a beta version of it below. You should add this to the "general class methods". After running the C++ simulation, you can then call sensor_data = transducer.combine_sensor_data(sensor_data)
.
Let me know if you have any problems,
Brad.
% function to average the individual time series recorded at each
% grid point of each transducer element (as returned by the C++
% code) and return a single time series per active transducer
% element (as returned by the MATLAB code)
function sensor_data_sum = combine_sensor_data(obj, sensor_data)
% check the data is the correct size
if size(sensor_data, 1) ~= (obj.number_active_elements * obj.element_width * obj.element_length)
error('The number of time series in the input sensor_data must match the number of grid points in the active tranducer elements.');
end
% get index of which element each time series belongs to
ind = obj.indexed_active_elements_mask(obj.indexed_active_elements_mask > 0);
% create empty output
sensor_data_sum = zeros(obj.number_active_elements, size(sensor_data, 2));
% check if an elevation focus is set
if isinf(obj.elevation_focus_distance)
% loop over time series and sum
for ii = 1:length(ind)
sensor_data_sum(ind(ii), :) = sensor_data_sum(ind(ii), :) + sensor_data(ii, :);
end
else
% get the elevation delay for each grid point of each
% active transducer element (this is given in units of grid
% points)
dm = obj.delay_mask(2);
dm = dm(obj.active_elements_mask ~= 0);
% loop over time series, shift and sum
for ii = 1:length(ind)
sensor_data_sum(ind(ii), 1:end - dm(ii)) = sensor_data_sum(ind(ii), 1:end - dm(ii)) + sensor_data(ii, 1 + dm(ii):end);
end
end
% divide by number of time series in each element
sensor_data_sum = sensor_data_sum .* (1/ (obj.element_width * obj.element_length));
end