k-Wave Toolbox |
![]() ![]() |
On this page… |
---|
This example provides a simple demonstration of using k-Wave for the simulation and detection of a time varying pressure source within a two-dimensional homogeneous propagation medium. It builds on the Homogeneous Propagation Medium Example.
In the Initial Value Problem examples, the initial pressure distribution is defined by assigning the source values to source.p0
. To define a time varying pressure source, both a source mask (which defines which grid points belong to the source) and a time varying source input must be assigned. The source mask is defined by assigning a binary matrix (i.e., a matrix of 1's and 0's with the same dimensions as the computational grid) to source.p_mask
where the 1's represent the grid points that form part of the source. The time varying input signal is then assigned to source.p
which is indexed as source.p(source_point_index, time_index)
. The source can have any number of time points (it doesn't need to be the same length as kgrid.t_array
) and can be defined as either a single time series (in which case it is applied to all of the source points), or a matrix of time series following the source points using MATLAB's standard column-wise linear matrix index ordering. For example, if source.p_mask
is defined as
source.p_mask = 0 1 0 1 0 1 1 0 1 0 1 0
the ordering of the source points within source.p(source_point_index, time_index)
would follow
0 3 0 1 0 5 2 0 6 0 4 0
In this example a sinusoidal input is assigned to a single source element to create an acoustic monopole. The remaining input structures are defined in the same way as in previous examples. Note, to avoid numerical instabilities, the input should first be filtered using filterTimeSeries
(see the Filtering A Delta Function Input Signal Example for more information).
% define a single source element source.p_mask = zeros(Nx, Ny); source.p_mask(end - Nx/4, Ny/2) = 1; % define a time varying sinusoidal source source_freq = 0.25e6; % [Hz] source_mag = 2; % [au] source.p = source_mag*sin(2*pi*source_freq*kgrid.t_array); % smooth the source source.p = filterTimeSeries(kgrid, medium, source.p);
The simulation is again invoked by calling kspaceFirstOrder2D
.
A plot of the input time series driving the source element along with the acoustic pressure recorded at the sensor element is given below. The final pressure field within the computational domain can also be returned by assigning both the sensor_data
and field_data
output fields.
% run the simulation [sensor_data, field_data] = kspaceFirstOrder2D(kgrid, medium, source, sensor);
![]() |
Time Varying Source Problems | Dipole Point Source In A Homogeneous Propagation Medium | ![]() |
© 2009-2012 Bradley Treeby and Ben Cox.