k-Wave Toolbox |

## Dipole Point Source In A Homogeneous Propagation Medium Example

On this page…
Overview Defining the time varying velocity source Running the simulation

### Overview

This example provides a simple demonstration of using k-Wave for the simulation and detection of a time varying pressure dipole source within a two-dimensional homogeneous propagation medium. It builds on the Monopole Point Source In A Homogeneous Propagation Medium Example.

- open the file in the MATLAB Editor
- run the file in MATLAB

Back to Top

### Defining the time varying velocity source

A time varying velocity source is defined analogous to the time varying pressure source encountered in the previous example. A binary matrix (i.e., a matrix of 1's and 0's with the same dimensions as the computational grid) is assigned to `source.u_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.ux` and `source.uz`. These can be defined independently, and may be a single time series (in which case it is applied to all source elements), or a matrix of time series following the source elements using MATLAB's standard column-wise linear matrix index ordering. In this example, a dipole is created by assigning a sinusoidal velocity input to a single source element. Note, to avoid numerical stabilities, 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.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;
    source_mag = 2/(medium.sound_speed*medium.density);
    source.ux = -source_mag*sin(2*pi*source_freq*kgrid.t_array);

    % smooth the source
    source.ux = filterTimeSeries(kgrid, medium, source.ux);

Note, an acoustic dipole can also be created using a pressure source comprising of two adjacent grid points with their inputs out-of-phase. Higher order source patterns can similarly be created using combinations of pressure or velocity sources.

Back to Top

### Running the simulation

A plot of the input time series driving the source element along with the acoustic pressure recorded at the sensor element is given below. By scaling the magnitude of the velocity input by the impedance of the medium, the magnitude of the pressure recorded at the sensor is the same as in the previous example. 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);

Back to Top

© 2009, 2010, 2011 Bradley Treeby and Ben Cox.