Peak Width at Half Height

조회 수: 92 (최근 30일)
Laiba Qadeer
Laiba Qadeer 2020년 3월 10일
댓글: Rufus Adjetey 2020년 11월 13일
I started using MATLAB only a few days ago. And I have trouble finding the width of peak. I have two subplots, both of which represent one peak from the data only. I want to know the width of peak at half distance. I also want the line representing width to be displayed on the plot. Please tell me how this can be done.
I searched the internet for help but could not get the desired result.
Here is my code for both graphs:
subplot(2,1,1)
plot(Hwave,Hintense,'.'),title('Original data'),xlabel('Wavelength'),ylabel('Intensity')
axis tight, grid
subplot(2,1,2)
plot(Hwaveinter,Hreal,'.'),title('Eight Times Interpolated Data'),xlabel('Wavelength'),ylabel('Intensity')
axis tight, grid
Thanks
  댓글 수: 3
Laiba Qadeer
Laiba Qadeer 2020년 3월 10일
I have attached the image
Adam Danz
Adam Danz 2020년 3월 10일
Image Analyst's demo will work well with your data.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2020년 3월 10일
편집: Image Analyst 2020년 3월 10일
See this demo:
% Initialization steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 24;
% Make Gaussian https://en.wikipedia.org/wiki/Gaussian_function
x = linspace(0, 100, 1024);
amp = 50;
mu = 35;
sigma = 20;
y = amp * exp(-(x - mu).^2 / (2 * sigma^2));
hFig = figure;
plot(x, y, 'b-', 'LineWidth', 2);
grid on;
xlabel('x', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize);
hFig.WindowState = 'maximized';
% Find the half height - midway between min and max y values.
halfHeight = (min(y) + max(y)) / 2;
hold on;
yline(halfHeight, 'Color', 'g', 'LineWidth', 2);
% Find left edge
index1 = find(y >= halfHeight, 1, 'first');
x1 = x(index1)
line([x1, x1], [0, y(index1)], 'Color', 'r', 'LineWidth', 2);
text(x1+1, 5, sprintf('x1 = %.2f', x1), 'FontSize', fontSize, 'Color', 'r');
% Find right edge
index2 = find(y >= halfHeight, 1, 'last');
x2 = x(index2)
line([x2, x2], [0, y(index2)], 'Color', 'r', 'LineWidth', 2);
text(x2+1, 5, sprintf('x2 = %.2f', x2), 'FontSize', fontSize, 'Color', 'r');
% Compute the full width, half max.
fwhm = x2 - x1
text(mu, halfHeight+2, sprintf('width = %.2f', fwhm), 'FontSize', fontSize, 'Color', 'r', 'HorizontalAlignment', 'center');
caption = sprintf('Full Width, Half Max = %.2f', x2 - x1);
title(caption, 'FontSize', fontSize);
Adapt code as needed for your variable names.
  댓글 수: 12
Image Analyst
Image Analyst 2020년 11월 12일
You data is discrete - it's quantized. There are no elements that are exactly 0.6 for y. So it picks the closest element above that. If you want to interpolate with interp1() or polyval(), you're certainly welcome to do that.
Rufus Adjetey
Rufus Adjetey 2020년 11월 13일
Thank you very much

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by