<?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: Changing CFL or reference speed to make simulation stable.</title>
		<link>http://www.k-wave.org/forum/topic/changing-cfl-or-reference-speed-to-make-simulation-stable</link>
		<description>Support for the k-Wave MATLAB toolbox</description>
		<language>en-US</language>
		<pubDate>Tue, 12 May 2026 22:28:58 +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/changing-cfl-or-reference-speed-to-make-simulation-stable" rel="self" type="application/rss+xml" />

		<item>
			<title>bencox on "Changing CFL or reference speed to make simulation stable."</title>
			<link>http://www.k-wave.org/forum/topic/changing-cfl-or-reference-speed-to-make-simulation-stable#post-8568</link>
			<pubDate>Wed, 13 Jul 2022 16:52:26 +0000</pubDate>
			<dc:creator>bencox</dc:creator>
			<guid isPermaLink="false">8568@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hi sgrghimire,&#60;/p&#62;
&#60;p&#62;I'm not sure what you mean by reference sound speed. &#60;code&#62;medium.sound_speed_ref&#60;/code&#62; is an optional parameter in &#60;code&#62;kspaceFirstOrder2D&#60;/code&#62; but you don't seem to be using that. &#60;/p&#62;
&#60;p&#62;If you have a large impedance mismatch, then the simulation may need many points per wavelength for the simulation to converge. In some cases, it may be possible to make the smaller values of density or sound speed unrealistically large without affecting the reflection coefficient very much at all. This can be a useful trick to reduce the number of points per wavelength required.&#60;/p&#62;
&#60;p&#62;Best wishes&#60;br /&#62;
Ben
&#60;/p&#62;</description>
		</item>
		<item>
			<title>sgrghimire on "Changing CFL or reference speed to make simulation stable."</title>
			<link>http://www.k-wave.org/forum/topic/changing-cfl-or-reference-speed-to-make-simulation-stable#post-8526</link>
			<pubDate>Thu, 05 May 2022 19:05:30 +0000</pubDate>
			<dc:creator>sgrghimire</dc:creator>
			<guid isPermaLink="false">8526@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;I was simulating a structure suspended in air with varying density (o.5, 1, 1.5, 2 gm/cm3) and speed (1.2 power of density) . I was changing value of CFL to make simulations stable when value density value was at 1.5 and 2 as it started to break, without changing it. However, I noticed that I could also change the reference sound speed to do the same thing, to make the simulation more stable. Interestingly, it decreases computational time drastically.&#60;/p&#62;
&#60;p&#62;1. Changing Ref sound speed: 1500 m/s, computing time: 9 mins.&#60;br /&#62;
2. Changing CFL to 0.04, computing time: 1hr 1 minutes (when CFL is changed, reference speed changes automatically to 577 m/s.)&#60;/p&#62;
&#60;p&#62;I calculated transmission loss in both cases. In case 1, I am getting 80 dB with formula used in the code. In case 2, I am getting the same value 0f 80 dB.&#60;br /&#62;
Does this mean changing ref speed is more efficient than CFL?&#60;br /&#62;
Any insight on this would be much appreciated. Thank you.&#60;/p&#62;
&#60;p&#62;Here is my code.&#60;/p&#62;
&#60;p&#62;clearvars;&#60;br /&#62;
close all;&#60;/p&#62;
&#60;p&#62;% create the computational grid&#60;br /&#62;
Nx = 3032 ;&#60;br /&#62;
Ny = 1496;&#60;br /&#62;
dx = 6.6e-06;&#60;br /&#62;
dy = dx;&#60;br /&#62;
kgrid = kWaveGrid(Nx, dx, Ny, dy);&#60;/p&#62;
&#60;p&#62;%load image&#60;br /&#62;
img1 = loadImage('1.bmp');  %https://i.imgur.com/hmBLu0q.png&#60;/p&#62;
&#60;p&#62;%resize&#60;br /&#62;
img1 = imbinarize(resize(img1, [Nx, Ny]));&#60;br /&#62;
img_indices1 = find(img1 ==1);&#60;/p&#62;
&#60;p&#62;% define the medium properties&#60;br /&#62;
%Medium: Air&#60;br /&#62;
medium.density = 10* ones(Nx, Ny); % [kg/m^3]&#60;br /&#62;
medium.sound_speed = 330*ones(Nx, Ny); % [m/s]&#60;br /&#62;
medium.alpha_coeff = 1.64 * ones(Nx,Ny);&#60;br /&#62;
medium.alpha_power = 2;&#60;br /&#62;
medium.BonA = 20* ones(Nx,Ny);&#60;/p&#62;
&#60;p&#62;% create the time array&#60;br /&#62;
cfl = 0.05;&#60;br /&#62;
t_end = 0.5e-4;   % [s]&#60;br /&#62;
kgrid.makeTime(max(medium.sound_speed(:)), cfl);&#60;/p&#62;
&#60;p&#62;% define source mask for a linear transducer with an odd number of elements&#60;br /&#62;
x_offset = 50;          % [grid points]&#60;br /&#62;
sensor_start = round(Ny *0.1);&#60;br /&#62;
sensor_end = round(Ny*0.9);&#60;br /&#62;
source.p_mask = makeLine(Nx, Ny, [1 sensor_start], [1 sensor_end]);&#60;/p&#62;
&#60;p&#62;% define the properties of the tone burst used to drive the transducer&#60;br /&#62;
sampling_freq = 1/kgrid.dt;     % [Hz]&#60;br /&#62;
tone_burst_freq = 0.5e6;          % [Hz]&#60;br /&#62;
tone_burst_cycles = 3;&#60;br /&#62;
source_strength = 1;            %[Pa]&#60;/p&#62;
&#60;p&#62;%Appending the source&#60;br /&#62;
source.p = source_strength * toneBurst(sampling_freq, tone_burst_freq, tone_burst_cycles);&#60;/p&#62;
&#60;p&#62;%Sensor&#60;br /&#62;
x_offset1 = round(Nx*0.4); % [grid points]&#60;br /&#62;
x_offset2 = round(Nx*0.6);&#60;br /&#62;
width = 10; % [grid points]&#60;br /&#62;
sensor.mask = zeros(Nx, Ny);&#60;br /&#62;
sensor.mask(x_offset1, Ny/2 - width/2 + 1:Ny/2 + width/2) = 1;&#60;br /&#62;
sensor.mask(x_offset2, Ny/2 - width/2 + 1:Ny/2 + width/2) = 1;&#60;/p&#62;
&#60;p&#62;% define the frequency response of the sensor elements&#60;br /&#62;
center_freq = 0.5e6;      % [Hz]&#60;br /&#62;
bandwidth = 80;         % [%]&#60;br /&#62;
sensor.frequency_response = [center_freq, bandwidth];&#60;/p&#62;
&#60;p&#62;% assign the input options&#60;br /&#62;
input_args = { 'PlotPML', false,'PlotLayout', false...&#60;br /&#62;
    'DataCast', 'gpuArray-single', 'PMLInside',false,...&#60;br /&#62;
        'RecordMovie', false, 'MovieName', 'example_movie',...&#60;br /&#62;
        'MovieProfile', 'MPEG-4', 'MovieArgs', {'FrameRate', 10} };&#60;/p&#62;
&#60;p&#62;counter = 0;&#60;/p&#62;
&#60;p&#62;for i = 0.5:0.5:2&#60;/p&#62;
&#60;p&#62;    clear sensor_data;&#60;/p&#62;
&#60;p&#62;    %Defining properties of structure as scaling function&#60;/p&#62;
&#60;p&#62;    medium.density(img_indices1) = i*100;&#60;br /&#62;
    a = medium.density(img_indices1);&#60;br /&#62;
    medium.sound_speed(img_indices1)= a .^ 1.2;&#60;br /&#62;
    b = mean(medium.sound_speed(img_indices1));&#60;br /&#62;
    medium.alpha_coeff(img_indices1) = 10;&#60;br /&#62;
    medium.BonA(img_indices1)  = 400;&#60;br /&#62;
    %reference.sound_speed = 1500;&#60;/p&#62;
&#60;p&#62;    %run simulations&#60;br /&#62;
    [sensor_data] = kspaceFirstOrder2D(kgrid, medium, source, sensor, input_args{:});&#60;/p&#62;
&#60;p&#62;    % compute the amplitude spectra of the recorded time series&#60;br /&#62;
    [~, sensor_data1] = spect(sensor_data(1,:), 1/kgrid.dt);&#60;br /&#62;
    [f, sensor_data2] = spect(sensor_data(2,:), 1/kgrid.dt);&#60;/p&#62;
&#60;p&#62;    % applying gaussian filter to the data&#60;br /&#62;
    sigma = 3; % pick sigma value for the gaussian&#60;br /&#62;
    gaussFilter = gausswin(6*sigma + 1)';&#60;br /&#62;
    gaussFilter = gaussFilter / sum(gaussFilter); % normalize&#60;/p&#62;
&#60;p&#62;    filteredY1 = conv(sensor_data1, gaussFilter, 'same');&#60;br /&#62;
    filteredY2 = conv(sensor_data2, gaussFilter, 'same');&#60;/p&#62;
&#60;p&#62;    max_Y1 = max(filteredY1);&#60;br /&#62;
    max_Y2 = max(filteredY2);&#60;br /&#62;
    loss1 = -10* log((max_Y2)/ max_Y1) ;&#60;br /&#62;
    loss = round(loss1);&#60;br /&#62;
    disp(loss);&#60;/p&#62;
&#60;p&#62;    counter = counter +1;&#60;/p&#62;
&#60;p&#62;    %graphs&#60;br /&#62;
    subplot(2,2,counter);&#60;br /&#62;
    plot(f*1e-6, filteredY1, '-k',...&#60;br /&#62;
        f*1e-6, filteredY2, '-r', 'linewidth', 1);&#60;br /&#62;
    xlim([0 4]);&#60;br /&#62;
    xlabel('Frequency (MHz)', 'FontWeight', 'bold');&#60;br /&#62;
    ylabel('Amplitude (a.u)','FontWeight', 'bold');&#60;br /&#62;
    legend('Sensor-1', 'Sensor-2', 'Fontsize', 7,'FontWeight', 'bold','FontSize', 9);&#60;br /&#62;
    title(['Loss = ', num2str(loss), ' dB'], 'FontSize', 9, 'FontWeight', 'bold');&#60;/p&#62;
&#60;p&#62;end
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
