Hi can anyone help me I want to calculate the FWHM of the contour plot to find the focal beam spot but my result is different.The one I drew with black is where its should be.
Show older comments
% Load your data
load("scan_2D_rms.mat");
% Extract relevant data
x_axis = saveRMSResult.xAxis;
y_axis = saveRMSResult.yAxis;
Signal= saveRMSResult.data;
% sensitivity = -277
% Gain = 20
% P[dB re 1uPa] =U[dB re 1V] -G[dB]-Sensitivity[dB re 1V/uPa]
S = 20*log10(Signal)-20-(-277);
Pressure= (10.^(S/20)*1e-12);
% % Apply Gaussian low-pass filter
% sigma =1; % Standard deviation of the Gaussian filter, adjust as needed
% P_filtered = imgaussfilt(Pressure, sigma);
% Plotting the beam pattern
figure;
imagesc(x_axis, y_axis, Pressure);
colormap('jet');
xlabel('X-axis (mm)');
ylabel('Y-axis (mm)');
title('2D Beam Pattern of Focused Ultrasound');
% save('2D_Beam_Pattern_XY.mat','x_axis','y_axis','P_filtered')
%
% %
% Identify peak pressure
[maxPressure, idx] = max(Pressure(:));
% Convert index to subscript (row and column)
[peakY, peakX] = ind2sub(size(Pressure), idx);
% Find FWHM
threshold = maxPressure / 2;
% Find contours where Pressure equals threshold
contourLevels = [threshold threshold];
contourData = contourc(x_axis, y_axis, Pressure, contourLevels);
% Extract the X and Y coordinates of the contour line
fwhmContourX = [];
fwhmContourY = [];
i = 1;
while i < length(contourData)
numPoints = contourData(2, i);
fwhmContourX = [fwhmContourX, contourData(1, i+1:i+numPoints)];
fwhmContourY = [fwhmContourY, contourData(2, i+1:i+numPoints)];
i = i + numPoints + 1;
end
% Calculate the spot size (diameter) in X and Y directions
spotSizeX = max(fwhmContourX) - min(fwhmContourX);
spotSizeY = max(fwhmContourY) - min(fwhmContourY);
% Display the results
fprintf('Focal Spot Size (FWHM) in X direction: %.2f mm\n', spotSizeX);
fprintf('Focal Spot Size (FWHM) in Y direction: %.2f mm\n', spotSizeY);
% Optional: Plot the FWHM contour on top of the beam pattern
hold on;
plot(fwhmContourX, fwhmContourY, 'w', 'LineWidth', 2);

Accepted Answer
More Answers (1)
Shivam Gothi
on 30 Aug 2024
Hello,
There are different definitions of beam diameter. Refer to the below link.
What you are getting is the FWHM beam diameter (highlighted by white contour in the image attached by you).
From my understanding, you are expecting
diameter. For this, update the code and change the line :
threshold = maxPressure / 2;
to :
threshold = maxPressure * 0.865;
By making above modification, you will get the required plot as shown below

I hope this helps !
3 Comments
Honey
on 30 Aug 2024
Edited: Walter Roberson
on 30 Aug 2024
Shivam Gothi
on 30 Aug 2024
Ok.
As per my understanding, you want to plot contour of actual beam focal spot, by using FWHM contour information only, not by changing the threshold.
Is this the case?
Honey
on 30 Aug 2024
Categories
Find more on Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

