Hi, I'm new to K-WAVE. I want to simulate the 2D propagation in three different mediums. I did it with two mediums without problems. When I define three mediums and run the simulation I receive the error:
"Error using waitbar (line 90) The second argument must be a message string or a handle to an existing waitbar." How can I solve it?
Thanks.
k-Wave
A MATLAB toolbox for the time-domain
simulation of acoustic wave fields
Wave propagation in three mediums
(7 posts) (3 voices)-
Posted 9 years ago #
-
Hi savpetr
The number of media should not change anything. The waitbar is only the bar which shows the progress of the computations. Could you post your code?
To define different media you can set heterogeneous maps of density, speed etc. in the variablesmedium.sound_speed
,medium.sound_speed
etc.Best regards,
AnthonyPosted 9 years ago # -
Hi Anthony,
Thank you for your answer. This is my code:
medium.sound_speed = 1250*ones(Nx, Ny);
medium.density = 835*ones(Nx, Ny);
medium.sound_speed(1:round(l1/dx),:) = 5850;
medium.density(1:round(l1/dx), :) = 7800;
medium.sound_speed(round(l2/dx):round(l3/dx), : ) = 341;
medium.density(round(l2/dx):round(l3/dx), : ) = 1.2;l1,l2 and l3 are the distances from the start of the grid.
Posted 9 years ago # -
Hi savpetr,
It seems correct to me. Anyway, I don't think that the error message you get come from your medium definition... Did you change anything else in the example? Could you post your complete code?
Anthony
PS : By the way, you seem to have very large differences in the density and sound speed, see related topics but it may cause (other) problems.
Posted 9 years ago # -
Hi Anthony,
this is my code:
clear all;
clc;% =========================================================================
% SIMULATION
% =========================================================================l1 = 0.01;
l2 = 0.08;
l3 = 0.01;
l_tot = l1 + l2 + l3;% create the computational grid
Nx = 128; % number of grid points in the x (row) direction
Ny = 128; % number of grid points in the y (column) direction
dx = l_tot/Nx; % grid point spacing in the x direction [m]
dy = dx; % grid point spacing in the y direction [m]
kgrid = makeGrid(Nx, dx, Ny, dy);% define the properties of the propagation medium
medium.sound_speed = 1250*ones(Nx, Ny);
medium.density = 835*ones(Nx, Ny);
medium.sound_speed(round((l1+l2)/dx):end,:) = 5850;
medium.density(round((l1+l2)/dx):end, :) = 7800;
medium.sound_speed(1:round(l1/dx), : ) = 341;
medium.density(1:round(l1/dx), : ) = 1.2;% create the time array
[kgrid.t_array, dt] = makeTime(kgrid, max(max(medium.sound_speed)));% define a single source point
source.u_mask = zeros(Nx, Ny);
source.u_mask(end - Nx/4, Ny/2) = 1;% define a time varying sinusoidal velocity source in the x-direction
source_freq = 0.25e6; % [Hz]
source_mag = 2/(min(min(medium.sound_speed))*min(min(medium.density)));
source.ux = -source_mag*sin(2*pi*source_freq*kgrid.t_array);% filter the source to remove high frequencies not supported by the grid
source.ux = filterTimeSeries(kgrid, medium, source.ux);% define a single sensor point
sensor.mask = zeros(Nx, Ny);
sensor.mask(Nx/2, Ny/2) = 1;% define the acoustic parameters to record
sensor.record = {'p', 'p_final'};% run the simulation
sensor_data = kspaceFirstOrder2D(kgrid, medium, source, sensor, 'PlotScale', [-0.5, 0.5]);I saw 'Monopole Point Source In A Homogeneous Propagation Medium Example'. Why this code doesn't work?
Posted 9 years ago # -
Hi savpetr,
You have both an instability and a plot scale issue. If you change the plot scale to
[-80, 80]
and the definition of the time array to:% create the time array CFL = 0.1; [kgrid.t_array, dt] = makeTime(kgrid, max(max(medium.sound_speed)), CFL);
your simulation should run.
Brad
Posted 9 years ago # -
Hi Brad,
Thank you so much. The code works.
Savino
Posted 9 years ago #
Reply
You must log in to post.