k-Wave Toolbox |

## Simulations In One Dimension Example

On this page…
Overview Creating the k-space grid and defining the medium properties Defining the initial pressure distribution and sensor mask Running the simulation

### Overview

This example provides a demonstration of using k-Wave for the simulation and detection of photoacoustic waves within a one-dimensional heterogeneous propagation medium. It builds on the Homogeneous Propagation Medium and Heterogeneous Propagation Medium examples.

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

Back to Top

### Creating the k-space grid and defining the medium properties

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
    c = 1500*ones(Nx, 1);           % [m/s]
    c(1:round(Nx/3)) = 2000;        % [m/s]
    rho = 1000*ones(Nx, 1);         % [kg/m^3]
    rho(round(4*Nx/5):end) = 1500;  % [kg/m^3]

Back to Top

### Defining the initial pressure distribution and sensor mask

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;
    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]

Back to Top

### Running the simulation

The computation is invoked by running `kspaceFirstOrder1D` with the inputs defined above. To record long enough to capture the reflections, `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
    [t_array dt] = makeTime(kgrid, max(c(:)));

    % replace t_array with a longer array to capture the reflections
    t_end = 2.5*kgrid.x_size/max(c(:));
    t_array = 0:dt:t_end;

    % run the simulation
    sensor_data = kspaceFirstOrder1D(p0, kgrid, c, rho, t_array, sensor_mask, 'PlotLayout', true);

As the function runs, status updates and computational parameters are printed to the command line.

    Running k-space simulation...
      dt: 7.5ns, t_end: 31.995us, time steps: 4267
      input grid size: 512 pixels (25.6mm)
      smoothing p0 distribution...
      smoothing c distribution...
      smoothing rho distribution...
      precomputation completed in 0.45523s
      starting time loop...
      computation completed in 6.4823s

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.

Back to Top

© 2009 Bradley Treeby and Ben Cox.