Dear All,

I am having trouble with sensor element directivity in k-wave. In particular I am unable to get figure-of-eight (cos(theta)) directionality to work in problems that are more general than the "Sensor Element Directivity in 2D Example". In my case I am trying to observe the cos(theta) rolloff when all sensors have a directivity angle of zero and they are receiving a signal from a point source (instead of receiving a plane wave). Please run and take a look at the code below to see the issue.

Thank You,

Rehman Ali

```
% =========================================================================
% DEFINE THE GRID AND MEDIUM PROPERTIES
% =========================================================================
% create the computational grid
Nx = 128; % number of grid points in the x (row) direction
Ny = 128; % number of grid points in the y (column) direction
dx = 1e-3/Nx; % grid point spacing in the x direction [m]
dy = dx; % grid point spacing in the y direction [m]
kgrid = makeGrid(Nx, dx, Ny, dy);
x = (-(Nx-1)/2:(Nx-1)/2)*dx;
y = (-(Ny-1)/2:(Ny-1)/2)*dy;
% define the properties of the propagation medium
medium.sound_speed = 1500; % [m/s]
% create the time array, then halve it to make the example end sooner
[kgrid.t_array, dt] = makeTime(kgrid, medium.sound_speed);
kgrid.t_array = (0:0.7*length(kgrid.t_array))*dt;
% =========================================================================
% DEFINE THE DIRECTIONAL SENSOR ARRAY
% =========================================================================
% define a line of sensor points
sensor.mask = zeros(Nx,Ny);
depth_idx = 24;
lat_idx = 2:1:Ny-1;
sensor.mask(depth_idx, lat_idx) = 1;
% define the angle of max directivity for each sensor point:
% 0 = max sensitivity in x direction (up/down)
sensor.directivity_angle = zeros(Nx,Ny);
% define the directivity pattern
sensor.directivity_pattern = 'gradient'; % Cosine-Based Directivity
%sensor.directivity_pattern = 'pressure'; % Sinc-Based Directivity
% define the directivity size
sensor.directivity_size = 16*kgrid.dx;
% =========================================================================
% SIMULATION AND VISUALISATION FOR TIME-VARYING SOURCE PROBLEM
% =========================================================================
% define a time varying sinusoidal source (instead of an initial pressure)
source.p_mask = zeros(Nx,Ny);
source.p_mask(90, 64) = 1;
source.p0 = [];
source_freq = 12e6;
source_mag = 20.25;
source.p = source_mag*sin(2*pi*source_freq*kgrid.t_array);
% run the simulation
input_args = {'PMLInside', false, 'PlotPML', false, 'PMLAlpha', 2000};
sensor_data = kspaceFirstOrder2D(kgrid, medium, source, sensor, input_args{:});
% plot the largest value of the output for each sensor
max_data = max(sensor_data(:, 150:end), [], 2);
figure, plot(y(lat_idx)', max_data./max(max_data),'o')
xlabel('sensor lateral location (m)')
ylabel('maxima of single-element sensors'' outputs')
axis([min(y) max(y) 0 1.05])
```