<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>k-Wave User Forum &#187; Topic: Transducer simulation with Imager</title>
		<link>http://www.k-wave.org/forum/topic/transducer-simulation-with-imager</link>
		<description>Support for the k-Wave MATLAB toolbox</description>
		<language>en-US</language>
		<pubDate>Wed, 13 May 2026 03:46:09 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://www.k-wave.org/forum/search.php</link>
		</textInput>
		<atom:link href="http://www.k-wave.org/forum/rss/topic/transducer-simulation-with-imager" rel="self" type="application/rss+xml" />

		<item>
			<title>Bradley Treeby on "Transducer simulation with Imager"</title>
			<link>http://www.k-wave.org/forum/topic/transducer-simulation-with-imager#post-4134</link>
			<pubDate>Sun, 24 Nov 2013 15:10:28 +0000</pubDate>
			<dc:creator>Bradley Treeby</dc:creator>
			<guid isPermaLink="false">4134@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hi nealmp,&#60;/p&#62;
&#60;p&#62;The line of code giving the error is used in the &#34;Simulating B-mode Ultrasound Images Example&#34; to increase the resolution of a 2D ultrasound image consisting of a series of scan lines. In your case, you only have a single scan line, so the 2D interpolation will generate an error.&#60;/p&#62;
&#60;p&#62;Brad.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>nealmp on "Transducer simulation with Imager"</title>
			<link>http://www.k-wave.org/forum/topic/transducer-simulation-with-imager#post-4131</link>
			<pubDate>Fri, 22 Nov 2013 19:00:04 +0000</pubDate>
			<dc:creator>nealmp</dc:creator>
			<guid isPermaLink="false">4131@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;So my objective with the simulation that I pulled together is to map out an image of a simulated environment using acoustic waves. In the code, I have a transducer, a couple of sensors and an object. I'm actually having trouble with a couple of things in the simulation, the first of which being that I'm not getting a reflection off my object. But my main concern involves the Imaging portion of the simulation. The error I'm hit with is displayed after the code, telling me basically that my vectors do not define a grid matching kgrid size. I'm not sure how to go about solving this error. Any help is appreciated. &#60;/p&#62;
&#60;p&#62;clear all;&#60;br /&#62;
close all;&#60;br /&#62;
clc&#60;/p&#62;
&#60;p&#62;% simulation settings&#60;br /&#62;
DATA_CAST = 'single';&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% DEFINE THE K-WAVE GRID&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% set the size of the perfectly matched layer (PML)&#60;br /&#62;
PML_X_SIZE = 20;            % [grid points]&#60;br /&#62;
PML_Y_SIZE = 10;            % [grid points]&#60;br /&#62;
PML_Z_SIZE = 10;            % [grid points]&#60;/p&#62;
&#60;p&#62;% set total number of grid points not including the PML&#60;br /&#62;
Nx = 64 - 2*PML_X_SIZE;    % [grid points]&#60;br /&#62;
Ny = 64 - 2*PML_Y_SIZE;    % [grid points]&#60;br /&#62;
Nz = 32 - 2*PML_Z_SIZE;     % [grid points]&#60;/p&#62;
&#60;p&#62;% set desired grid size in the x-direction not including the PML&#60;br /&#62;
x = 40e-3;                  % [m]&#60;/p&#62;
&#60;p&#62;% calculate the spacing between the grid points&#60;br /&#62;
dx = x/Nx;                  % [m]&#60;br /&#62;
dy = dx;                    % [m]&#60;br /&#62;
dz = dx;                    % [m]&#60;/p&#62;
&#60;p&#62;% create the k-space grid&#60;br /&#62;
kgrid = makeGrid(Nx, dx, Ny, dy, Nz, dz);&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% DEFINE THE MEDIUM PARAMETERS&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% define the properties of the propagation medium&#60;br /&#62;
medium.sound_speed = 1540;      % [m/s]&#60;br /&#62;
medium.density = 1000*ones(Nx,Ny,Nz);          % [kg/m^3]&#60;br /&#62;
medium.alpha_coeff = 0.75;      % [dB/(MHz^y cm)]&#60;br /&#62;
medium.alpha_power = 1.5;&#60;br /&#62;
medium.BonA = 6;&#60;/p&#62;
&#60;p&#62; object=makeBall(kgrid.Nx,kgrid.Ny,kgrid.Nz,kgrid.Nx/2,kgrid.Ny/2,kgrid.Nz/2,1);&#60;br /&#62;
 medium.sound_speed(object==1) = 150;&#60;br /&#62;
 medium.density(object==1) =720;&#60;/p&#62;
&#60;p&#62;for i=1:1:length(medium.alpha_coeff)&#60;/p&#62;
&#60;p&#62;    if(i==length(medium.alpha_coeff))&#60;br /&#62;
        medium.alpha_coeff = medium.alpha_coeff(i);&#60;br /&#62;
    end&#60;/p&#62;
&#60;p&#62;end &#60;/p&#62;
&#60;p&#62;for i=1:1:length(medium.sound_speed)&#60;/p&#62;
&#60;p&#62;    if(i==length(medium.sound_speed))&#60;br /&#62;
        medium.sound_speed = medium.sound_speed(i);&#60;br /&#62;
    end&#60;/p&#62;
&#60;p&#62;end&#60;/p&#62;
&#60;p&#62;for i=1:1:length(medium.density)&#60;/p&#62;
&#60;p&#62;    if(i==length(medium.density))&#60;br /&#62;
        medium.density = medium.density(i);&#60;br /&#62;
    end&#60;/p&#62;
&#60;p&#62;end&#60;/p&#62;
&#60;p&#62;% create the time array&#60;br /&#62;
t_end = 300e-6;                  % [s]&#60;br /&#62;
% kgrid.t_array = makeTime(kgrid, medium.sound_speed, [], t_end);&#60;br /&#62;
[kgrid.t_array, dt] = makeTime(kgrid, medium.sound_speed);&#60;br /&#62;
kgrid.t_array = 0:dt:t_end;&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% DEFINE THE INPUT SIGNAL&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% define properties of the input signal&#60;br /&#62;
source_strength = 1e6;          % [Pa]&#60;br /&#62;
tone_burst_freq = 0.5e6;        % [Hz]&#60;br /&#62;
tone_burst_cycles = 5;&#60;/p&#62;
&#60;p&#62;% create the input signal using toneBurst&#60;br /&#62;
input_signal = toneBurst(1/kgrid.dt, tone_burst_freq, tone_burst_cycles);&#60;/p&#62;
&#60;p&#62;% scale the source magnitude by the source_strength divided by the&#60;br /&#62;
% impedance (the source is assigned to the particle velocity)&#60;br /&#62;
input_signal = (source_strength./(medium.sound_speed*medium.density)).*input_signal;&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% DEFINE THE ULTRASOUND TRANSDUCER&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% physical properties of the transducer&#60;br /&#62;
transducer.number_elements = 25;    % total number of transducer elements&#60;br /&#62;
transducer.element_width = 1;       % width of each element [grid points]&#60;br /&#62;
transducer.element_length = 6;     % length of each element [grid points]&#60;br /&#62;
transducer.element_spacing = 0;     % spacing (kerf width) between the elements [grid points]&#60;br /&#62;
transducer.radius = inf;            % radius of curvature of the transducer [m]&#60;/p&#62;
&#60;p&#62;% calculate the width of the transducer in grid points&#60;br /&#62;
transducer_width = transducer.number_elements*transducer.element_width ...&#60;br /&#62;
    + (transducer.number_elements - 1)*transducer.element_spacing;&#60;/p&#62;
&#60;p&#62;% use this to position the transducer in the middle of the computational grid&#60;br /&#62;
transducer.position = round([1, Ny/2 - transducer_width/2, Nz/2 - transducer.element_length/2]);&#60;/p&#62;
&#60;p&#62;% properties used to derive the beamforming delays&#60;br /&#62;
transducer.sound_speed = 1540;              % sound speed [m/s]&#60;br /&#62;
transducer.focus_distance = Nx/4;          % focus distance [m]&#60;br /&#62;
transducer.elevation_focus_distance = 19e-3;% focus distance in the elevation plane [m]&#60;br /&#62;
transducer.steering_angle = 0;              % steering angle [degrees]&#60;/p&#62;
&#60;p&#62;% apodization&#60;br /&#62;
transducer.transmit_apodization = 'Rectangular';&#60;br /&#62;
transducer.receive_apodization = 'Rectangular';&#60;/p&#62;
&#60;p&#62;% define the transducer elements that are currently active&#60;br /&#62;
transducer.active_elements = zeros(transducer.number_elements, 1);&#60;br /&#62;
transducer.active_elements(6:20) = 1;&#60;/p&#62;
&#60;p&#62;% append input signal used to drive the transducer&#60;br /&#62;
transducer.input_signal = input_signal;&#60;/p&#62;
&#60;p&#62;% create the transducer using the defined settings&#60;br /&#62;
transducer = makeTransducer(kgrid, transducer);&#60;/p&#62;
&#60;p&#62;% print out transducer properties&#60;br /&#62;
transducer.properties;&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% DEFINE SENSOR MASK&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;%%%%ORIGINAL CODE%%%%%%%&#60;br /&#62;
% % create a binary sensor mask with four detection positions&#60;br /&#62;
% sensor.mask = zeros(Nx, Ny, Nz);&#60;br /&#62;
% sensor.mask([Nx/4, Nx/2, 3*Nx/4], Ny/2 - transducer_width/2, Nz/2 - transducer.element_length/2) = 1;&#60;/p&#62;
&#60;p&#62;% create a binary sensor mask with four detection positions&#60;br /&#62;
sensor.mask = zeros(Nx, Ny, Nz);&#60;br /&#62;
sensor.mask(1, [5, 40], Nz/2) = 1;&#60;br /&#62;
%sensor.mask(Nx/2, Ny/2, Nz/2) = 1;&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% RUN&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% set the input settings&#60;/p&#62;
&#60;p&#62;input_args = {'DisplayMask', transducer.all_elements_mask &#124; sensor.mask &#124; object...&#60;br /&#62;
    'PMLInside', false, 'PlotPML', false, 'PMLSize', [PML_X_SIZE, PML_Y_SIZE, PML_Z_SIZE], ...&#60;br /&#62;
    'PMLInside', false, 'DataCast', DATA_CAST, 'PlotScale', [-source_strength/2, source_strength/2]};&#60;/p&#62;
&#60;p&#62;% run the simulation&#60;br /&#62;
[sensor_data] = kspaceFirstOrder3D(kgrid, medium, transducer, sensor, input_args{:});&#60;/p&#62;
&#60;p&#62;% calculate the amplitude spectrum of the input signal and the signal&#60;br /&#62;
% recorded each of the sensor positions&#60;br /&#62;
[f_input, as_input] = spect([input_signal, zeros(1, 2*length(input_signal))], 1/kgrid.dt);&#60;br /&#62;
[f, as_1] = spect(sensor_data(1, :), 1/kgrid.dt);&#60;br /&#62;
[f, as_2] = spect(sensor_data(2, :), 1/kgrid.dt);&#60;br /&#62;
%[f, as_3] = spect(sensor_data(3, :), 1/kgrid.dt);&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% VISUALISATION&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% plot the input signal and its frequency spectrum&#60;br /&#62;
figure;&#60;br /&#62;
subplot(2, 1, 1), plot((0:kgrid.dt:(length(input_signal)-1)*kgrid.dt)*1e6, input_signal, 'k-');&#60;br /&#62;
xlabel('Time [\mus]');&#60;br /&#62;
ylabel('Input Particle Velocity [m/s]');&#60;br /&#62;
subplot(2, 1, 2), plot(f_input/1e6, as_input./max(as_input(:)), 'k-');&#60;br /&#62;
hold on;&#60;br /&#62;
line([tone_burst_freq, tone_burst_freq]/1e6, [0 1], 'Color', 'k', 'LineStyle', '--');&#60;br /&#62;
xlabel('Frequency [MHz]');&#60;br /&#62;
ylabel('Relative Amplitude Spectrum [au]');&#60;br /&#62;
f_max = medium.sound_speed / (2*dx);&#60;br /&#62;
set(gca, 'XLim', [0 f_max/1e6]);&#60;/p&#62;
&#60;p&#62;% plot the recorded time series&#60;br /&#62;
figure;&#60;br /&#62;
stackedPlot(kgrid.t_array*1e6, {'Sensor Position 1', 'Sensor Position 2', 'Sensor Position 3'}, sensor_data);&#60;br /&#62;
xlabel('Time [\mus]');&#60;/p&#62;
&#60;p&#62;% plot the corresponding amplitude spectrums&#60;br /&#62;
figure;&#60;br /&#62;
plot(f/1e6, as_1./max(as_1(:)), 'k-', f/1e6, as_2./max(as_1(:)), 'b-');&#60;br /&#62;
legend('Sensor Position 1', 'Sensor Position 2', 'Sensor Position 3');&#60;br /&#62;
xlabel('Frequency [MHz]');&#60;br /&#62;
ylabel('Normalised Amplitude Spectrum [au]');&#60;br /&#62;
f_max = medium.sound_speed / (2*dx);&#60;br /&#62;
set(gca, 'XLim', [0 f_max/1e6]);&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% IMAGE PROCESSING&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% create radius variable assuming that t0 corresponds to the middle of the&#60;br /&#62;
% input signal&#60;br /&#62;
t0 = length(input_signal)*kgrid.dt/2;&#60;br /&#62;
r = ( (1:length(kgrid.t_array))*kgrid.dt/2 - t0);    % [m]&#60;br /&#62;
% create time gain compensation function based on attenuation value,&#60;br /&#62;
% transmit frequency, and round trip distance&#60;br /&#62;
tgc_alpha = 0.25;		% [dB/(MHz cm)]&#60;br /&#62;
tgc = exp(2*tgc_alpha*tone_burst_freq/1e6*r*100);&#60;br /&#62;
% apply the time gain compensation to each of the scan lines&#60;br /&#62;
scan_lines = bsxfun(@times, tgc, transducer.scan_line(sensor_data));&#60;/p&#62;
&#60;p&#62;% filter the scan lines using both the transmit frequency and the second harmonic&#60;br /&#62;
scan_lines_fund = gaussianFilter(scan_lines, 1/kgrid.dt, tone_burst_freq, 100, true);&#60;br /&#62;
scan_lines_harm = gaussianFilter(scan_lines, 1/kgrid.dt, 2*tone_burst_freq, 30, true);&#60;/p&#62;
&#60;p&#62;% envelope detection&#60;br /&#62;
scan_lines_fund = envelopeDetection(scan_lines_fund);&#60;br /&#62;
scan_lines_harm = envelopeDetection(scan_lines_harm);&#60;/p&#62;
&#60;p&#62;% normalised log compression&#60;br /&#62;
compression_ratio = 3;&#60;br /&#62;
scan_lines_fund = logCompression(scan_lines_fund, compression_ratio, true);&#60;br /&#62;
scan_lines_harm = logCompression(scan_lines_harm, compression_ratio, true);&#60;/p&#62;
&#60;p&#62;length(scan_lines_fund)&#60;br /&#62;
length(kgrid)&#60;/p&#62;
&#60;p&#62;% upsample the image using linear interpolation&#60;br /&#62;
scale_factor = 2;&#60;br /&#62;
scan_lines_fund = interp2(1:kgrid.Nt, (1:2).', scan_lines_fund, 1:kgrid.Nt, (1:1/scale_factor:2).');&#60;br /&#62;
scan_lines_harm = interp2(1:kgrid.Nt, (1:2).', scan_lines_harm, 1:kgrid.Nt, (1:1/scale_factor:2).');&#60;/p&#62;
&#60;p&#62;mat2gray(scan_lines_fund)&#60;/p&#62;
&#60;p&#62;%end program&#60;/p&#62;
&#60;p&#62;The Error:&#60;/p&#62;
&#60;p&#62;Error using griddedInterpolant&#60;br /&#62;
The grid vectors do not define a grid of points that match the given values.&#60;/p&#62;
&#60;p&#62;Error in interp2/makegriddedinterp (line 214)&#60;br /&#62;
            F = griddedInterpolant(varargin{:});&#60;/p&#62;
&#60;p&#62;Error in interp2 (line 127)&#60;br /&#62;
        F = makegriddedinterp({X, Y}, V, method,extrap);&#60;/p&#62;
&#60;p&#62;Error in example_us_defining_transducer_test (line 319)&#60;br /&#62;
scan_lines_fund = interp2(1:kgrid.Nt, (1:2).', scan_lines_fund, 1:kgrid.Nt,&#60;br /&#62;
(1:1/scale_factor:2).');
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
