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.
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Honey
am 30 Aug. 2024
Bearbeitet: Walter Roberson
am 30 Aug. 2024
% 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);
0 Kommentare
Akzeptierte Antwort
Shivam Gothi
am 30 Aug. 2024
Hello,
I wanted to clarify that there is no error with the "white" contour you get in the image attached by you. white contour represents the "beam spot" as defined by the "FWHM" (Full Width at Half Maximum) criterion. This contour includes all the points where the pressure is greater than half of the maximum pressure.
I understand you were expecting the contour indicated by the black line, but that does not correspond to the "beam spot" as defined by FWHM. However, there is a workaround to achieve your desired contour. You can define a new threshold, let us say, "threshold_desired_contour," and plot the contour for the points where the pressure exceeds this new threshold.
To implement this, you can add a few additional lines at the end of your existing code:
%%%%%% ADD THESE LINES TO PLOT THE DESIRED CONTOUR ALONG WITH
% THE CONTOUR DEFINED ACCORDING TO "FWHM" DEFINATION %%%%%%%%%
contour_size = 0.9; %Enter number between 0 - 1 (how big you want the contour to be.)
threshold=maxPressure*contour_size;
Desired_contourData = contourc(x_axis, y_axis, Pressure, [threshold threshold]);
% Extract the X and Y coordinates of the contour line
ContourX = Desired_contourData(1,2:end);
ContourY = Desired_contourData(2,2:end);
% Calculate the spot size (diameter) in X and Y directions
Desired_spotSizeX = max(ContourX) - min(ContourX);
Desired_spotSizeY = max(ContourY) - min(ContourY);
% Display the results
fprintf('Focal Spot Size of the desired contour in X direction: %.2f mm\n', Desired_spotSizeX);
fprintf('Focal Spot Size of the desired contour in Y direction: %.2f mm\n', Desired_spotSizeY);
%Plot the desired contour on top of the beam pattern.
hold on;
plot(ContourX, ContourY, 'k', 'LineWidth', 2);
%%% Add appropriate legends %%%
axx = gca;
axx.FontSize = 12;
legend({'Focal spot (FWHM)','desired Focal spot'},'Location','northeast');
The plot generated after adding above code:
The screen-shot of command window is attached below:
I hope this is as per your requirement !
Weitere Antworten (1)
Shivam Gothi
am 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 Kommentare
Shivam Gothi
am 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?
Siehe auch
Kategorien
Mehr zu Contour Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!