k-Wave Toolbox |

## Focussed 2D Array with Directional Elements Example

On this page…
Overview Define a focussed array of directional elements Using an infinitely wide line source Running the simulation Plotting

### Overview

This example demonstrates the use of k-Wave to compute the outputs from a curved detector array which consists of several elements, each of which consists of a number of grid points.

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

Back to Top

### Define a focussed array of directional elements

To start with, a curved detector array is defined using the `makeCircle` function.

    % define a semicircular sensor centered on the grid
    semicircle_radius = 65; % [grid points]
    arc = makeCircle(Nx, Ny, Nx/2, Ny/2, semicircle_radius, pi);

The grid points making up this curved array are divided up between a number of elements. This is achieved by calculating the angles from each grid point to the focus of the array and grouping the grid points with similar angles.

    % find total number and indices of the grid points constituting the
    % semicircle
    arc_indices = find(arc == 1);
    Nv = length(arc_indices);

    % calculate angles between grid points in the arc and the centre of the grid
    arc_angles = atan((kgrid.y(arc_indices))./kgrid.x(arc_indices));

    % sort the angles into ascending order, and adjust the indices accordingly
    [sorted_arc_angles,sorted_index] = sort(arc_angles);
    sorted_arc_indices = arc_indices(sorted_index);

    % divide the semicircle into Ne separate sensor elements
    Ne = 13;
    sensor.mask = zeros(Nx,Ny);
    for loop = 1:Ne

        % the indices of the grid points belonging to one element.
        % (There is a two grid point gap between the elements.)
        grid point_indices = sorted_arc_indices(floor((loop-1)*Nv/Ne)+2:floor(loop*Nv/Ne)-1);

        % add the element to the sensor.mask
        sensor.mask(grid point_indices) = 1;

    end

Back to Top

### Using an infinitely wide line source

To model a plane wave source parallel to one of the grid dimensions, two steps are necessary. First, `source.p_mask` is set so that it stretches across the domain.

    source.p_mask = zeros(Nx,Ny);
    source.p_mask(140,:) = 1;

Secondly, the inputs to the simulation are set so that the perfectly matched layer is turned off on the two sides that `source.p_mask` meets.

    input_args = {'PMLAlpha', [4 0], 'DisplayMask', display_mask, 'PlotScale', [-0.75 0.75]};

Back to Top

### Running the simulation

The simulation is run and the time series are measured for every non-zero grid point in `sensor.mask`. These time series are then allocated to their relevant elements, and averaged together.

    sensor_data = kspaceFirstOrder2D(kgrid, medium, source, sensor, input_args{:});

    % split up the data, recorded on all the grid points, between the elements
    element_data = zeros(Ne,Nt);
    for loop = 1:Ne

        % the indices of the sensor grid points in the sensor mask
        sensor_indices = find(sensor.mask==1);

        % the indices of the grid points belonging to one element.
        grid point_indices = sorted_arc_indices(floor((loop-1)*Nv/Ne)+2:floor(loop*Nv/Ne)-1);

        % indices of sensor_data that refer to the data for this element
        data_indices = zeros(length(grid point_indices),1);
        for loop2 = 1:length(grid point_indices)
            data_indices(loop2) = find(sensor_indices == grid point_indices(loop2));
        end

        % for one element per loop, average the time series from each of the
        % element's grid points to give one time series for the whole element
        element_data(loop,:) = mean(sensor_data(data_indices,:),1);

    end

The time series corresponding to the different elements are plotted. The directionality introduced by the large size of the detector (because it averages the incoming wave over its area) is clearly seen.

Back to Top

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