| k-Wave Toolbox |
|
| On this page… |
|---|
|
Creating the k-space grid and defining the medium properties |
This example provides a simple demonstration of using k-Wave for the simulation and detection of the pressure field generated by an initial pressure distribution within a one-dimensional heterogeneous propagation medium. It builds on the Homogeneous Propagation Medium and Heterogeneous Propagation Medium examples.
Simulations in one-dimension are performed in an analogous fashion to those in two-dimensions. The medium discretisation is again performed by makeGrid using the inputs for a single dimension. The properties of a heterogeneous acoustic propagation medium are also given as one-dimensional arrays.
% create the computational grid Nx = 512; % number of pixels in the x (column) direction dx = 0.05e-3; % pixel width [m] kgrid = makeGrid(Nx, dx); % define the properties of the propagation medium medium.sound_speed = 1500*ones(Nx, 1); % [m/s] medium.sound_speed(1:round(Nx/3)) = 2000; % [m/s] medium.density = 1000*ones(Nx, 1); % [kg/m^3] medium.density(round(4*Nx/5):end) = 1500; % [kg/m^3]
As in two-dimensions, the initial pressure distribution is simply an array of arbitrary numeric values over the medium discretisation given by the k-space grid. Here a smoothly varying pressure function is created explicitly using a portion of a sinusoid.
% create initial pressure distribution using a smoothly shaped sinusoid x_pos = 280; % pixels width = 100; % pixels height = 1; in = 0:pi/(width/2):2*pi; source.p0 = [zeros(x_pos,1); ((height/2)*sin(in-pi/2)+(height/2)).'; zeros(Nx - x_pos - width - 1, 1)];
Again both Cartesian and binary sensor masks can be used to define the locations where the pressure field is recorded at each time-step. Here a Cartesian sensor mask with two points is explicitly defined.
% create a Cartesian sensor mask sensor.mask = [-10e-3, 10e-3]; % [mm]
The computation is invoked by running kspaceFirstOrder1D with the inputs defined above. To record long enough to capture the reflections, kgrid.t_array is explicitly created using the time step dt returned from makeTime. By default, a visualisation of the propagating wave-field and a status bar are displayed.
% use makeTime to determine a suitable dt [kgrid.t_array, dt] = makeTime(kgrid, medium.sound_speed); % replace t_array with a longer array to capture the reflections t_end = 2.5*kgrid.x_size/max(medium.sound_speed(:)); kgrid.t_array = 0:dt:t_end; % run the simulation sensor_data = kspaceFirstOrder1D(kgrid, medium, source, sensor, 'PlotLayout', true);
As the function runs, status updates and computational parameters are printed to the command line.
Running k-space simulation... start time: 09-Feb-2011 12:41:07 dt: 7.5ns, t_end: 31.995us, time steps: 4267 input grid size: 512 pixels (25.6mm) maximum supported frequency: 15MHz smoothing p0 distribution... precomputation completed in 0.57513s starting time loop... estimated simulation time 1.9342s... computation completed in 10.2944s
A plot of the initial pressure distribution, sensor mask, and medium properties (returned using 'PlotLayout' set to true) is given below.
When the time loop has completed, the function returns the recorded time series at each of sensor locations defined by sensor_mask, with the ordering again dependent on whether a Cartesian or binary sensor mask is used. A visualisation is given below.
|
Setting An Initial Pressure Gradient | Simulations In Three Dimensions | ![]() |
© 2009, 2010, 2011 Bradley Treeby and Ben Cox.