Peak Width at Half Height

92 visualizaciones (últimos 30 días)
Laiba Qadeer
Laiba Qadeer el 10 de Mzo. de 2020
Comentada: Rufus Adjetey el 13 de Nov. de 2020
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 comentarios
Laiba Qadeer
Laiba Qadeer el 10 de Mzo. de 2020
I have attached the image
Adam Danz
Adam Danz el 10 de Mzo. de 2020
Image Analyst's demo will work well with your data.

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 10 de Mzo. de 2020
Editada: Image Analyst el 10 de Mzo. de 2020
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 comentarios
Image Analyst
Image Analyst el 12 de Nov. de 2020
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 el 13 de Nov. de 2020
Thank you very much

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by