I computed beam pattern pressure P using the following two ways:
i) P = extractAmpPhase(sensor_data.p, 1/kgrid.dt, transducer.freq);
P = reshape(extracted_P_amp, kgrid.Nx, kgrid.Ny, kgrid.Nz);
P = P(:,:,kgrid.Nz/2);
ii) sensor_P = reshape(sensor_data.p, kgrid.Nx, kgrid.Ny, kgrid.Nz, time_points);
sensor_P_xy = sensor_P(:,:,kgrid.Nz/2,:);
sensor_P_xy = reshape(sensor_P_xy, kgrid.Nx, kgrid.Ny, time_points);
[freq, amp_spect] = spect(sensor_P_xy, 1/kgrid.dt, 'Dim', 3);
[f1_value, f1_index] = findClosest(freq, transducer.freq);
P = amp_spect(:, :, f1_index);
I wonder if the above can offer the same results?