k-Wave Toolbox |

## Using A Binary Sensor Mask Example

On this page…
Overview Defining a binary sensor mask Running the simulation

### Overview

This example demonstrates how to use a binary sensor mask for the detection of photoacoustic waves within a two-dimensional homogeneous propagation medium. It builds on the Homogeneous Propagation Medium Example.

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

Back to Top

### Defining a binary sensor mask

In the Homogeneous Propagation Medium Example, the sensor mask (which defines where the pressure field is recorded at each time-step) was defined as a 2 x N matrix of Cartesian points within the k-space grid. It is also possible to define the sensor mask as binary matrix (i.e., a matrix of 1's and 0's) representing the pixels within the computational grid that will collect the data. In this case, the sensor mask must have the same dimensions as the initial pressure distribution. Here `makeCircle` is used (instead of `makeCartCircle`) to define a binary sensor mask of an arc created using the midpoint circle algorithm. It is also possible to explicitly create an arbitrary binary sensor mask, or to load one from an external image map (see the Loading External Image Maps Example).

    % define a binary sensor mask
    sensor_x_pos = Nx/2;        % pixels
    sensor_z_pos = Nz/2;        % pixels
    sensor_radius = Nx/2 - 20;  % pixels
    sensor_arc_angle = 3*pi/2;  % radians
    sensor_mask = makeCircle(Nx, Nz, Nx/2, Nz/2, sensor_radius, sensor_arc_angle);

A plot of the loaded initial pressure distribution and the sensor mask is given below.

Back to Top

### Running the simulation

The computation is again invoked by calling `kspaceFirstOrder2D`. For a Cartesian sensor mask (as in the Homogeneous Propagation Medium Example), the returned time-series are ordered the same way as the set of Cartesian sensor points. For a binary sensor mask (as in this example), the time-series are instead returned using MATLAB's standard column-wise linear matrix index ordering. A visualisation of the recorded time data is given below. The data ordering is clearly visible; the data is returned column-wise from top to bottom, and left to right. The recorded data at a particular time step can be restored to its original position in the grid using `unmaskSensorData`.

For both Cartesian and binary sensor masks, the data is indexed as `sensor_data(sensor position, time)`.

Back to Top

© 2009 Bradley Treeby and Ben Cox.