k-Wave Toolbox |
![]() ![]() |
On this page… |
---|
This example provides a short comparison between the simulation functions kspaceFirstOrder2D
and kspaceSecondOrder
. It builds on the Homogeneous Propagation Medium and Using A Binary Sensor Mask examples.
In the previous examples, simulations are performed using the function kspaceFirstOrder2D
. However, simulations of initial value problems in homogeneous media can also be performed using the function kspaceSecondOrder
. The first-order codes are based on the sequential calculation of the acoustic pressure, particle velocity, and acoustic density using first-order constitutive acoustic equations (the equations of motion, continuity, and state). For a homogeneous medium, these equations can also be combined into a second-order acoustic wave equation and solved using Green's function methods. The second-order code is based on the numerical evaluation of an exact Green's function solution. For initial value problems in homogeneous media, the two approaches give the same results.
In comparison, the function kspaceSecondOrder
has slightly less functionality than its first-order counterparts (kspaceFirstOrder1D
, kspaceFirstOrder2D
, and kspaceFirstOrder3D
). For example, it only supports binary sensor masks and does not support time varying sources or the full range of visualisation options. However, it has greated computational efficiency and also allows an initial pressure gradient to be defined (see Setting An Initial Pressure Gradient Example).
The second order code does not implement an absorbing boundary layer (see Controlling The Absorbing Boundary Layer Example for more details on the perfectly matched layer used in kspaceFirstOrder2D
). Instead, to delay the appearance of wave wrapping, it extends the size of the computational grid. Although this reduces the computational efficiency, it allows the exactness of the solution to be maintained. The grid extension is controlled by setting the optional input parameter 'ExpandGrid'
to true
. Note, the wrapped waves will still appear if the simulation time is longer than the time it takes for the waves to propagate through the grid extension.
The function kspaceSecondOrder
(this is used for all dimensions) takes the same input structures as the first order simulation functions. For example, to run the Homogeneous Propagation Medium Example, the Cartesian sensor mask is first converted to a binary sensor mask using cart2grid
, and then kspaceSecondOrder
is called with 'ExpandGrid'
set to true
.
% convert the cartesian sensor mask to a binary sensor mask sensor.mask = cart2grid(kgrid, sensor.mask); % run the simulation using the second order code sensor_data = kspaceSecondOrder(kgrid, medium, source, sensor, 'ExpandGrid', true);
When the medium is not absorbing and no compensation for wave wrapping is used, the two simulation functions give identical results to almost machine precision. A plot of the signals recorded at the first sensor position and the difference between them is given below (set example_number = 1
within the example m-file).
When the medium is absorbing and wave wrapping is mitigated using a perfectly matched layer, there is a small error in the numerical result computed using kspaceFirstOrder2D
. A plot of the signals recorded at the first sensor position and the difference between them is given below (set example_number = 4
within the example m-file)
![]() |
Defining a Gaussian Sensor Frequency Response | Setting An Initial Pressure Gradient | ![]() |
© 2009, 2010, 2011 Bradley Treeby and Ben Cox.