<?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: Simulation of a flat reflector</title>
		<link>http://www.k-wave.org/forum/topic/simulation-of-a-flat-reflector</link>
		<description>Support for the k-Wave MATLAB toolbox</description>
		<language>en-US</language>
		<pubDate>Wed, 13 May 2026 00:42:23 +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/simulation-of-a-flat-reflector" rel="self" type="application/rss+xml" />

		<item>
			<title>rainbowwhale on "Simulation of a flat reflector"</title>
			<link>http://www.k-wave.org/forum/topic/simulation-of-a-flat-reflector#post-7374</link>
			<pubDate>Tue, 07 Apr 2020 03:24:36 +0000</pubDate>
			<dc:creator>rainbowwhale</dc:creator>
			<guid isPermaLink="false">7374@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;CFL number should be calculated using highest speed of sound.&#60;br /&#62;
By using highest speed of sound, current CFL number is about 4.13.&#60;br /&#62;
I tried using dt as 0.05/(PPP*F0) which has CFL number of about 0.2 and it worked.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Ryuji on "Simulation of a flat reflector"</title>
			<link>http://www.k-wave.org/forum/topic/simulation-of-a-flat-reflector#post-7363</link>
			<pubDate>Sat, 04 Apr 2020 02:07:08 +0000</pubDate>
			<dc:creator>Ryuji</dc:creator>
			<guid isPermaLink="false">7363@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hi, thanks for providing the great library.&#60;br /&#62;
I would like to simulate a small 40kHz-ultrasound transducer with a flat reflector in 3D.&#60;br /&#62;
When I set the medium heterogeneous (air and acrylic), I cannot see any propagation even in the air. Is this because of the large change in impedance? I would appreciate it if you could tell me how to make my code work.&#60;br /&#62;
Thanks advance!&#60;/p&#62;
&#60;p&#62;Best regards,&#60;br /&#62;
Ryuji&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% sorce code&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;clear all;&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% DEFINE LITERALS&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% select which code to run&#60;br /&#62;
%   1: MATLAB CPU code&#60;br /&#62;
%   2: MATLAB GPU code&#60;br /&#62;
%   3: C++ code&#60;br /&#62;
MODEL           = 2;&#60;/p&#62;
&#60;p&#62;% scale parameter (changes the resolution of the simulation)&#60;br /&#62;
SC              = 1;&#60;/p&#62;
&#60;p&#62;% grid parameters&#60;br /&#62;
PML_SIZE        = 10;                    % size of the perfectly matched layer [grid points]&#60;br /&#62;
Nx              = 128*SC - 2*PML_SIZE;   % number of grid points in the x direction&#60;br /&#62;
Ny              = 64*SC - 2*PML_SIZE;   % number of grid points in the y direction&#60;br /&#62;
Nz              = 64*SC - 2*PML_SIZE;   % number of grid points in the z direction&#60;/p&#62;
&#60;p&#62;% sampling parameters&#60;br /&#62;
PPW             = 10*SC;	% points per wavelength (this defines the grid size)&#60;br /&#62;
PPP             = 10*SC;    % points per period (this defines the CFL)&#60;br /&#62;
T_END           = 1e-3;     % total compute time [s] (this must be long enough to reach steady state)&#60;br /&#62;
RECORD_PERIODS  = 2;        % number of periods to record&#60;/p&#62;
&#60;p&#62;% medium parameters&#60;br /&#62;
C0              = 346;      % sound speed [m/s]&#60;br /&#62;
RHO0            = 1.2;      % density [kg/m^3]&#60;br /&#62;
CR              = 1.43e3;   % sound speed in the reflector [m/s]&#60;br /&#62;
RHOR            = 1.18e3;   % density of the reflector [kg/m^3]&#60;/p&#62;
&#60;p&#62;% source parameters&#60;br /&#62;
F0              = 40e3;     % source frequency [Hz]&#60;br /&#62;
SOURCE_RADIUS   = 5e-3;     % piston radius [m]&#60;br /&#62;
SOURCE_MAG      = 0.5e6;    % source pressure [Pa]&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% CREATE GRID&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% calculate the grid spacing based on the PPW and F0&#60;br /&#62;
dx = C0 / (PPW * F0);   % [m]&#60;br /&#62;
dt = 1 / (PPP*F0);      % [s]&#60;br /&#62;
SOURCE_RADIUS = SOURCE_RADIUS / dx;&#60;/p&#62;
&#60;p&#62;% calculate the CFL&#60;br /&#62;
disp(['CFL = ' num2str(C0*dt/dx)]);&#60;/p&#62;
&#60;p&#62;% create the computational grid&#60;br /&#62;
kgrid = makeGrid(Nx, dx, Ny, dx, Nz, dx);&#60;/p&#62;
&#60;p&#62;% create the time array&#60;br /&#62;
kgrid.t_array = 0:dt:T_END;&#60;/p&#62;
&#60;p&#62;% assign medium properties&#60;br /&#62;
% medium.sound_speed = C0;&#60;br /&#62;
% medium.density = RHO0;&#60;br /&#62;
medium.sound_speed = C0 * ones(Nx, Ny, Nz);&#60;br /&#62;
medium.density = RHO0 * ones(Nx, Ny, Nz);&#60;br /&#62;
% assign reflector properties&#60;br /&#62;
medium.sound_speed(Nx, :, :) = CR;&#60;br /&#62;
medium.density(Nx, :, :) = RHOR;&#60;br /&#62;
% assign the reference sound speed to the background medium&#60;br /&#62;
% medium.sound_speed_ref = C0;&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% CREATE SOURCE&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% create piston source mask&#60;br /&#62;
piston = makeDisc(Ny, Nz, Ny/2, Nz/2, SOURCE_RADIUS);&#60;br /&#62;
source.p_mask = zeros(Nx, Ny, Nz);&#60;br /&#62;
source.p_mask(1, :, :) = piston;&#60;/p&#62;
&#60;p&#62;% create time varying source&#60;br /&#62;
source.p = SOURCE_MAG * sin(2*pi*F0*kgrid.t_array);&#60;/p&#62;
&#60;p&#62;% filter source with up-ramp&#60;br /&#62;
ramp_length = round((2*pi/F0)/dt);&#60;br /&#62;
ramp = (-cos( (0:(ramp_length-1))*pi/ramp_length ) + 1)/2;&#60;br /&#62;
source.p(1:ramp_length) = ramp .* source.p(1:ramp_length);&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% CREATE SENSOR MASK&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% set sensor mask to record central axis, not including the source point&#60;br /&#62;
% sensor.mask = zeros(Nx, Ny, Nz);&#60;br /&#62;
% sensor.mask(2:end, Ny/2, Nz/2) = 1;&#60;br /&#62;
sensor.mask = [2, 1, Nz/2, Nx, Ny, Nz/2].';&#60;/p&#62;
&#60;p&#62;% record the maximum pressure&#60;br /&#62;
sensor.record = {'p', 'p_rms'};&#60;/p&#62;
&#60;p&#62;% average only the final few periods when the field is in steady state&#60;br /&#62;
sensor.record_start_index = kgrid.Nt - RECORD_PERIODS*PPP + 1;&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% RUN k-WAVE SIMULATION&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% run code&#60;br /&#62;
switch MODEL&#60;br /&#62;
    case 1&#60;br /&#62;
        % MATLAB CPU&#60;br /&#62;
        sensor_data = kspaceFirstOrder3D(kgrid, medium, source, sensor, ...&#60;br /&#62;
            'DataCast', 'single', 'PMLInside', false, ...&#60;br /&#62;
            'DisplayMask', source.p_mask, 'PlotScale', [-1, 1]*SOURCE_MAG);&#60;br /&#62;
    case 2&#60;br /&#62;
        % MATLAB GPU&#60;br /&#62;
        sensor_data = kspaceFirstOrder3D(kgrid, medium, source, sensor, ...&#60;br /&#62;
            'DataCast', 'gpuArray-single', 'PMLInside', false, ...&#60;br /&#62;
            'DisplayMask', source.p_mask, 'PlotScale', [-1, 1]*SOURCE_MAG);&#60;br /&#62;
    case 3&#60;br /&#62;
        % C++&#60;br /&#62;
        sensor_data = kspaceFirstOrder3DC(kgrid, medium, source, sensor, 'PMLInside', false);&#60;/p&#62;
&#60;p&#62;    otherwise&#60;/p&#62;
&#60;p&#62;end&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% ANALYTICAL SOLUTION&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% calculate the wavenumber&#60;br /&#62;
k = 2*pi*F0./C0;&#60;/p&#62;
&#60;p&#62;% define radius and axis&#60;br /&#62;
a = SOURCE_RADIUS*dx;&#60;br /&#62;
x = (kgrid.x_vec(2:end, :) - min(kgrid.x_vec(:)));&#60;/p&#62;
&#60;p&#62;% calculate the analytical solution for a piston in an infinite baffle&#60;br /&#62;
% for comparison (Eq 5-7.3 in Pierce)&#60;br /&#62;
r_a = sqrt(x.^2 + a^2);&#60;br /&#62;
p_ref = SOURCE_MAG*abs(-2i*exp(1i*k*(x+r_a)/2).*sin((k*r_a - k*x)/2));&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% VISUALISATION&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% plot the pressure along the focal axis of the piston&#60;br /&#62;
figure;&#60;br /&#62;
plot(sensor_data.p(end,:), 'bx');&#60;/p&#62;
&#60;p&#62;img = gather(sensor_data.p_rms);&#60;br /&#62;
image(img, 'CDataMapping', 'scaled')&#60;br /&#62;
daspect([1 1 1])&#60;br /&#62;
colormap default&#60;br /&#62;
colorbar
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
